Andy Hinkle Andy Hinkle - 4 months ago 29x
MySQL Question

Edit MySQL Row PHP

I'm trying to edit and update a row using PHP.

Here is the code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">

<div class="header">
<?php include 'header.php';?>

Displays all data from 'players' table

// connect to the database

// get results from database
$query = "SELECT EmployeeName, DOB, Age, StreetAddress, City, State, ZipCode,
Email, HomePhone, Wireless, JobTitle, id, HomeDept, Manager FROM headcount ORDER BY `headcount`.`EmployeeName` ASC";

$response = @mysqli_query($dbc, $query);

// display data in table
echo "<p><b>View All</b> | <a href='../employees/rides.php'>Rides</a></p>";

echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>Employee Name</th> <th>Home Department</th> <th>Job Title</th> <th>Edit</th></tr>";

// loop through results of database query, displaying them in the table
while($row = mysqli_fetch_array($response)){

// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['EmployeeName'] . '</td>';
echo '<td>' . $row['HomeDept'] . '</td>';
echo '<td>' . $row['JobTitle'] . '</td>';
echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
echo "</tr>";

// close table>
echo "</table>";


mysql_connect('localhost', 'root', 'root') or die(mysql_error());
mysql_select_db("hwss") or die(mysql_error());

$UID = (int)$_GET['ID'];
$query = mysql_query("SELECT * FROM headcount WHERE id = '$UID'") or die(mysql_error());

while($row = mysql_fetch_array($query)) {
$EmployeeName = $row['EmployeeName'];
$DOB = $row['DOB'];
$Age = $row['Age'];
$email = $row['email'];
<form action="update.php" method="post">
<input type="hidden" name="ID" value="<?=$UID;?>">
email: <input type="text" name="ud_email" value="<?=$email;?>"><br>
Name: <input type="text" name="ud_EmployeeName" value="<?=$EmployeeName?>"><br>
DOB: <input type="text" name="ud_dob" value="<?=$DOB?>"><br>
Age: <input type="text" name="ud_Age" value="<?=$Age?>"><br>
<input type="Submit">
echo 'No entry found. <a href="javascript:history.back()">Go back</a>';

When I click edit it says "No entry found" with the back link on each ID url. I understand that I don't have any Update code yet. I'm simply just trying to get it to display the data before adding the rest.

Error Message

Notice: Undefined index: ID in C:\xampp\htdocs\Scheduling\Employees\edit.php on line 5
No entry found. Go back


Use: $_GET['id']

$UID = (int)$_GET['id'];

instead of

$UID = (int)$_GET['ID'];