Display Table Data in the update form
I have created an update form and code for updating my 2nd table in mysql
db. The update table code is working fine. The problem I have is how do I
display the data from the 2nd table in the form fields so that it is
easier for users to ammend and then submit an update.
Hope you guys can point me where I go wrong.
Tx CS
<?php
require("common.php"); //common connects to my db
if(empty($_SESSION['user']))
{
header("Location: login.php");
die("Redirecting to login.php");
}
if(isset($_POST['update']))
{
if(!empty($_POST))
{
if(empty($_POST['hostname']))
{
die("Please enter your host name.");
}
if(empty($_POST['hostcity']))
{
die("Please enter your city.");
}
if(empty($_POST['state']))
{
die("Please enter your state.");
}
if(empty($_POST['country']))
{
die("Please enter your country.");
}
$query_params = array(
':hostid' => $_SESSION['user']['id'],
':hostname' => $_POST['hostname'],
':hostcity' => $_POST['hostcity'],
':state' => $_POST['state'],
':country' => $_POST['country']
);
$query = "
UPDATE hostdetails
SET
hostname = :hostname ,
hostcity = :hostcity ,
state = :state ,
country = :country
";
$query .= "
WHERE
hostid = :hostid
";
try
{
// Execute the query
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
//var_dump($db->ErrorInfo());
//var_dump($stmt->ErrorInfo());
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
}
}
?>
<h1>Edit Shop</h1>
<form action="editshop.php" method="post">
Username:<br />
<b><?php echo htmlentities($_SESSION['user']['username'], ENT_QUOTES,
'UTF-8'); ?></b>
<br /><br /> //from first table which i can display the username
Host Name:<br />
<input type="text" id="hostname" name="hostname" value="<?php echo
htmlentities($_SESSION['user'][':hostname'], ENT_QUOTES, 'UTF-8'); ?>"
/>
<br /><br />
Host City:<br />
<input type="text" name="hostcity" value="<?php echo
htmlentities($_SESSION['user']['hostcity']); ?>" /><br />
<br /><br />
State:<br />
<input type="text" name="state" value="<?php echo
htmlentities($_SESSION['user']['state']); ?>" /><br />
<br /><br />
Country:<br />
<input type="text" name="country" value="<?php echo
htmlentities($_SESSION['user']['country']); ?>" /><br />
<br /><br />
<input type="submit" name="update" value="Update Account" />
</form>
No comments:
Post a Comment