
john_wenhold
New Members-
Posts
7 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
john_wenhold's Achievements

Newbie (1/5)
0
Reputation
-
I have a form that when filled out, the info gets sent to mysql database. If my database table is completely empty, then everything works. But if there is an entry in the table already, I get the message 'error querying database'. I know it has something to do with the following code I wrote: $query = "SELECT * FROM textnook WHERE phonenumber = '{$_POST['phonenumber']}'"; $data = mysql_query ($query); if (mysql_num_rows($data) == 0) { The purpose of the code above is to not allow someone to sign up with the same PHONENUMBER more than once. But it is causing my database to only let ONE total entry into the table. Here is the entire code. If anyone knows the problem please help. Thanks <?php $firstname = ($_POST['firstname']); $lastname = ($_POST['lastname']); $username = ($_POST['username']); $password1 = ($_POST['password1']); $password2 = ($_POST['password2']); $phonenumber = ($_POST['phonenumber']); $sex = ($_POST['sex']); $month = ($_POST['month']); $day = ($_POST['day']); $year = ($_POST['year']); $categories = ($_POST['categories']); $days = ($_POST['days']); $text = ($_POST['text']); $comments = ($_POST['comments']); $submit = ($_POST['signup']); 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 ('thetextnook.db.5566025.hostedresource.com', 'thetextnook', 'Jpw78413', 'thetextnook') 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 receive :' .implode(", ",$_POST['categories']) . '<br /> <br />'; echo 'You have signed up to receive :' .implode(", ",$_POST['days']) . '<br /> <br />'; echo 'And you have signed up to receive :' . $_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(); } else { echo '<p> An account already exists with this phone number. Please select a different phone number. </p>'; $output_form = true; } } else { echo 'Attention! Unfortunately you did not provide all of the required sign up information. <br /> <br /> To sign up, please fill out all of the required form fields and make sure you confirm your password correctly. Thankyou'; $output_form = true; } } else { $output_form = true; } if ($output_form) { ?>
-
My entire code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title> TheTextNook Sign up - Results </title> <link type="text/css" rel="stylesheet" href="signup.css" /> </head> <body> <div id="allcontent"> <h1> <span id="title"> Title </span> <span id="home"> <a href="home.html"> Home </a> </span> </h1> <h2> XXXXXXX </h2> <?php $firstname = ($_POST['firstname']); $lastname = ($_POST['lastname']); $username = ($_POST['username']); $password1 = ($_POST['password1']); $password2 = ($_POST['password2']); $phonenumber = ($_POST['phonenumber']); $sex = ($_POST['sex']); $month = ($_POST['month']); $day = ($_POST['day']); $year = ($_POST['year']); $categories = ($_POST['categories']); $days = ($_POST['days']); $text = ($_POST['text']); $comments = ($_POST['comments']); $submit = ($_POST['signup']); 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', 'xxxxxx', 'xxxxxx') 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 receive :' .implode(", ",$_POST['categories']) . '<br /> <br />'; echo 'You have signed up to receive ' .implode(", ",$_POST['days']) . '<br /> <br />'; echo 'And you have signed up to receive the following amount:' . $_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(); } else { echo '<p> An account already exists with this username. Please select a different username. </p>'; $output_form = true; } } else { echo 'Attention! Unfortunately you did not provide all of the required sign up information. <br /> <br /> To sign up, please fill out all of the required form fields and make sure you confirm your password correctly. Thankyou'; $output_form = true; } } else { $output_form = true; } if ($output_form) { ?> <div id="form"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table> <tr> <th> General Info: </th> <td id="us"> Tell Us About Yourself </td> </tr> <tr> <th> </th> <td> <table> <tr> <td> <span class="star"> * </span> Firstname: </td> <td> <input type="text" name="firstname" value="<?php if(isset($_POST['signup'])) echo $_POST['firstname']; ?>" /> </td> </tr> <tr> <td> <span class="star"> * </span> Lastname: </td> <td> <input type="text" name="lastname" value="<?php if(isset($_POST['signup'])) echo $_POST['lastname']; ?>" /> </td> </tr> <tr> <td> <span class="star"> * </span> Username: </td> <td> <input type="text" name="username" value="<?php if(isset($_POST['signup'])) echo $_POST['username']; ?>" /> </td> </tr> <tr> <td> <span class="star"> * </span> Password: </td> <td> <input type="password" id="password1" name="password1" /> </td> </tr> <tr> <td> <span class="star"> * </span> Confirm Password: </td> <td> <input type="password" id="password2" name="password2" /> </td> </tr> <tr> <td> <span class="star"> * </span> Phone #: </td> <td> <input type="text" name="phonenumber[]" value="<?php if(isset($_POST['signup'])) echo $_POST['phonenumber']['0']; ?>" maxlength="3" size="3" /> <input type="text" name="phonenumber[]" value="<?php if(isset($_POST['signup'])) echo $_POST['phonenumber']['1']; ?>" maxlength="3" size="3" /> <input type="text" name="phonenumber[]" value="<?php if(isset($_POST['signup'])) echo $_POST['phonenumber']['2']; ?>" maxlength="4" size="4" /> </td> </tr> <tr> <td> <span class="star"> * </span> Sex: </td> <td> <input type="radio" name="sex" value="male"<?php if(isset($_POST['signup']) && isset($_POST['sex']) && $_POST['sex']=='male') echo "checked='checked'"; ?> /> male <input type="radio" name="sex" value="female"<?php if(isset($_POST['signup']) && isset($_POST['sex']) && $_POST['sex']=='female') echo "checked='checked'"; ?> /> female </td> </tr> <tr> <td> <span class="star"> * </span> Date of Birth: </td> <td> <select name="month"> <?php $months = array('jan'=>'January', 'feb'=>'February', 'mar'=>'March', 'apr'=>'April', 'may'=>'May', 'june'=>'June', 'july'=>'July', 'aug'=>'August', 'sep'=>'September', 'oct'=>'October', 'nov'=>'November', 'dec'=>'December'); foreach($months as $k1=>$v1) { $echo_out0 = "<option value='".$k1."'"; if(isset($_POST['signup'])) { if($k1==$_POST['month']) { $echo_out0 .= " selected='selected'"; } } $echo_out0 .=">".$v1."</option>\n"; echo $echo_out0; } ?> </select> <select name="day"><?php for ($i = 1; $i <= 31; $i++) { $echo_out0_1 = "<option value='".$i."'"; if(isset($_POST['signup'])) { if($i==$_POST['day']) { $echo_out0_1 .= " selected='selected'"; } } $echo_out0_1 .= ">".$i."</option>"; echo $echo_out0_1; } ?> </select> <select name="year"><?php for ($i = 2010; $i >= 1900; $i--) { $echo_out0_2 = "<option value='".$i."'"; if(isset($_POST['signup'])) { if($i==$_POST['year']) { $echo_out0_2 .= " selected='selected'"; } } $echo_out0_2 .= ">".$i."</option>"; echo $echo_out0_2; } ?> </select> </td> </tr> </table> </td> </tr> <tr> <th> <span class="star"> * </span> Categories: </th> <td id="cat"> Choose the categories </td> </tr> <tr> <th> </th> <td> <?php $required_checkboxes = array('all'=>'All Categories', 'fastfood'=>'Fast Food', 'restaurants'=>'Restaurants', 'bars/clubs'=>'Bars/Clubs', 'a'=>'A', 'b'=>'B', 'c'=>'C'); $counter = 1; foreach($required_checkboxes as $k1=>$v1) { $echo_out = "<input type='checkbox' name='categories[]' value='".$k1."'"; if(isset($_POST['signup']) && isset($_POST['categories'])) { foreach($_POST['categories'] as $k2=>$v2) { if ($k1==$v2) { $echo_out .=" checked='checked'"; break 1; } } } $echo_out .= " /> ".$v1; echo $echo_out; $counter++; if($counter>4) echo "<br />"; } ?> </td> </tr> <tr> <th> <span class="star"> * </span> Days: </th> <td id="run"> Choose the days you </td> </tr> <tr> <th> </th> <td> <?php $days = array('Everyday','Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); foreach($days as $k1=>$v1) { $echo_out2 = "<input type='checkbox' name='days[]' value='".$v1."'"; if(isset($_POST['signup']) && isset($_POST['days'])) { foreach($_POST['days'] as $k2=>$v2) { if ($v1==$v2) { $echo_out2 .= " checked='checked'"; break 1; } } } $echo_out2 .= " /> ".$v1." <br />"; echo $echo_out2; } ?> </td> </tr> <tr> <th> <span class="star"> * </span> # of Texts: </th> <td id="walk"> Choose the / category / day </td> </tr> <tr> <th> </th> <td id="walk1"> NOTE: You may not always receive the max # of text messages </td> </tr> <tr> <th> </th> <td> <select name="text"> <?php $text_options = array('unlimited'=>'Unlimited', '1'=>'1', '3'=>'3', '5'=>'5', '10'=>'10', '15'=>'15', '20'=>'20', '25'=>'25', '50'=>'50'); foreach($text_options as $k1=>$v1) { $echo_out3 = "<option value='".$k1."'"; if(isset($_POST['signup'])) { if($k1==$_POST['text']) { $echo_out3 .= " selected='selected'"; } } $echo_out3 .= ">".$v1."</option>\n"; echo $echo_out3; } ?> </select> </td> </tr> <tr> <th> Comments: </th> <td> <textarea name="comments" rows="10" cols="50"><?php if(isset($_POST['signup'])) echo $_POST['comments']; ?> Comments/Suggestions </textarea> </td> </tr> </table> <p id="end"> <input type="submit" value="SignUp" name="signup" /> </p> </form> </div> <?php } ?> <p id="copyright"> Copyright 2010 © TheTextNook.com - All rights reserved <span id="about"> <a href="about.html"> About </a> </span> <span id="privacy"> <a href="about.html"> Privacy </a> </span> <span id="contact"> <a href="about.html"> Contact Us </a> </span> <span id="advertise"> <a href="about.html"> Advertise </a> </span> </p> </div> </body> </html>
-
Here is all my code for the page. If you could help, i would really appreciate it. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title> TheTextNook Sign up - Results </title> <link type="text/css" rel="stylesheet" href="signup.css" /> </head> <body> <div id="allcontent"> <h1> <span id="title"> Title </span> <span id="home"> <a href="home.html"> Home </a> </span> </h1> <h2> XXXXXXX </h2> <?php $firstname = ($_POST['firstname']); $lastname = ($_POST['lastname']); $username = ($_POST['username']); $password1 = ($_POST['password1']); $password2 = ($_POST['password2']); $phonenumber = ($_POST['phonenumber']); $sex = ($_POST['sex']); $month = ($_POST['month']); $day = ($_POST['day']); $year = ($_POST['year']); $categories = ($_POST['categories']); $days = ($_POST['days']); $text = ($_POST['text']); $comments = ($_POST['comments']); $submit = ($_POST['signup']); 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', 'xxxxxx', 'xxxxxx') 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 receive :' .implode(", ",$_POST['categories']) . '<br /> <br />'; echo 'You have signed up to receive ' .implode(", ",$_POST['days']) . '<br /> <br />'; echo 'And you have signed up to receive the following amount:' . $_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(); } else { echo '<p> An account already exists with this username. Please select a different username. </p>'; $output_form = true; } } else { echo 'Attention! Unfortunately you did not provide all of the required sign up information. <br /> <br /> To sign up, please fill out all of the required form fields and make sure you confirm your password correctly. Thankyou'; $output_form = true; } } else { $output_form = true; } if ($output_form) { ?> <div id="form"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table> <tr> <th> General Info: </th> <td id="us"> Tell Us About Yourself </td> </tr> <tr> <th> </th> <td> <table> <tr> <td> <span class="star"> * </span> Firstname: </td> <td> <input type="text" name="firstname" value="<?php if(isset($_POST['signup'])) echo $_POST['firstname']; ?>" /> </td> </tr> <tr> <td> <span class="star"> * </span> Lastname: </td> <td> <input type="text" name="lastname" value="<?php if(isset($_POST['signup'])) echo $_POST['lastname']; ?>" /> </td> </tr> <tr> <td> <span class="star"> * </span> Username: </td> <td> <input type="text" name="username" value="<?php if(isset($_POST['signup'])) echo $_POST['username']; ?>" /> </td> </tr> <tr> <td> <span class="star"> * </span> Password: </td> <td> <input type="password" id="password1" name="password1" /> </td> </tr> <tr> <td> <span class="star"> * </span> Confirm Password: </td> <td> <input type="password" id="password2" name="password2" /> </td> </tr> <tr> <td> <span class="star"> * </span> Phone #: </td> <td> <input type="text" name="phonenumber[]" value="<?php if(isset($_POST['signup'])) echo $_POST['phonenumber']['0']; ?>" maxlength="3" size="3" /> <input type="text" name="phonenumber[]" value="<?php if(isset($_POST['signup'])) echo $_POST['phonenumber']['1']; ?>" maxlength="3" size="3" /> <input type="text" name="phonenumber[]" value="<?php if(isset($_POST['signup'])) echo $_POST['phonenumber']['2']; ?>" maxlength="4" size="4" /> </td> </tr> <tr> <td> <span class="star"> * </span> Sex: </td> <td> <input type="radio" name="sex" value="male"<?php if(isset($_POST['signup']) && isset($_POST['sex']) && $_POST['sex']=='male') echo "checked='checked'"; ?> /> male <input type="radio" name="sex" value="female"<?php if(isset($_POST['signup']) && isset($_POST['sex']) && $_POST['sex']=='female') echo "checked='checked'"; ?> /> female </td> </tr> <tr> <td> <span class="star"> * </span> Date of Birth: </td> <td> <select name="month"> <?php $months = array('jan'=>'January', 'feb'=>'February', 'mar'=>'March', 'apr'=>'April', 'may'=>'May', 'june'=>'June', 'july'=>'July', 'aug'=>'August', 'sep'=>'September', 'oct'=>'October', 'nov'=>'November', 'dec'=>'December'); foreach($months as $k1=>$v1) { $echo_out0 = "<option value='".$k1."'"; if(isset($_POST['signup'])) { if($k1==$_POST['month']) { $echo_out0 .= " selected='selected'"; } } $echo_out0 .=">".$v1."</option>\n"; echo $echo_out0; } ?> </select> <select name="day"><?php for ($i = 1; $i <= 31; $i++) { $echo_out0_1 = "<option value='".$i."'"; if(isset($_POST['signup'])) { if($i==$_POST['day']) { $echo_out0_1 .= " selected='selected'"; } } $echo_out0_1 .= ">".$i."</option>"; echo $echo_out0_1; } ?> </select> <select name="year"><?php for ($i = 2010; $i >= 1900; $i--) { $echo_out0_2 = "<option value='".$i."'"; if(isset($_POST['signup'])) { if($i==$_POST['year']) { $echo_out0_2 .= " selected='selected'"; } } $echo_out0_2 .= ">".$i."</option>"; echo $echo_out0_2; } ?> </select> </td> </tr> </table> </td> </tr> <tr> <th> <span class="star"> * </span> Categories: </th> <td id="cat"> Choose the categories </td> </tr> <tr> <th> </th> <td> <?php $required_checkboxes = array('all'=>'All Categories', 'fastfood'=>'Fast Food', 'restaurants'=>'Restaurants', 'bars/clubs'=>'Bars/Clubs', 'a'=>'A', 'b'=>'B', 'c'=>'C'); $counter = 1; foreach($required_checkboxes as $k1=>$v1) { $echo_out = "<input type='checkbox' name='categories[]' value='".$k1."'"; if(isset($_POST['signup']) && isset($_POST['categories'])) { foreach($_POST['categories'] as $k2=>$v2) { if ($k1==$v2) { $echo_out .=" checked='checked'"; break 1; } } } $echo_out .= " /> ".$v1; echo $echo_out; $counter++; if($counter>4) echo "<br />"; } ?> </td> </tr> <tr> <th> <span class="star"> * </span> Days: </th> <td id="run"> Choose the days you </td> </tr> <tr> <th> </th> <td> <?php $days = array('Everyday','Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); foreach($days as $k1=>$v1) { $echo_out2 = "<input type='checkbox' name='days[]' value='".$v1."'"; if(isset($_POST['signup']) && isset($_POST['days'])) { foreach($_POST['days'] as $k2=>$v2) { if ($v1==$v2) { $echo_out2 .= " checked='checked'"; break 1; } } } $echo_out2 .= " /> ".$v1." <br />"; echo $echo_out2; } ?> </td> </tr> <tr> <th> <span class="star"> * </span> # of Texts: </th> <td id="walk"> Choose the / category / day </td> </tr> <tr> <th> </th> <td id="walk1"> NOTE: You may not always receive the max # of text messages </td> </tr> <tr> <th> </th> <td> <select name="text"> <?php $text_options = array('unlimited'=>'Unlimited', '1'=>'1', '3'=>'3', '5'=>'5', '10'=>'10', '15'=>'15', '20'=>'20', '25'=>'25', '50'=>'50'); foreach($text_options as $k1=>$v1) { $echo_out3 = "<option value='".$k1."'"; if(isset($_POST['signup'])) { if($k1==$_POST['text']) { $echo_out3 .= " selected='selected'"; } } $echo_out3 .= ">".$v1."</option>\n"; echo $echo_out3; } ?> </select> </td> </tr> <tr> <th> Comments: </th> <td> <textarea name="comments" rows="10" cols="50"><?php if(isset($_POST['signup'])) echo $_POST['comments']; ?> Comments/Suggestions </textarea> </td> </tr> </table> <p id="end"> <input type="submit" value="SignUp" name="signup" /> </p> </form> </div> <?php } ?> <p id="copyright"> Copyright 2010 © TheTextNook.com - All rights reserved <span id="about"> <a href="about.html"> About </a> </span> <span id="privacy"> <a href="about.html"> Privacy </a> </span> <span id="contact"> <a href="about.html"> Contact Us </a> </span> <span id="advertise"> <a href="about.html"> Advertise </a> </span> </p> </div> </body> </html>
-
I have a form that allows people to choose days of the week and categories. They are checkboxes. No matter what checkboxes I pick, the word 'array' is all that gets stored in my database. Anyone know how to fix it? Here's the code <?php $required_checkboxes = array('all'=>'All Categories', 'fastfood'=>'Fast Food', 'restaurants'=>'Restaurants', 'bars/clubs'=>'Bars/Clubs', 'a'=>'A', 'b'=>'B', 'c'=>'C'); $counter = 1; foreach($required_checkboxes as $k1=>$v1) { $echo_out = "<input type='checkbox' name='categories[]' value='".$k1."'"; if(isset($_POST['signup']) && isset($_POST['categories'])) { foreach($_POST['categories'] as $k2=>$v2) { if ($k1==$v2) { $echo_out .=" checked='checked'"; break 1; } } } $echo_out .= " /> ".$v1; echo $echo_out; $counter++; if($counter>4) echo "<br />"; } ?> <?php $days = array('Everyday','Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'); foreach($days as $k1=>$v1) { $echo_out2 = "<input type='checkbox' name='days[]' value='".$v1."'"; if(isset($_POST['signup']) && isset($_POST['days'])) { foreach($_POST['days'] as $k2=>$v2) { if ($v1==$v2) { $echo_out2 .= " checked='checked'"; break 1; } } } $echo_out2 .= " /> ".$v1." <br />"; echo $echo_out2; } ?>
-
I have a form that asks for phonenumber. The phone number is sticky, but it is just storing a '0' in my database. Anyone know what is wrong? <tr> <td> <span class="star"> * </span> Phone #: </td> <td> <input type="text" name="phonenumber[]" value="<?php if(isset($_POST['signup'])) echo $_POST['phonenumber']['0']; ?>" maxlength="3" size="3" /> <input type="text" name="phonenumber[]" value="<?php if(isset($_POST['signup'])) echo $_POST['phonenumber']['1']; ?>" maxlength="3" size="3" /> <input type="text" name="phonenumber[]" value="<?php if(isset($_POST['signup'])) echo $_POST['phonenumber']['2']; ?>" maxlength="4" size="4" /> </td> </tr>
-
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
-
I'm getting an 'error querying database' saying when I hit submit with the entire form filled out. Anyone know what the problem is? Note: the 'xxx' in $dbc are my personal info that I just took out for security sake. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title> TheTextNook Sign up - Results </title> <link type="text/css" rel="stylesheet" href="signup.css" /> </head> <body> <div id="allcontent"> <h1> <span id="title"> TextNook </span> <span id="home"> <a href="home.html"> Home </a> </span> </h1> <h2> TextNook Sign Up </h2> <?php $firstname = ($_POST['firstname']); $lastname = ($_POST['lastname']); $username = ($_POST['username']); $password1 = ($_POST['password1']); $password2 = ($_POST['password2']); $phonenumber = ($_POST['phonenumber']); $sex = ($_POST['sex']); $month = ($_POST['month']); $day = ($_POST['day']); $year = ($_POST['year']); $categories = ($_POST['categories']); $days = ($_POST['days']); $text = ($_POST['text']); $comments = ($_POST['comments']); $submit = ($_POST['signup']); 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', 'xxxx', 'xxxx', 'xxxxxx') or die ('Error connecting to MySQL server.'); mysql_select_db ('thetextnook', $dbc); $query = "SELECT * FROM textnook WHERE user_name = '{$_POST['username']}'"; $data = mysql_query ($query); if (mysql_num_rows($data) == 0) { $query = "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 ($query, $dbc) or die ('Error querying database.'); echo 'Sign Up Confirmed' . '<br /> <br />'; echo 'Thanks for joining TextNook!' . '<br /> <br />'; echo 'You have signed up to receive text messages for the following categories:' .implode(", ",$_POST['categories']) . '<br /> <br />'; echo 'You have signed up to receive text messages on the following days:' .implode(", ",$_POST['days']) . '<br /> <br />'; echo 'And you have signed up to receive the following amount of text message(s) 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);