Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving Passwords to a mySQL Database

Status
Not open for further replies.

rvr1

Programmer
Feb 6, 2004
16
NL
I am attempting to save a password to a mySQL table using the following code:

$sql = "INSERT INTO ModLoginTable (ModLogName,password)
VALUES ('$modlogname',password('$randompassword')";

mysql_query($sql) or die ("Cannot create a new entry in the Table");

However, it dosen't want to work. I know that the variable $modlogname is valid as I can insert it into other tables, and the variable $randompassword is also correct.

I'm very new to PHP - am I missing something basic??

Thanks,

Rob
 
Pls add mysql_error() in order to know what is the error that you are getting:

mysql_query($sql) or die ("Cannot create a new entry in the Table" . mysql_error());

Cheers.
 
The error message I get is:

Cannot create a new entry in the ModLoginTable Table You have an error in your SQL syntax near '' at line 2

Thanks for the help so far :)
Rob
 
I guess line 2 is the $sql="Insert..."

Insert sintax looks ok... did you try:

VALUES ('" . $modlogname . "',password('" . $randompassword . "')";

just in case?

add "echo $sql;" before the query and after the $sql="insert.." in order to see what sentence is issuing to the DB.
 
By reversing the order of the insert values, it now works!

$sql = "INSERT INTO ModLoginTable (password,ModLogName)
VALUES (password('$randompassword'),'$modlogname')";

mysql_query($sql) or die ("Cannot create a new entry in the ModLoginTable Table" . mysql_error());

Thanks for the help :)
 
<what> !!!!!?????????????? </what>

quite weird... but if it is working now.. good for you.

Cheers.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top