I use the following code to store the email and passwords in my database when logging in, but somehow it only stores the passwords. The email field remains NULL in the database. Any suggestions?
Here’s the code:
<?php
define('DB_NAME', 'XXXXXXX');
define('DB_USER', 'XXXXXXX');
define('DB_PASSWORD', 'XXXXXXX');
define('DB_HOST', 'db.example.com');
$link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not Connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
$value = $_POST['email'];
$value = $_POST['password'];
$sql = "INSERT INTO demo (email) VALUES ('$value')";
$sql = "INSERT INTO demo (password) VALUES ('$value')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
mysql_close();
?>
You are first saying $value is the email adddress. Then you are saying $value is the password.
So when you insert, $value is always going to be password. Try renaming your variables.
Don’t forget to secure for SQL injections. Do some searching on SO for this.