Ah... part of the confusion is from me trying to change some of the information so that it was generic for posting on here. My table's item_id is an auto increment key for each item in the database. The 2nd name is also unique, and I'm using it to find the item_id, then using item_id as an identifier in hidden fields. (or at least trying to)
Other than that, I'm turned around, upside down, inside out and lost.
I've dropped in the code rework that you gave me, fixed the confusing spots and it still doesn't work.
The page loads, with the passed variable $id populating the two boxes with info. But when I hit submit, it echos my error ' you have reached this page in error' and gives me this error:
Fatal error: Call to undefined function escape_data() in /data/21/2/40/160/2040975/user/2235577/htdocs/edit_user10.php on line 39
I can get rid of the escape_data() but still it doesn't do what I want.
the entire code with actual table/column names is here:
<html>
<body>
<?php
if ((isset($_GET['id'])) && (is_numeric($_GET['id']))) {
$id = $_GET['id'];
// that was the part to check for passed variables. This is what does something with it
require ('databaseconnect.php');
$query = "SELECT * FROM plantae WHERE $id = plant_name";
$result = mysql_query($query);
if (mysql_num_rows($result) == 1){
while ($row = mysql_fetch_array($result)) {
?>
<form action="edit_user10.php" method="post">
<table cellpadding="10">
<tr>
<td align="left"><?php echo $row['plant_name']; ?></td>
<td align="left"><input type="text" name="scientific_name" value="<?php echo $row['scientific_name']; ?>"></td>
<td align="left"><input type="text" name="common_name_english" value="<?php echo $row['common_name_english']; ?>"></td>
</tr>
</table>
<input type="hidden" name="plant_name" value="<?php echo $row['plant_name']; ?>">
<input type="submit" name="submit" value="Submit Change">
</form>
<?php
}
}
}
else {
echo 'you have reached this page in error';
}
// up to this point i had a working script. when I tried to set up the ability to edit, it broke.
if (isset($_POST['submit'])){
$pn = escape_data($_POST['plant_name']);
$sn = escape_data($_POST['scientific_name']);
$cne = escape_data($_POST['common_name_english']);
$query = "UPDATE plantae SET scientific_name='$sn', common_name_english='$cne' WHERE plant_name=$pn";
$result = mysql_query ($query);
if (mysql_affected_rows() == 1) {
echo 'your plant has been updated';
}
}
?>