Jump to content

anevins

Members
  • Posts

    251
  • Joined

  • Last visited

Everything posted by anevins

  1. this gives same result: if (check_email_address($email)){ $i=1; } elseif (check_email_address($email)==false){ echo '<span class="error">Please enter a valid email address.</span>'; $i=0; } How am I supposed to use this elseif
  2. Hi, I'm using a function I took from the web for email validation, but there's something wrong with the form in general when I use this. When I test it out, I get the messages "Please enter a valid email address.Thank you..." when I input the letter 'o' into all input fields. I don't know why the validation isn't working for the "Thank you" message, but I think it has something to do with this email. Could anyone help me out here? function: function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } From the tutorial, this is how you're supposed to use the function: if (check_email_address($email)) { echo $email . ' is a valid email address.'; } else { echo $email . ' is not a valid email address.'; } The form: include_once('php/functions.php'); $firstname = $_POST['first_name']; $lastname = $_POST['last_name']; $email = $_POST['email']; $reason = $_POST['reason']; $i = 0; if(isset($_POST['submit'])){ if (empty($firstname)){ echo '<span class="error">Please enter your First name.</span>'; } if (empty($lastname)){ echo '<span class="error">Please enter your Last name.</span>'; } if (check_email_address($email)){ $i=1; } else { echo '<span class="error">Please enter a valid email address.</span>'; $i=0; } if (empty($reason)){ echo '<span class="error">Please enter your reason to contact me.</span>'; } if (empty($firstname) && empty($lastname) && ($i=0) && empty($reason)){ echo '<span class="error">All fields are required.</span>'; } if (!empty($firstname) && !empty($lastname) && ($i=1) && !empty($reason)){ echo '<span class="correct">Thank you...</span>'; } } ?> <div id="form"> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table> <tr><td>First name:</td><td><input type="text" name="first_name" value="<?php echo $firstname; ?>"/></td></tr> <tr><td></td><td><?php echo $firstname_error; ?></td></tr> <tr><td>Last name: </td><td><input type="text" name="last_name" value="<?php echo $lastname; ?>"/></td></tr> <tr><td></td><td><?php echo $lastname_error; ?></td></tr> <tr><td>Email Address: </td><td><input type="text" name="email" value="<?php echo $email; ?>"/></td></tr> <tr><td></td><td><?php echo $email_error; ?></td></tr> <tr><td>Reason: </td><td><textarea rows="5" cols="16" name="reason" ><?php echo $reason; ?></textarea></td></tr> <tr><td></td><td><?php echo $reason_error; ?></td></tr> <tr><td> </td><td><input type="submit" name="submit" id="submit" value="submit" /></td></tr> </table> </form> </div> Thanks.
  3. navigation.php <?php $dom = new DOMDocument('1.0', 'UTF-8'); $dom->loadHTMLFile($_SERVER['PHP_SELF']); $body = $dom->getElementsByTagName('body'); $id= $body->item(0)->getAttribute('id'); // home ?> <div id="header"> <div id="logo"> <a href="index.php"><img src="images/nevins.png" alt="NEVINS Web Design" /></a> </div> <ul id="navigation"> <li <?php if ($id=='home') echo 'class="selected"';?>><a href="index.php">Welcome</a></li> <li>|</li> <li <?php if ($id=='gallery') echo 'class="selected"';?>><a href="gallery.php">Gallery </a></li> <li>|</li> <li><?php if ($id=='contact') echo 'class="selected"';?><a href="contact.php">Contact</a></li> </ul> </div> index.php: <?php include_once('php/header.php'); ?> <body id="home"> <script type="text/javascript"> Cufon.replace('h1'); Cufon.replace('#navigation a' ,{ hover: true, fontFamily: 'Josefin Sans Std'}); </script> <?php include_once('php/navigation.php');?>
  4. When using PHP_SELF I get the errors: Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: I/O warning : failed to load external entity "/xampp/portfolio/index.php" in D:\xampp\xampp\htdocs\xampp\portfolio\php\navigation.php on line 4 Fatal error: Call to a member function getAttribute() on a non-object in D:\xampp\xampp\htdocs\xampp\portfolio\php\navigation.php on line 6 I'm not sure what you mean by "can you show the class..." sorry.
  5. $dom->loadHTMLFile(__FILE__); I get warnings: Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: error parsing attribute name in file:///D:/xampp/xampp/htdocs/xampp/portfolio/php/navigation.php, line: 15 in D:\xampp\xampp\htdocs\xampp\portfolio\php\navigation.php on line 4 and $dom vardumped is object(DOMDocument)#1 (0) { }
  6. Thanks TeNDoLLA, Since my issue that I opened this thread with, has been solved, I will start a new thread with this new issue.
  7. I want to load the current page dynamically, instead of: $dom->loadHTMLFile('index.php'); I can't use $_SERVER["PHP_SELF"] or $_SERVER["SCRIPT_NAME"] as they both give values of a string with a directory, rather than the file. For example, if used $dom->loadHTMLFile('$_SERVER["PHP_SELF"]'); The string passed to function is that it is trying to load is: /xampp/portfolio/gallery.php Is there any way I can pick off the gallery.php and not the rest of the string? Thanks.
  8. What if I wanted to load the current page from the user, instead of typing a specific page or string. I've tried using $dom->loadHTMLFile('$_SERVER["PHP_SELF"]'); but; fatal error. Do you know how I could do this?
  9. Thanks, from $dom = new DOMDocument('1.0', 'UTF-8'); $dom->loadHTMLFile('index.php'); $body = $dom->getElementsByTagName('body'); echo $body->item(0)->getAttribute('id'); // home i get home
  10. can i give html a file instead of a string? e.g $html = 'index.php';
  11. I'm trying to access an attribute in an HTML body tag. I keep getting NULL when I var_dump the variable I'm trying to use to store the attribute. Extract from entire dom NOTE: code is taken from index.php <?php include_once('php/header.php'); include_once('php/simple_html_dom.php'); ?> <body id="home"> <?php $html = file_get_html('index.php'); $body = $html->find('body'); $id = $body->attribute; var_dump($id); ?>
  12. Hello, I was wondering why data should be normalized, what is the most significant reason? Are any of these the most significant reason: Improves data integretiy. Improves data efficieny. Reduces database size. Thanks
  13. SOLVED Thanks Kickstart
  14. I've got a syntax error with my sql query and I don't know the correct structure. I want to select all from a table 'rating' where the column 'check' is equal to the value 'checked', and I want to order it by the id descending, with a limit of 3. This is the wrong syntax: SELECT * FROM rating WHERE check='checked' ORDER BY rating_id DESC LIMIT 3 Any ideas on the right syntax?
  15. If I try and echo something out within that if statement, nothing is echod.. When I var dumped those variables, nothing was outputted to the browser when inside the if statement, but before it I got those values posted just above
  16. var dump on all variables declared (8 variables) string(2) "44" string(7) "id8 8fd" string(9) "idontknow" string(6) "noidea" string(2) "19" string(7) "pb3 2dd" string(9) "idontknow" string(6) "noidea"
  17. This doesnt' work: if (!empty($b_house) && !empty($b_postcode) && !empty($b_city) && !empty($b_country) && !empty($d_house) && !empty($d_postcode) && !empty($d_city) && !empty($d_country)){ ... } replacing !empty with isset doesn't work either. I just want to say if all of them are not empty, do the if statement. Any solutions?
  18. :: SOLVED Solution: replacing !isset with empty
  19. I can't get this validation to work with my form: if (!isset($b_house) && !isset($b_postcode) && !isset($b_city) && !isset($b_country)){ echo '<div class="wrong">Please enter all of the billing information.</div>'; } The error message will just not show up at all, any ideas whats wrong?
  20. Reply to the little guy, Nothing is returned now.
  21. All lines are accounted for, there are no empty lines
  22. Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 2644 in ... line 54 line 54: echo preg_replace("/(".implode("|", $words).")/ie", 'censor($0);', $_POST['text']);
  23. I think that's the same as Matthew's example. I can't use those replacing arrays as it requires me to specify what the new format of each word will be, as I have too many words. I'm using the file() function to load in the text file with my words, into an array called $bad_words
  24. I checked that video out Matthew, it's all good until you have to create a replace array. I have over 500 words, therefore it would be impractical to create an array to replace the 500 words, specifying the swearing format in each word.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.