Hi,
im a new user to php,problem is : i want to edit/modify the data from the form to the database.kindly make certain changes to it so that the record can be modified.Attached php code is paste below:-

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 mysql_select_db("test_one", $con);


// some code
$query="select * from db_test";
$result=mysql_query($query);
?>

<?php
while($person=mysql_fetch_array($result))
{
echo "<h4>" .$person['Name']."</h4>";
echo "<h4>" .$person['Description']."</h4>";
?>
    <a href="modify.php?id=<?php echo $person['ID']; ?>" >Modify User </a>
    <br />

<?php
}
?>




</p>
<p> Creating a user</p>

<form name="form1" method="post" action="modify.php">

    Name:
        <input type="text" name="inputname" id="inputname">
     <br>
  Description:
     <input type="text" name="inputdesc" id="inputDesc">

  <br>

    <input type="submit" name="submit">

</form>


</body>
</html>

Recommended Answers

All 6 Replies

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

mysql_query("UPDATE Persons SET Age = '36'
WHERE FirstName = 'Peter' AND LastName = 'Griffin'");

mysql_close($con);
?>


ya i have gone through this code, which i named as modify.php page. but i am stuck with one point, i.e how to fetch ID a value from the code and the name with description field to get it modified.
if possible for u , can u make up a page regarding my query as described.
It would be Appreciable.

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 mysql_select_db("test_one", $con);

$query="UPDATE test_one SET name = 'modificationvalue' WHERE id = ''";
$result=mysql_query($query);
?>

    <?php
while($person=mysql_fetch_array($result))
{
echo "<h4>" .$person['Name']."</h4>";
echo "<h4>" .$person['Description']."</h4>";
?>
    <a href="modify.php?id=<?php echo $person['ID']; ?>"> Modify User </a>
    <br />

<?php
}
?>

First of all use CODE tag in editor to post your code.
Now when you have modified form with data filled.Add new hidden field with id.
So when you click on update on modify.php page, you can have $id = $_POST;
And you can have update query on that auto id.

<form name="form1" method="post" action="modify.php">
<input type="hidden" name="id" value="56" >

Thanks, nandanm
this worked out with what i wanted.. nice and comprehensive solution.

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.