Hi,

I need some advice on how to edit records from a mysql database using php.

Basically the record will be displayed after a particular field is chosen.

What i need to know is how can i show the field data in a drop down box one after another and display the other data corresponding to it on a page and then edit them.

e.g., i have a form which captures name, address, telephone numbers etc.

Lets say i have the names displayed in a drop down box i want the address and telephones number displayed in the page in editable format.

I have the form and other stuff just need pointer on how to display using a drop down box and edit data.

Thank you very much.

<?php
$conn=mysql_connect("localhost","root");
mysql_select_db("test");
echo "Select a name: <select name='name'>";
$query="select name from users";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$name=$row['name'];
echo "<option value='$name'>$name</option>":
}
echo "</select>";
?>

This will show all the names of table users in a dropdown box.
If this isnt what you were looking for, can you be more specific and show us your code ?

<?php
$conn=mysql_connect("localhost","root");
mysql_select_db("test");
echo "Select a name: <select name='name'>";
$query="select name from users";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$name=$row['name'];
echo "<option value='$name'>$name</option>":
}
echo "</select>";
?>

This will show all the names of table users in a dropdown box.
If this isnt what you were looking for, can you be more specific and show us your code ?

You Could place the above code in a form and submit it to a page say forms.php

code for forms.php

<?php
$conn=mysql_connect("localhost","root");
mysql_select_db("test");
$name=$_POST['name'];
$sqlQuery='Select * from user where name='."'$name'";
$queryResult= mysql_query($sqlQuery);
list($row)=mysql_fetch_row($queryResult);
$arrayKeyList=array_keys($row);
$table="<form action='update,php' method='POST'><table>";
for($i=0;$i<sizeof($row);$i++)
    {
   $table.='<tr><td>'."$arrayKeyList[$i]"."</td><td><input type='text' value=$row[$arrayKeyList[$i]] name=$arrayKeyList[$i] />";

    
    }

$table.="<input type='submit'/></table></form>";
echo "$table";
?>

Once the form is submitted you can obtain the editted values using the POST paramter, and use the update query as follows

Update [tablename] set [column]=[value] where condition

Hope this would be of help to you

Hi,

I tried doing something similar to forms.php, but while opening the page in the Internet explorer, it was throwing up some errors at line containing "$row[$arrayKeyList[$i]]". It was expecting some ''.
Some help regdg the above will be appreciated.


You Could place the above code in a form and submit it to a page say forms.php

code for forms.php

<?php
$conn=mysql_connect("localhost","root");
mysql_select_db("test");
$name=$_POST['name'];
$sqlQuery='Select * from user where name='."'$name'";
$queryResult= mysql_query($sqlQuery);
list($row)=mysql_fetch_row($queryResult);
$arrayKeyList=array_keys($row);
$table="<form action='update,php' method='POST'><table>";
for($i=0;$i<sizeof($row);$i++)
    {
   $table.='<tr><td>'."$arrayKeyList[$i]"."</td><td><input type='text' value=$row[$arrayKeyList[$i]] name=$arrayKeyList[$i] />";

    
    }

$table.="<input type='submit'/></table></form>";
echo "$table";
?>

Once the form is submitted you can obtain the editted values using the POST paramter, and use the update query as follows

Update [tablename] set [column]=[value] where condition

Hope this would be of help to you

In the above code you used update.php for the table form action so whtas the code for update.php

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.