I’m new to this and I’m not sure if this is a php question or a sql, but I have a form with no required fields where when submit it updates columns in a database row. Currently, when the form is submitted if an input is left empty it updates the corresponding column with the empty space and erasing the value that was once there. What I am trying to figure out is how to make it so upon form submission, if an input value is empty, it doesnt update the database column.
if ( isset($_POST['submit']) ) {
$user = $_SESSION['user_name'];
$signature = $mysqli->real_escape_string($_POST['signature']);
$skype = $mysqli->real_escape_string($_POST['skype']);
$facebook = $mysqli->real_escape_string($_POST['facebook']);
$insert = $mysqli->query("
UPDATE users
SET u_signature='$signature', u_skype='$skype', u_facebook='$facebook'
WHERE u_name='$user'
") or die ($mysqli->error);
1 Answer