I'm currently trying to create a update type of script where a admin can click a update button, the text that's already in the database is shown in the textboxes & the admin can then replace the text if it's incorrect.
I currently have a error called "Undefined index". This is when i attempt to set a value to my text boxes from my select statement.
This is my current progress,
<?php
require 'configure.php';
if(isset($_GET['id']))
{
$id=$_GET['id'];
if(isset($_POST['Edit']))
{
$sql = "UPDATE `pet` SET `pettype` = :petType WHERE id = :id";
$statement = $pdo->prepare($sql);
$id = $_GET['id'];
$petType = $_POST['petType'];
$statement->bindValue(':id', $id);
$statement->bindValue(':petType', $petType);
$update = $statement->execute();
if($sql)
{
header('location:index.php');
}
}
$jobID = $_GET['id'];
$stmt = $pdo->query('SELECT * FROM pet WHERE petType = "' . $jobID . '"');
$result = $stmt->fetch(PDO::FETCH_ASSOC);
}
?>
This is my update code, as well as my populate statement at the bottom.
<form method="post" action="">
Name:<input type="text" name="petID" value="<?php echo $_POST['petID'] ?>" /><br />
Age:<input type="text" name="petType" value="<?php echo $_POST['petType'] ?>" /><br /><br />
<br />
<input type="submit" name="submit" value="update" />
</form>
This is my Form which i'm using to edit the data.
I've tried
value="<?php echo ($pdo['petType']) ?>"
value="<?php echo $stmt['petType'] ?>"
Perhaps someone with a little more knoeledge would be able to help. Thank you