lilman Posted November 11, 2006 Share Posted November 11, 2006 I have been at this for hours, and I am stumped and feeling dumb. I for the life of me cannot figure out why query will not execute. I know it has nothing to do with the database connection, seeing that I've tested it. I have even gone as far as trying to insert default values instead of calling variables. I have tried both queries, and both return false. I know the variables contain something as it prints all the values if the query doesn't execute. I have pasted the code below, if anyone could help me out I would really appreciate it. Thanks/*if(mysql_query("INSERT INTO users(group, user_name, password, first_name, last_name, gender, email_address) VALUES(".$group.", ".$user_name.", ".$password.", ".$first_name.", ".$last_name.", ".$gender.", ".$email_address.")"))*/if(mysql_query("INSERT INTO usesrs (group, user_name, password, first_name, last_name, gender, email_address) VALUES ('2', 'user', 'pass', 'isaac', 'meals', 'male', 'email')")) echo "successful in registering you an account";else{ echo "couldn't submit"; echo "<br />"; echo $group; echo "<br />"; echo $first_name; echo "<br />"; echo $last_name; echo "<br />"; echo $user_name; echo "<br />"; echo $email_address; echo "<br />"; echo $password; echo "<br />"; echo $gender;} Quote Link to comment Share on other sites More sharing options...
marcus Posted November 11, 2006 Share Posted November 11, 2006 [code]$sql = "INSERT INTO usesrs (group, user_name, password, first_name, last_name, gender, email_address) VALUES ('2', 'user', 'pass', 'isaac', 'meals', 'male', 'email')";$result = mysql_query($sql);if($result){ echo "successful in registering you an account";}else{ echo "couldn't submit"; echo ""; echo $group; echo ""; echo $first_name; echo ""; echo $last_name; echo ""; echo $user_name; echo ""; echo $email_address; echo ""; echo $password; echo ""; echo $gender;}[/code] Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 11, 2006 Share Posted November 11, 2006 Is the table name users or use[b]s[/b]rs?You can get much better error trapping to help you resolve your problem. Change this:[code]if(mysql_query("INSERT INTO usesrs (group, user_name, password, first_name, last_name, gender, email_address) VALUES ('2', 'user', 'pass', 'isaac', 'meals', 'male', 'email')"))[/code]to this:[code]$query = "INSERT INTO usesrs (`group`, user_name, password, first_name, last_name, gender, email_address) VALUES ('2', 'user', 'pass', 'isaac', 'meals', 'male', 'email')";$result = mysql_query($query) or die("Error ". mysql_error(). " with query ". $query); // useful error messageif ($result) {.... etc[/code]Notice the backticks around group. Group is a MySQL reserved word and you should avoid using those as table or field names. Using backticks is a work-around.Full list of reserved words - http://www.htmlite.com/mysql002a.php Quote Link to comment Share on other sites More sharing options...
lilman Posted November 11, 2006 Author Share Posted November 11, 2006 Thanks for the replies so far. I've done what has been suggested, changed the column groud to class and edited my code. Below is both the code and the error message I get when I run it.Line 22 would be the one with $result.Notice: Use of undefined constant mysql_error - assumed 'mysql_error' in /registering.php on line 22Error mysql_error with query INSERT INTO usesrs (class, user_name, password, first_name, last_name, gender, email_address) VALUES ('2', 'lilman', 'ed9961646291a608b6c586c38a28cac45bf97c15', 'isaac', 'meals', 'Male', 'lilman87@password.com.') $query = "INSERT INTO usesrs (class, user_name, password, first_name, last_name, gender, email_address) VALUES ('$group', '$user_name', '$password', '$first_name', '$last_name', '$gender', '$email_address')"; $result = mysql_query($query) or die("Error ". mysql_error. " with query ". $query);; if($result) echo "successful in registering you an account"; else { echo "failed"; } Quote Link to comment Share on other sites More sharing options...
marcus Posted November 11, 2006 Share Posted November 11, 2006 don't bother putting the or die(); part, just to test.and you have two ;'s on that line Quote Link to comment Share on other sites More sharing options...
lilman Posted November 11, 2006 Author Share Posted November 11, 2006 Good catch, I am embrassed I missed that. I made that fix but I get the same exact message on the same exact line. Quote Link to comment Share on other sites More sharing options...
marcus Posted November 11, 2006 Share Posted November 11, 2006 You might aswell just leave the mysql error out, or just use or die(); Quote Link to comment Share on other sites More sharing options...
lilman Posted November 11, 2006 Author Share Posted November 11, 2006 The last mistake what I mispelled the table's name. Thanks for all the help! Quote Link to comment Share on other sites More sharing options...
marcus Posted November 11, 2006 Share Posted November 11, 2006 Haha, no problem! 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.