john_wenhold Posted February 3, 2010 Share Posted February 3, 2010 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); Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 3, 2010 Share Posted February 3, 2010 For debug purposes, it would be useful to print out mysql_error() on the die() call. Obviously not the way to go for a finished product, but useful whilst developing to say or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
schilly Posted February 3, 2010 Share Posted February 3, 2010 well you likely have an error in your query. change $result = mysql_query ($query, $dbc) or die ('Error querying database.'); to $result = mysql_query ($query, $dbc) or die ("MYSQL ERROR: $query - " . mysql_error()); and see what it says. Quote Link to comment 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.