I know, but when I do that, only the PHP shows up. The html just disappears. I’ll try again:
- edit_master_list.php
<?php
session_start();
require_once('inc/db_connect.php');
?>
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset = "utf-8"> <!-- must be within the first 512 characters of the html code and before any content -->
<title>Test</title>
<meta name="description" content="">
<meta name="author" content="">
</head>
<body class="master_list">
<div id = "wrapper">
<h1>List of Organizations for Editing</h1>
<table>
<tr>
<th>First Name</th>
<th>Address</th>
<th>Phone</th>
</tr>
<?php
// query for selected information for all organizations
$query = "SELECT id, first_name, address, phone
FROM pdo_test
ORDER BY first_name ASC";
$stmt = $db->query($query);
$result = $stmt->fetchAll();
?>
<?php
foreach ($result as $row) {
$id = $row['id'];
echo '<tr>';
echo '<td>' . $row['first_name'] . '</td>';
echo '<td>' . $row['address'] . '</td>';
echo '<td>' . $row['phone'] . '</td>';
echo '<td><a href="edit_info.php?id=' . $id . '">Edit</a></td>';
echo '</tr>';
}
?>
</table>
</div><!-- end of #wrapper -->
</body>
</html>
- edit_info.php
<?php
session_start();
require_once('inc/db_connect.php');
if (isset($_GET['id'])) {
$id = $_GET['id'];
$_SESSION['id'] = $id;
$edit_query = "SELECT id, first_name, address, phone
FROM pdo_test
WHERE id = $id";
$stmt = $db->prepare($edit_query);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
// print_r($result);
$num_items = sizeOf($result);
// echo $num_items;
//Profile Information
$first_name = $result['first_name'];
$address = $result['address'];
$phone = $result['phone'];
} else {
header('location: edit_info.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset = "utf-8"> <!-- must be within the first 512 characters of the html code and before any content -->
<title>Restore Canada | Edit Organization Info</title>
<meta name="description" content="">
<meta name="author" content="">
</head>
<body class="form_page">
<div id = "wrapper">
<h2>Edit Information for "<?php echo $first_name; ?>"</h2>
<p>Return to the <a href="edit_master_list.php">list of organizations</a>.</p>
<form action="process_edit.php" method="post">
<table>
<tr>
<td><label for="first_name">First Name</label></td>
<td>
<input type="text" name="first_name" id="first_name" value="<?php echo $first_name; ?>">
<input type="hidden" name="id" id="info_id" value="<?php echo $id; ?>">
</td>
</tr>
<tr>
<td><label for="address">Address</label></td>
<td><input type="text" name="address" id="address" value="<?php echo $address; ?>"></td>
</tr>
<tr>
<td><label for="phone">Phone</label></td>
<td><input type="text" name="phone" id="phone" value="<?php echo $phone; ?>"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Edit Info"></td>
</tr>
</table>
</form>
</div><!-- end of #wrapper -->
</body>
</html>
- process_edit.php
<?php
session_start();
require_once('inc/db_connect.php');
// initialize extra variables
if (isset($_POST['id'])) {
$id = $_POST['id'];
$first_name = $_POST['first_name'];
$address = $_POST['address'];
$phone = $_POST['phone'];
echo $id . " :: " . $first_name . " :: " . $address . " :: " . $phone . "<br />";
$data = array(
':first_name' => $first_name,
':address' => $address,
':phone' => $phone,
':id' => $id
);
// insert the data
$query = "UPDATE pdo_test
SET first_name = ':first_name',
address = ':address',
phone = ':phone',
WHERE id = ':id'
";
/*$query = "UPDATE pdo_test
SET first_name = $first_name,
address = $address,
phone = $phone,
WHERE id = $id
";*/
$stmt = $db->prepare($query);
echo $query . "<br />";
// perform the database query
$stmt->execute($data);
var_dump($data);
//header('location:edit_master_list.php?msg=yes_update');
//exit();
} else {
header('location:edit_master_list.php?msg=no_id');
exit();
}
?>
This is what I’m getting.