<?php
$record = $_GET["rid"];
$db_server = "localhost";
$db_name = "database";
$db_user = "username";
$db_pass = "password";
$con1 = mysql_connect($db_server, $db_user, $db_pass) or die(mysql_error());
mysql_select_db($db_name, $con1);
if (isset($_POST['submit']) && $_POST['submit'] == "Update") {
$query_update = "UPDATE table SET " .
"date = '" . $_POST['date'] . "', " .
"amount = '" . $_POST['amount'] . "', " .
"description = '" . implode(", ",$_POST['description']) . "', " .
"name = '" . $_POST['name'] . "', " .
"paid = '" . $_POST['paid'] . "', " .
"id = '" . $_POST['id'] .
"' WHERE id = '" . $record . "'";
$result_update = mysql_query($query_update) or die(mysql_error());
header("Location: view_table.php");
}
else {
$query = "SELECT * FROM table " .
"WHERE id = '" . $record . "'";
$result = mysql_query($query)
or die(mysql_error());
$row = mysql_fetch_array($result);
$description = explode(", ", $row['description']);
?>
<h1>Update Debt</h1>
Date: <input type="text" name="date" value="<?php echo $row['date']; ?>" /> <br />
Amount: <input type="text" name="amount" value="<?php echo $row['amount']; ?>" /> <br />
Description: <textarea name="description[]"><?php echo $row['description']; ?></textarea> <br />
Name: <input type="text" name="name" value="<?php echo $row['name']; ?>" /> <br />
Paid: <input type="text" name="paid" value="<?php echo $row['paid']; ?>" /> <br />
ID: <input type="text" name="id" value="<?php echo $row['id']; ?>" /> <br />
<input type="submit" name="submit" value="Update" />
<?php
}
?>