Im making a simple mysql php login, here is the code for inserting the code into a mysql database. <?php $host = localhost; $username = "deleted"; $password = "deleted"; $usern = $_POST[name]; $passw = $_POST[pass]; $database = "deleted"; mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Can't retrieve database."); $query="INSERT INTO user (username, password) values ('$usern', '$passw')"; mysql_query($query); if (!mysql_query($query)) { die('Error: ' . mysql_error()); } echo "1 user added"; mysql_close($host,$username,$password) ?> The mysql table name is 'user' and has 'username' and 'password' in the fields. when i run the script it only adds the password to mysql database and leaves the username empty, how do I fix that. thanks, Jonathan
you're inserting data into your table using: $query="INSERT INTO user (username, password) values ('$usern', '$passw')"; Code (markup): how sure are you that $usern contains a value? before that line, can you do a simple print to confirm that there is a value in the variable? i suspect it's empty: print "username to be inserted: " . $usern . "<br><br>"; $query="INSERT INTO user (username, password) values ('$usern', '$passw')"; Code (markup):
thanks sooo much. found out that on the html form i made the username variable 'user' not 'name'. Thanks.