here is my code for edit user detail but selected id is not showing .only showing last inserted id. please help me for correct this code..

 my view code

 <?php

//connects to database
$con = mysql_connect("localhost","root",""); 
if (!$con) 
  { 
  die('Could not connect: ' . mysql_error()); 
  } 

mysql_select_db("users", $con); 


//select table
$select = mysql_query("SELECT * FROM entryform") or die('No table exist!');
$numrows = mysql_num_rows($select);

        echo <<<EOM
                <table border='1'>
                <tr>
                        <th>Complaint No.</th>
                        <th> Name      </th>
                        <th>Department</th>
                        <th>Problem</th>
                        <th>Ext no.</th>
                        <th>IP Add</th>
                        <th>Remark</th>
                        <th>Email</th>
                        <th>Status</th>
                        <th>Edit /Delete </th>
                </tr>
EOM;

while ($row = mysql_fetch_assoc($select))
{
        echo <<<EOM
                <tr>
                        <td>{$row['id']}</td>
                        <td>{$row['Name']}</td>
                        <td>{$row['Department']}</td>
                        <td>{$row['Problem']}</td>
                        <td>{$row['Ext_no']}</td>
                        <td>{$row['Ip_Add']}</td>
                        <td>{$row['Remark']}</td>
                        <td>{$row['Email']}</td>
                        <td>{$row['status']}</td>
                        <td><a href='User_update/select.php?id={$row['id']}'>Edit</a>  <a href='delete.php'>Delete</a></td>

                </tr>

EOM;
}

        echo <<<EOTABLE

        </table>

EOTABLE;

?>



My select.php page


<?php
mysql_connect("localhost","root","");
mysql_select_db("users") or die("Unable to select database");

$sql = "SELECT * FROM entryform WHERE id = id ";

$result = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());

$i = 0;

echo '<table width="50%">';
echo '<tr>';
echo '<td>ID</td><br/>';
echo '<td>Name</td>';
echo '<td>Department</td>';
echo '<td>Problem</td>';
echo '<td>Ext no</td>';
echo '<td>Ip_Add</td>';
echo '<td>Remark</td>';
echo '<td>Email</td>';
echo '<td>status</td>';
echo '</tr>';

echo "<form name='form_update' method='post' action='update.php'>\n";
while ($entryform = mysql_fetch_array($result)) {
    echo '<tr>';
    echo "<td>{$entryform['id']}<input type='hidden' Name='id[$i]' value='{$entryform['id']}' />";
    echo "<td><input type='text' size='12' name='Name[$i]' value='{$entryform['Name']}'/> </td>";
    echo "<td><input type='text' size='12' name='Department[$i]' value='{$entryform['Department']}' /></td>";
    echo "<td><input type='text' size='40' name='Problem[$i]' value='{$entryform['Problem']}' /></td>";
    echo "<td><input type='text' size='10' name='Ext_no[$i]' value='{$entryform['Ext_no']}' /></td> ";
    echo "<td><input type='text' size='10' name='Ip_Add[$i]' value='{$entryform['Ip_Add']}' /></td>";
    echo "<td><input type='text' size='20' name='Remark[$i]' value='{$entryform['Remark']}' /></td>";
    echo "<td><input type='text' size='25' name='Email[$i]' value='{$entryform['Email']}' /></td>";
    echo "<td><input type='text' size='10' name='status[$i]' value='{$entryform['status']}' /></td>";

    echo '</tr>';
    ++$i;
}
echo '<tr>';
echo "<td><input type='submit' value='submit' /></td>";
echo '</tr>';
echo "</form>";
echo '</table>';
?>


my update.php page


<?php
mysql_connect("localhost","root","");
mysql_select_db("users") or die("Unable to select database");

$size = count($_POST['Name']);

$i = 0;
while ($i < $size) {
    $Name= $_POST['Name'][$i];
    $Department= $_POST['Department'][$i];
    $Problem= $_POST['Problem'][$i];
    $Ext_no= $_POST['Ext_no'][$i];
    $Ip_Add= $_POST['Ip_Add'][$i];
    $Remark= $_POST['Remark'][$i];
    $Email= $_POST['Email'][$i];
    $status= $_POST['status'][$i];
    $id = $_POST['id'][$i];


    $query = "UPDATE entryform SET Name = '$Name',Department = '$Department',Problem = '$Problem',Ext_no = '$Ext_no',Ip_Add = '$Ip_Add',Remark = '$Remark',Email = '$Email',status = '$status'WHERE id = '$id' LIMIT 1";
    mysql_query($query) or die ("Error in query: $query");
    echo "$Name<br /><br /><em>Updated!</em><br /><br />";

    ++$i;
}
?>

$sql = "SELECT * FROM entryform WHERE id = id ";

This is not right. I think this should be:

$id = isset($_GET['id']) ? $_GET['id'] : 0;
$sql = "SELECT * FROM entryform WHERE id = $id ";

$id = isset($_GET['id']) ? $_GET['id'] : 0;

error showing ...

i want to show only one page if i selected my editable row id

i want to show only one page if i selected my editable row id

Exactly what it does...

$sql = "SELECT * FROM entryform WHERE id = $id ";

Notice: Undefined variable: id in F:\wamp\www\User_update\select.php on line 13
SELECT * FROM entryform WHERE id =

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

i want show only one records then i click edit.page search my selected id but not showing only selected id details showing all records

search page code display (select.php?id=334).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.