Edit MySQL Row PHP

ahinkle

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

Here is the code:

index.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

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

    <center>
    <?php
    /* 
        VIEW.PHP
        Displays all data from 'players' table
    */

        // connect to the database
        include_once('../connection.php');

        // 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>";
    ?>
    </center>

edit.php

<?php
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());

if(mysql_num_rows($query)>=1){
    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">
</form>
<?php
}else{
    echo 'No entry found. <a href="javascript:history.back()">Go back</a>';
}
?>
</body>
</html>

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
Rexie Galban

Use: $_GET['id']

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

instead of

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related