spode Posted May 30, 2007 Share Posted May 30, 2007 I'm clueless...the data isn't inserting into the database and it's not showing any errors. Any ideas? <?php case 'new': if(isset($_POST['submit'])) { $newusername = $_POST['newusername']; $newpassword = $_POST['newpassword']; $createaccount = "INSERT INTO tbl_users values ('$newusername','$newpassword')" or die(mysql_error()); $result = mysql_query($account); echo "<p>Go back to the account viewer by clicking <a href=\"show_ids.php\">here</a></p>"; } else { echo "<h1>New Account</h1> <form action=\"crud.php?action=new\" method=\"post\"> <table> <tr> <td>Username:</td> <td><input type=\"text\" name=\"newusername\" size=\"20\"></td> </tr> <tr> <td>Password:</td> <td><input type=\"password\" name=\"newpassword\" size=\"20\"></td> </tr> <tr> <td><input type=\"submit\" name=\"submit\" value=\"Register\"></td> </tr> </form> </table>"; } break; ?> thanks Link to comment https://forums.phpfreaks.com/topic/53493-data-not-being-inserted/ Share on other sites More sharing options...
gabeg Posted May 30, 2007 Share Posted May 30, 2007 does just this work? <?php $createaccount = "INSERT INTO tbl_users values ('test','pass')" or die(mysql_error()); $result = mysql_query($account); ?> [code] [/code] Link to comment https://forums.phpfreaks.com/topic/53493-data-not-being-inserted/#findComment-264404 Share on other sites More sharing options...
conker87 Posted May 30, 2007 Share Posted May 30, 2007 I've edited your code a little. But it's mostly the same. You're query variable was not the same name as the mysql_query() result. <?php if(isset($_POST['submit'])) { $newusername = $_POST['newusername']; $newpassword = $_POST['newpassword']; $createaccount = "INSERT INTO `tbl_users` VALUES('$newusername','$newpassword')" or die(mysql_error()); $result = mysql_query($createaccount); //this was $account and not $createaccount echo "<p>Go back to the account viewer by clicking <a href=\"show_ids.php\">here</a></p>"; } else { echo "<h1>New Account</h1> <form action=\"crud.php\" method=\"post\"> <table> <tr> <td>Username:</td> <td><input type=\"text\" name=\"newusername\" size=\"20\"></td> </tr> <tr> <td>Password:</td> <td><input type=\"password\" name=\"newpassword\" size=\"20\"></td> </tr> <tr> <td><input type=\"submit\" name=\"submit\" value=\"Register\"></td> </tr> </form> </table>"; } ?> Link to comment https://forums.phpfreaks.com/topic/53493-data-not-being-inserted/#findComment-264407 Share on other sites More sharing options...
gabeg Posted May 30, 2007 Share Posted May 30, 2007 I noticed this too, you are adding the mysql_error to the wrong line of your script. you want the error to appear when you do the mysql_query call. change $createaccount = "INSERT INTO `tbl_users` VALUES('$newusername','$newpassword')" or die(mysql_error()); $result = mysql_query($createaccount); to <?php $createaccount = "INSERT INTO `tbl_users` VALUES('$newusername','$newpassword')"; $result = mysql_query($createaccount) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/53493-data-not-being-inserted/#findComment-264408 Share on other sites More sharing options...
spode Posted May 30, 2007 Author Share Posted May 30, 2007 ok, now i'm getting the MySQL syntax error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''tbl_users' VALUES ('gensilver91','tennis')' at line 1 hmm? Link to comment https://forums.phpfreaks.com/topic/53493-data-not-being-inserted/#findComment-264413 Share on other sites More sharing options...
gabeg Posted May 30, 2007 Share Posted May 30, 2007 ok, now i'm getting the MySQL syntax error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''tbl_users' VALUES ('gensilver91','tennis')' at line 1 hmm? your mysql syntax is wrong, you don't put the names of the columns in your database http://www.tizag.com/mysqlTutorial/mysqlinsert.php "INSERT INTO 'tbl_users' (username, password) VALUES('$username', '$password')" Link to comment https://forums.phpfreaks.com/topic/53493-data-not-being-inserted/#findComment-264414 Share on other sites More sharing options...
spode Posted May 30, 2007 Author Share Posted May 30, 2007 it works now, thanks guys Link to comment https://forums.phpfreaks.com/topic/53493-data-not-being-inserted/#findComment-264415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.