I'm working on library management system. and in update field. if user didn't pass data the i want to keep my data as it is, instead of changing it into blank
<?php
if( isset($_POST['update']) )
{
$conn = mysql_connect('localhost', 'root', '');
if( !$conn )
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('library', $conn);
$Book_ID = $_POST['Book_ID'];
$Book_Name = $_POST['Book_Name'];
$Author = $_POST['Author'];
$Quantity = $_POST['Quantity'];
$sql = "update books set Book_Name='$Book_Name', Author='$Author',
Quantity='$Quantity' where Book_ID='$Book_ID'";
mysql_select_db('test_db');
$retval = mysql_query($sql, $conn);
if( !$retval )
{
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
header("refresh:2; url=updatebook.php");
mysql_close($conn);
}
else
{
?>
<form method = "post" action = "<?php $_PHP_SELF ?>">
<table width = "400" border =" 0" cellspacing = "1" cellpadding = "2">
<tr>
<td width = "100">Book ID</td>
<td><input name = "Book_ID" type = "number" id = "Book_ID"></td>
</tr>
<tr>
<td width = "100">Book Name</td>
<td><input name = "Book_Name" type = "text" id = "Book_Name"></td>
</tr>
<tr>
<td width = "100">Author</td>
<td><input name = "Author" type = "text" id = "Author"></td>
</tr>
<tr>
<td width = "100">Quantity</td>
<td><input name = "Quantity" type = "text" id = "Quantity"></td>
</tr>
<tr>
<td width = "100"> </td>
<td> </td>
</tr>
<tr>
<td width = "100"> </td>
<td>
<tr>
<td width = "100"> </td>
<td> </td>
</tr>
<tr>
<td width = "100"> </td>
<td>
<input name = "update" type = "submit" id = "update" value = "Update">
</td>
</tr>
</table>
</form>
<?php
}
?>
If user didn't want to change value of some field and keep it blank. i don't want to update that field with blank. I want to keep the data of that field, as it is.
from this code if i enter Book ID and kept Book Name, blank then this code passes the value