deed02392 Posted October 19, 2007 Share Posted October 19, 2007 <?php include 'library/config.php'; include 'library/opendb.php'; $userId = $_POST['txtUserId']; $userPass = $_POST['txtUserPass']; //this code but replace the preset input to a form dependant value $insert = 'INSERT INTO tbl_auth_user (user_id, user_password) VALUES (\'theadmin\', PASSWORD(\'chumbawamba\'));'; //my attempt not working... $insert = 'INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('$userId', PASSWORD('$userPass'));'; $result = mysql_query($insert) or die('Query failed. ' . mysql_error()); include 'library/closedb.php'; ?> Hi, I'm trying to build a registration form with mysql, I used phpmyadmin to generate me some php from entries that i made in a mysql query box, and it made that. I'm desperately trying to reword it so that it will swap the 'theadmin' string to the variable, which pulls it out of a form. The same for the password. After about 20 minutes i managed to get it working but it would just add $userId to the table rather than actually getting it from the post?? Do I need some special way of entering it in there for it to properly add? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/73973-proper-mysql_query-function-syntax/ Share on other sites More sharing options...
mattal999 Posted October 19, 2007 Share Posted October 19, 2007 $insert = 'INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('" . $userId . "', '" . $userPass . "'));'; Quote Link to comment https://forums.phpfreaks.com/topic/73973-proper-mysql_query-function-syntax/#findComment-373335 Share on other sites More sharing options...
deed02392 Posted October 19, 2007 Author Share Posted October 19, 2007 Parse error: syntax error, unexpected '"' in D:\register.php on line 23 :/ Quote Link to comment https://forums.phpfreaks.com/topic/73973-proper-mysql_query-function-syntax/#findComment-373343 Share on other sites More sharing options...
sasa Posted October 19, 2007 Share Posted October 19, 2007 $insert = "INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('" . $userId . "', '" . $userPass . "'));"; Quote Link to comment https://forums.phpfreaks.com/topic/73973-proper-mysql_query-function-syntax/#findComment-373368 Share on other sites More sharing options...
deed02392 Posted October 19, 2007 Author Share Posted October 19, 2007 Query failed. 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 ')' at line 1 What on earth? There is no php on line 1! Quote Link to comment https://forums.phpfreaks.com/topic/73973-proper-mysql_query-function-syntax/#findComment-373373 Share on other sites More sharing options...
wildteen88 Posted October 19, 2007 Share Posted October 19, 2007 Query failed. 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 ')' at line 1 What on earth? There is no php on line 1! The line number refers to your sql query and not your PHP code. Remember when using mysql_error() the generated error reported is coming from mysql and not php. Quote Link to comment https://forums.phpfreaks.com/topic/73973-proper-mysql_query-function-syntax/#findComment-373375 Share on other sites More sharing options...
sasa Posted October 19, 2007 Share Posted October 19, 2007 ups extra ')' in the end $insert = "INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('" . $userId . "', '" . $userPass . "');"; Quote Link to comment https://forums.phpfreaks.com/topic/73973-proper-mysql_query-function-syntax/#findComment-373380 Share on other sites More sharing options...
deed02392 Posted October 21, 2007 Author Share Posted October 21, 2007 Thank you, it now works without error. Unfortunately when it posts the data to the database it doesn't encrypt the password with mysql's built in encryption cipher. So it just posts the password as text. How can i alter the queries string so that it encrypts it? I'm sure the function is PASSWORD() but i'm not sure how to integrate it into this line: $insert = "INSERT INTO tbl_auth_user (user_id, user_password) VALUES ('" . $userId . "', '" . $userPass . "');"; Oh and I forgot to add, although it successfuly puts data into the database, it also adds a blank entry?! Why is this string doing that? MySQL is difficult :'( Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/73973-proper-mysql_query-function-syntax/#findComment-374875 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.