I would like to be able to view and edit information contained within a table from my web browser however I can't for the life in me get the current values to pull though to an html text field.
Can anyone shed any light as im quite new to php?
Table name: request_details
Column Names: id, name, email_address
My PHP code is:
<?
$order = "SELECT * FROM request_details WHERE id='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
HTML Code
<form method="post" action="edit_data.php">
<input type="hidden" name="id" value="<?php echo "$row[id]"?>">
<tr>
<td>Name</td>
<td>
<input type="text" name="name" size="20" value="<?php echo "$row[name]"?>">
</td>
</tr>
<tr>
<td>Email Address</td>
<td>
<input type="text" name="email_address" size="40" value="<?php echo "$row[email_address]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
Right to make it a bit easier, when I use an actual ID not a variable it works, so for example
<?
include "db.inc.php";//database connection
$order = "SELECT * FROM request_details WHERE id='19'";
$result = mysql_query($order);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
?>
The above displays, yet the below does not
<?
include "db.inc.php";//database connection
$order = "SELECT * FROM request_details WHERE id='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
?>
Ok, so the premise is I have two web pages, the first displays all the information I require
code is:
<table>
<tr>
<td>
<table border="1">
<tr>
<td>Name</td>
<td>Telephone Number</td>
<td>Email Address</td>
<td>Venue</td>
<td>Event Date</td>
<td>Guests</td>
<td>Chair Cover Colour</td>
<td>Sash Colour</td>
<td>Price</td>
<td>Damage Deposit</td>
<td>Status</td>
<td>Notes</td>
</tr>
<tr>
<?
$order = "SELECT * FROM request_details";
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
echo ("<tr><td>$row[name]</td>");
echo ("<td>$row[telephone_number]</td>");
echo ("<td>$row[venue]</td>");
echo ("<td>$row[event_date]</td>");
echo ("<td>$row[guests]</td>");
echo ("<td>$row[cover_colour]</td>");
echo ("<td>$row[sash_colour]</td>");
echo ("<td>$row[price]</td>");
echo ("<td>$row[damage_deposit]</td>");
echo ("<td>$row[notes]</td>");
echo ("<td><a href=\"edit_form.php?id=$row[id]\">View</a></td></tr>");
}
?>
</table>
</td>
</tr>
</table>
When i click on view it takes me to the following url:
edit_form.php?id=1
for example
edit_form.php?id=19
The code for this page (where the information isn't displaying in the text field):
<table border=1>
<tr>
<td>
<table>
<?
$order = "SELECT * FROM request_details WHERE id='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
?>
<form method="post" action="edit_data.php">
<tr>
<input type="hidden" name="id" value="<?php echo $row['id']; ?>" />
<tr>
<td>Name</td>
<td>
<input type="text" name="name" size="20" value="<?php echo $row['name']; ?>">
</td>
</tr>
<tr>
<td>Email Address</td>
<td>
<input type="text" name="email_address" size="40"
value="<?php echo $row['email_address']; ?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit" name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
var_dump($row);what result you get?