pcw Posted June 3, 2009 Share Posted June 3, 2009 Hi, I have this script that is meant to match a form submission to what is recorded in the database. This was working but has stopped for some reason. I now get this message: Pin did not match - Email verification failed Even though I have echoed the gen_id and it matches what is in the database. Here is the code: function pin() { $username = $_POST['username']; print <<<PIN <html> <head> <link rel="stylesheet" type="text/css" href="../adminStyle.css"> </head> <body> <div id="header"><center><h1>Sitebuilder v2.0</center></h1><center><p><strong>Build your own membership site</strong></p></center></div> <div> <h2>Email validation</h2> <center> <form action="sb.php?cmd=pinver" method="POST"> <input type="hidden" name="date_registered" value="$date"> <input type="hidden" name="IP" value="$ip"> <input type="hidden" name="gen_id" value="$gen_id"> <table> <tr><td class="style2">PIN:</td> <td><input type="text" name="gen_id"></td></tr> </table> <input type="submit" name="submit" value="submit"> </form> </center> </div> <div class="footer"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>Copyright 2009 by Sitebuilder.</div> </div> </body> </html> PIN; }; and this checks the entry against the database function pin_chk() { include("data/required.php"); if (isset($_POST['submit'])) { mysql_connect('localhost', $dbuser, $dbpass) or die(mysql_error()); mysql_select_db( $db) or die(mysql_error()); $username = mysql_real_escape_string($_POST['username']); $gen_id = mysql_real_escape_string($_POST['gen_id']); if ($result = mysql_query("SELECT username, gen_id FROM profiles WHERE username='$username' AND gen_id='$gen_id'")) { if (mysql_num_rows($result) > 0) { verified(); header( 'Location: ../login.php' ); }else { echo "<p class=style3>Pin did not match - Email verification failed</p>"; unverified(); pin(); } } } }; Link to comment https://forums.phpfreaks.com/topic/160822-solved-mysql-error/ Share on other sites More sharing options...
akitchin Posted June 3, 2009 Share Posted June 3, 2009 it's probably because you have TWO inputs named "gen_id" which will no doubt lead to confusion in what value you're actually passing to your query. either change one of the names, or delete one of the inputs. PS: first, you won't end up with any values in those hidden inputs anyway, since you're not passing any of those variables ($date, $IP, $gen_id, etc.) to the pin() function. second, you don't need semicolons at the end of function statements. Link to comment https://forums.phpfreaks.com/topic/160822-solved-mysql-error/#findComment-848772 Share on other sites More sharing options...
kickstart Posted June 3, 2009 Share Posted June 3, 2009 Hi In addition to the above point, where is the username field coming from. All the best Keith Link to comment https://forums.phpfreaks.com/topic/160822-solved-mysql-error/#findComment-848778 Share on other sites More sharing options...
pcw Posted June 3, 2009 Author Share Posted June 3, 2009 Hi, thanks for both of your replies. I have followed your advice and have now got this: function pin() { $username = $_REQUEST['username']; print <<<PIN <html> <head> <link rel="stylesheet" type="text/css" href="../adminStyle.css"> </head> <body> <div id="header"><center><h1>Sitebuilder v2.0</center></h1><center><p><strong>Build your own membership site</strong></p></center></div> <div> <h2>Email validation</h2> <center> <form action="sb.php?cmd=pinver" method="POST"> <input type="hidden" name="username" value="username"> echo $username; <table> <tr><td class="style2">PIN:</td> <td><input type="text" name="gen_id"></td></tr> </table> <input type="submit" name="submit" value="submit"> </form> </center> </div> <div class="footer"><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>Copyright 2009 by Sitebuilder.</div> </div> </body> </html> PIN; } ######## PIN VERIFICATION ######## case "pinver": # Calls the function that checks that the entered validation PIN matches that in the database, before calling other # functions. (See includes.php and instructions). if (isset($_POST['submit'])) { mysql_connect('localhost', $dbuser, $dbpass) or die(mysql_error()); mysql_select_db( $db) or die(mysql_error()); $username = mysql_real_escape_string($_POST['username']); $gen_id = mysql_real_escape_string($_POST['gen_id']); echo $gen_id; if ($result = mysql_query("SELECT username, gen_id FROM profiles WHERE username='$username' AND gen_id='$gen_id'")) { if (mysql_num_rows($result) > 0) { verified(); header( 'Location: ../login.php' ); }else { echo "<p class=style3>Pin did not match - Email verification failed</p>"; unverified(); pin(); } } } break; But I am sttill getting th same problem Link to comment https://forums.phpfreaks.com/topic/160822-solved-mysql-error/#findComment-848793 Share on other sites More sharing options...
akitchin Posted June 3, 2009 Share Posted June 3, 2009 how are you calling the section of code in the "pinver" case? Link to comment https://forums.phpfreaks.com/topic/160822-solved-mysql-error/#findComment-848798 Share on other sites More sharing options...
pcw Posted June 3, 2009 Author Share Posted June 3, 2009 Its ok guys, I forgot to put $ in front of the username value Link to comment https://forums.phpfreaks.com/topic/160822-solved-mysql-error/#findComment-848800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.