I've tried to setup a script that when a form submits information to the PHP file, it will update the MySQL table. But I've tried to make it not update the database if the Post is blank/null. But it's not updating the table.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$nickname = $_POST['nickname'];
$user = $_POST['user'];
$enc_pass = md5($password);
$con=mysqli_connect("","","","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (!isset($name)){
mysqli_query($con,'UPDATE members SET name="$name"
WHERE username="$user"');
}
if(!$email == ""){
mysqli_query($con,'UPDATE members SET username="$email"
WHERE username="$user"');
}
if(!$password == ""){
mysqli_query($con,'UPDATE members SET password="$enc_pass"
WHERE username="$user"');
}
if(!$nickname == ""){
mysqli_query($con,'UPDATE members SET nickname="$nickname"
WHERE username="$user"');
}
mysqli_close($con);
?>
I've removed the MySQL credentials for safety. Can anyone help me with this?
Regards TameTimmah
md5is old and you may (eventually) get hacked. You really need to use prepared statements with this. Read this and this too