zang8027 Posted May 8, 2009 Share Posted May 8, 2009 I have dont many of these but i do not see why this is not working. Its a simple form validation. It simply posts to a process page that checks to see if everything is filled out. It is showing "noName" no matter what and all my errors are being echoed.. as if the "if statement" is not working <form action='processEmail.php' method='get'> <p>Your Name * <?php if(isset($_GET['error'])) { if($_GET['error'] = 'noName') { echo "<span class='redText'>You must enter a name</span>"; } } ?></p> <input type='text' name='uName' class='for'/> <p>Your Email * <?php if(isset($_GET['error'])) { if($_GET['error'] = 'noEmail') { echo "<span class='redText'>You must enter an email</span>"; } elseif($_GET['error']='invalid') { echo "<span class='redText'>You must enter a valid email</span>"; } } ?></p> <input type='text' name='email' class='for' /> <p>Type a Message * <?php if(isset($_GET['error'])) { if($_GET['error'] = 'noComment') { echo "<span class='redText'>You must enter a Message</span>"; } } ?></p> <textarea name='uMsg' class='for'></textarea> <br/> <br/> <input type='submit' value='Send it!'/> </form> and my process page: <?php //grab variables being passed and put them into usable variables $name = $_GET['uName']; $email = $_GET['email']; $text = $_GET['uMsg']; //Validate each field for being blank or wrong character if($_GET['name'] == "") { header("Location:contact.php?error='noName'"); } elseif($_GET['email'] == "") { header("Location:contact.php?error='noEmail'"); } elseif($_GET['comment'] == "") { header("Location:contact.php?error='noText'"); } elseif(!preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)) { header("Location:contact.php?error='invalid'"); }else{ //If all checks out, send the email Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/ Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Forgot how to do comparisons? if($_GET['error'] = 'noName') That is just an assignment. It's always true unless you're assigning empty values. Use 2 or 3 equal signs for comparison. You have a bunch of these IF statements. Fix them all. Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/#findComment-829168 Share on other sites More sharing options...
zang8027 Posted May 8, 2009 Author Share Posted May 8, 2009 thought so but i tried 2 earlier and it was still sending back ;noName' all the time Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/#findComment-829169 Share on other sites More sharing options...
zang8027 Posted May 8, 2009 Author Share Posted May 8, 2009 now i changed it to say if ['error'] == "") { do stuff here} no matter what the error, its not firing whats inside the brackets Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/#findComment-829176 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Please post an updated version of your code. Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/#findComment-829179 Share on other sites More sharing options...
zang8027 Posted May 8, 2009 Author Share Posted May 8, 2009 <?php if(isset($_GET['error'])) { if($_GET['error'] == 'noName') { echo "<span class='redText'>You must enter a name</span>"; } } ?> anything wrong with this code? Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/#findComment-829180 Share on other sites More sharing options...
zang8027 Posted May 8, 2009 Author Share Posted May 8, 2009 http://gregsreid.com/contact.php?error='noName' thats what im getting via url if i dont add the name Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/#findComment-829183 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Syntactically no. But if the echo does run, the output string is *not* xHTML-compliant. Your process page has its GET variables all mixed up. Correct those. Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/#findComment-829185 Share on other sites More sharing options...
zang8027 Posted May 8, 2009 Author Share Posted May 8, 2009 I fixed one problem... im dumb... my process page was copied from another one i made and the validation was wrong I still am not seeing the text though in my if statements Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/#findComment-829186 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 Please post an updated version of your code. Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/#findComment-829187 Share on other sites More sharing options...
PFMaBiSmAd Posted May 8, 2009 Share Posted May 8, 2009 Except for the 'email' field, none of your other form field names match the names you are using in the tests. For example, form field - uName and testing code - if($_GET['name'] == "") You in fact have a statement $name = $_GET['uName']; but $name is then not being used. You need to go through your code and check it for consistency. Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/#findComment-829191 Share on other sites More sharing options...
zang8027 Posted May 8, 2009 Author Share Posted May 8, 2009 <?php //grab variables being passed and put them into usable variables $name = $_GET['uName']; $email = $_GET['email']; $text = $_GET['uMsg']; //Validate each field for being blank or wrong character if($_GET['uName'] == "") { header("Location:contact.php?error='noName'"); } elseif($_GET['email'] == "") { header("Location:contact.php?error='noEmail'"); } elseif($_GET['uMsg'] == "") { header("Location:contact.php?error='noText'"); } elseif(!preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $email)) { header("Location:contact.php?error='invalid'"); }else{ //If all checks out, send the email //------------------Email----------------- //define the receiver of the email $to = "[email protected]"; //define the subject of the email $subject = 'A message from'.$name.'via www.GregSReed.com'; //define the message to be sent. Each line should be separated with \n nl2br($EmailBody = $text); $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $date = date("m/d/Y H:i:s"); $EmailFooter = "<br />Sent: $date<br /><br />"; $Message = $EmailBody.$EmailFooter; $ok = mail($to, $subject, $Message, $headers . "From:$name <".$to.">"); if($ok){ header("Location:contact.php?status=Success"); }else{ } } //End the else all validated ?> <?php include('header.php') ?> <div id='contact'> <?php if(isset($_GET['status'])) { if($_GET['status'] == 'success') { print "<h2>Success! Your message was sent.</h2>"; } } ?> <p class='yellowText'>Got a question or comment? Simply fill out the form below!</p> <form action='processEmail.php' method='get'> <p>Your Name * <?php if(isset($_GET['error'])) { if($_GET['error'] == 'noName') { print "<span class='redText'>You must enter a name</span>"; } } ?></p> <input type='text' name='uName' class='for'/> <p>Your Email * <?php if(isset($_GET['error'])) { if($_GET['error'] == 'noEmail') { echo "<span class='redText'>You must enter an email</span>"; } elseif($_GET['error'] =='invalid') { echo "<span class='redText'>You must enter a valid email</span>"; } } ?></p> <input type='text' name='email' class='for' /> <p>Type a Message * <?php if(isset($_GET['error'])) { if($_GET['error'] == 'noComment') { echo "<span class='redText'>You must enter a Message</span>"; } } ?></p> <textarea name='uMsg' class='for'></textarea> <br/> <br/> <input type='submit' value='Send it!'/> </form> </div> <?php include('footer.php') ?> Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/#findComment-829193 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 1. I don't understand why you store them in variables if you're going to call $_POST again in the IF statement. 2. Don't put those single quotes in the redirect. What is this? Link to comment https://forums.phpfreaks.com/topic/157317-quick-problem-with-code-that-worked-once-now-doesnt/#findComment-829197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.