How to only update a record when form value is not null?
Posted: Sat Nov 29, 2008 1:21 am
Hello,
i need a solution to this, can't seem to find it anywhere.
This is a stripped down form, with only the parts where i have the problem with
Thats it...When someone only enters a value in only one input, i.e. name, and leaves the rest blank, and clicks submit, it updates the table's field name2 and name3 with blank value....it erases the old record... How to use boolean to make the table only update the field with values that are not null in the form?
i need a solution to this, can't seem to find it anywhere.
Code: Select all
<?php
$name = $_POST["name"];
$name2 = $_POST["name2"];
$name3 = $_POST["name3"];
$con = mysql_connect("localhost","xxxxxxxxx","xxxxxxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxxxxxxx", $con);
$queryb = "UPDATE usersite SET name='$name', name2='$name2', name3='$name3' WHERE user='zvork'";
mysql_query($queryb) or die(mysql_error());
mysql_close($con)
?>
<html>
<body>
<table summary="">
<tr>
<td valign="top">
<form width="" style="background-color: #fff; " action="mysites.php" method="post">
name: <input type="text" size="30" name="name" /><br>
name2: <input type="text" size="30" name="name2" /><br>
name3: <input type="text" size="30" name="name3" /><br>
<input type="submit" value="submit" />
</form>
<br><br><br><br>
<table align="center"><tr><td>
<a href="/admin.php">Go back</a>
<br><br>
</td>
</tr>
</table>
</body>
</html>
Thats it...When someone only enters a value in only one input, i.e. name, and leaves the rest blank, and clicks submit, it updates the table's field name2 and name3 with blank value....it erases the old record... How to use boolean to make the table only update the field with values that are not null in the form?