Fira Posted September 26, 2006 Share Posted September 26, 2006 Here is my PHP code in adding a new user to two tables, one being USER and the other being CHARACTER.[quote]$newpass = "1"; //substr(md5(time()),0,6); $sql = "INSERT INTO user SET userid = '$_POST[newid]', password = '$newpass', email = '$_POST[newemail]'"; if (!mysql_query($sql)) error('Error at insert user info.' . mysql_error());echo "pass1"; $sql = "INSERT INTO character SET chara = '0'";if (!mysql_query($sql)) error('Error at insert character info.' . mysql_error());echo "pass2";[/quote]Both tables USER and CHARACTER have an auto-increment variable "id," both starting at 1. The code adds in the information into table USER, but not CHARACTER. When I run the code, "pass2" doesn't display, and when I check my character table, it's empty. What's wrong?Note that both tables are empty to begin with, and after the code is run, table USER has been filled out, but table CHARACTER has not. Quote Link to comment Share on other sites More sharing options...
Guest WarpNacelle Posted September 26, 2006 Share Posted September 26, 2006 It looks like you have used the syntax for an UPDATE statement rather then an INSERT.I believe your query should be:[code]INSERT INTO user (userid, password, email) VALUES ('$newid', '$newpass', '$newemail')[/code](I would suggest vaildating your $_POST variables and setting them like so - $newid = $_POST[newid])Give that a try... Quote Link to comment Share on other sites More sharing options...
Fira Posted September 26, 2006 Author Share Posted September 26, 2006 Yes, either way works, but the problem is the second part of the code, where I'm trying to set chara=0 in table CHARACTER. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 26, 2006 Share Posted September 26, 2006 Not sure... if you're not getting an error, something else is wrong. Quote Link to comment Share on other sites More sharing options...
Fira Posted September 26, 2006 Author Share Posted September 26, 2006 I've just removed the ". mysql_error()" portion of the code, and it displays the error "Error at insert character chara." Quote Link to comment Share on other sites More sharing options...
fenway Posted September 26, 2006 Share Posted September 26, 2006 Maybe it's a reserved keyword. Quote Link to comment Share on other sites More sharing options...
Daen Posted September 26, 2006 Share Posted September 26, 2006 [url=http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html]http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html[/url]This page says that 'Character' is a reserved word. That might be affecting it, since that's your table name. Quote Link to comment Share on other sites More sharing options...
fenway Posted September 27, 2006 Share Posted September 27, 2006 If adding backticks works, then yes... Quote Link to comment Share on other sites More sharing options...
Fira Posted October 7, 2006 Author Share Posted October 7, 2006 Awesome, I changed the table name to chara and it worked. Thanks. 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.