how to create edit form .and update user data my table is;

id int auto_increment
Name
Department
Problem
Ext_no
Ip_Add
Remark
Email
Status (set)

My view table code is ;-

<?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>
                </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='edit.php'>Edit</a>  <a href='delete.php'>Delete</a></td>

                </tr>

EOM;
}

        echo <<<EOTABLE

        </table>

EOTABLE;

?>

Recommended Answers

All 3 Replies

<a href='edit.php'>Edit</a>

First you will have to tell edit.php which user you want to edit, so change this to:

<a href='edit.php?id={$row['id']}'>Edit</a>

Now you can use $_GET['id'] in your edit script to retrieve the details.

here is my edit.php code but data not updated.please correct the code..

error message in page

Notice: Undefined variable: submit in edit.php on line 68

Notice: Undefined index: in edit.php on line 68

//change user and password to your mySQL name and password

<?php 
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost", "root", "");

//select which database you want to edit
mysql_select_db("users"); 

     $result = mysql_query("select * from entryform order by id"); 

   while($r=mysql_fetch_array($result)) 
   { 

       $id=$r["id"];
      $Name=$r["Name"];    
      $Department=$r["Department"];
      $Problem=$r["Problem"];  
      $Ext_no=$r["Ext_no"];
      $Ip_Add=$r["Ip_Add"];  
      $Remark=$r["Remark"];
      $Email=$r["Email"];  
      $Status=$r["status"];            

      echo "";
    // echo "<a href='edit.php?id=edit&id=$id'>Edit - $id $Name $Department $Problem $Ext_no $Ip_Add $Remark $Email $Status</a>";
      echo "";
    }    
?>           
<?php    
   if (!isset($_POST["submit"]))
   {
      $id = $_GET["id"];
      $sql = "SELECT * FROM entryform WHERE id=$id";
      $result = mysql_query($sql);        
      $row = mysql_fetch_array($result);
?>

      <form action="edit.php" method="post"  >
      <input type=hidden name="id" value="<?php echo $row["id"] ?>">

Name:<input type="text" name="make" value="<?php echo $row["Name"] ?>" size=30 /><br />
     Department:<input type="text" name="Department" value="<?php echo $row["Department"] ?>" size=30 /><br />
      Problem:<input type="text" NAME="Problem" value="<?php echo $row["Problem"] ?>" size=30 /><br />
      Ext no:<input type="text" NAME="Ext no" value="<?php echo $row["Ext_no"] ?>" size=30 /><br />
      Ip Add:<input type="text" NAME="Ip Add" value="<?php echo $row["Ip_Add"] ?>" size=30 /><br />
      Remark:<input type="text" NAME="Remark" value="<?php echo $row["Remark"] ?>" size=30 /><br />
      Email:<input type="text" NAME="Email" value="<?php echo $row["Email"] ?>" size=30 /><br />
     Status:<input type="text" NAME=" Status" value="<?php echo $row["status"] ?>" size=30 /><br />

      <input type="hidden" name="cmd" value="edit" />

      <input type="submit" name="submit" value="submit" />       
      </form>

        <?php 
     } 

   if ($_POST["$submit"])
   {
      $Name = $_POST["Name"];
      $Department = $_POST["Department"];
      $Problem = $_POST["Problem"];
      $Ext_no = $_POST["Ext_no"];
      $Ip_Add = $_POST["Ip_Add"];
      $Remark = $_POST["Remark"];
      $Email = $_POST["Email"];
      $Status = $_POST["status"];         

      $sql = "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";       
      $result = mysql_query($sql);
      echo "Thank you! Information updated.";       }

?>    
</body>
</html>

See if you get an error:

$result = mysql_query($sql) or die(mysql_error());
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.