john_wenhold Posted February 4, 2010 Share Posted February 4, 2010 I have a problems. If you could help, that would be great 1. I have a form people are filling out. And the info gets stored in mysql database. If someone tries giving me the same phonenumber in a form more than once, I want it to reject it. But something is wrong because it is causing there to be only one entry stored in the database. So if the database is empty, one form gets filled out and stored and the rest after do not unless I delete the first entry from the database. I know the problem is on one of these lines: $query = "SELECT * FROM textnook WHERE phonenumber = '{$_POST['phonenumber']}'"; $data = mysql_query ($query); if (mysql_num_rows($data) == 0) { But here is the entire code for it if (isset($submit)) { $output_form = false; if (isset($firstname) && !empty($firstname) && isset($lastname) && !empty($lastname) && isset($username) && !empty($username) && isset($password1) && !empty($password1) && isset($password2) && !empty($password2) && isset($phonenumber) && !empty($phonenumber) && isset($month) && !empty($month) && isset($day) && !empty($day) && isset($year) && !empty($year) && isset($categories) && !empty($categories) && isset($days) && !empty($days) && isset($text) && !empty($text) && isset($sex) && !empty($sex) && ($password1 == $password2)) { $dbc = mysql_connect ('server', 'xxxxx', 'xxxx', 'xxxx') or die ('Error connecting to MySQL server.'); mysql_select_db ('thetextnook', $dbc); $query = "SELECT * FROM textnook WHERE phonenumber = '{$_POST['phonenumber']}'"; $data = mysql_query ($query); if (mysql_num_rows($data) == 0) { $query1 = "INSERT INTO textnook ( first_name, last_name, user_name, password, phonenumber, sex, month, day, year, category, days, text, comments) VALUES ( '$firstname', '$lastname', '$username', '$password1', '$phonenumber', '$sex', '$month','$day', '$year', '$categories', '$days', '$text','$comments')"; $result = mysql_query ($query1, $dbc) or die ("MYSQL ERROR: $query1 - " . mysql_error()); echo 'Sign Up Confirmed' . '<br /> <br />'; echo 'Thanks for joining TextNook!' . '<br /> <br />'; echo 'You have signed up to r for the following categories:' .implode(", ",$_POST['categories']) . '<br /> <br />'; echo 'You have signed up on the following days:' .implode(", ",$_POST['days']) . '<br /> <br />'; echo 'And you have signed up to receive the following per category per day:' . $_POST['text'] . '<br /> <br />'; echo 'You can change these selections at anytime by logging into your account.' . '<br /> <br />'; echo 'Coming Soon: You will be able to choose individual stores and restraunts instead of entire categories.</span>' . '<br /> <br /> <br /> <br /> <br /> <br /> <br /> <br />'; mysql_close ($dbc); exit(); } #2 Quote Link to comment https://forums.phpfreaks.com/topic/190865-i-have-a-problem-with-my-code/ Share on other sites More sharing options...
MadTechie Posted February 4, 2010 Share Posted February 4, 2010 Would need to see the debug data, (echo some variables to check the data) but $query = "SELECT * FROM textnook WHERE phonenumber = '{$_POST['phonenumber']}'"; iassume it should be this $query = "SELECT * FROM textnook WHERE phonenumber = '$phonenumber'"; its probably not much of a change but i don't see $_POST used anywhere or $phonenumber being set for that matter.. oh and you may want to read up on SQL injections EDIT: STOP creating multiple threads technically once one of them is solved you be able to workout the rest, but you have make it much harder to help you... Read up on using arrays and it will solve your problem, also try some debugging! (echo some variables!) Quote Link to comment https://forums.phpfreaks.com/topic/190865-i-have-a-problem-with-my-code/#findComment-1006515 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.