Hi,
Please bear with me, as I am very new to PHP. I am attempting to use a form to update records in a mysql database. I have a basic html form that enables the user to select which table they want to update, then after submitting the form, the php script will show all of the fields in that table. Once you select a record to edit, there are several text boxes that should automatically have the information filled in. You should then be able to edit the info in these text boxes and submit the changes, thus updating the record. The problem I am having is instead of receiving the text automatically filled into the text fields, I am getting the following error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
I am using a variable in the script to represent the table. The variable is $select_table. However, when I replace the variable with the actual table name instead, the script works without error. I only run into the problem when using variables. I would appreciate any and all help.
Here is a look at the php script.:
<html>
<body>
<?php
$db = mysql_connect(\"localhost\", \"root\");
mysql_select_db(\"nascar\",$db);
if ($item) {
if ($submit) {
$sql = \"UPDATE $select_table SET
manufacturer=\'$manufacturer\',product_name=\'$product_name\',year=\'$year\',scale=\'$scale\',number=\'$number\',driver=\'$driver\',spons$
WHERE item=$item\";
$result = mysql_query($sql);
echo \"Thank you! Information updated.n\";
} else {
// query the DB
$sql = \"SELECT * FROM $select_table WHERE item=$item\";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form method=\"post\" action=\"<?php echo $PHP_SELF?>\">
<input type=hidden name=\"item\" value=\"<?php echo $myrow[\"item\"] ?>\">
manufacturer:<input type=\"Text\" name=\"manufacturer\" value=\"<?php echo $myrow[\"manufacturer\"] ?>\"><br>
product_name:<input type=\"Text\" name=\"product_name\" value=\"<?php echo $myrow[\"product_name\"] ?>\"><br>
year:<input type=\"Text\" name=\"year\" value=\"<?php echo $myrow[\"year\"] ?>\"><br>
scale:<input type=\"Text\" name=\"scale\" value=\"<?php echo $myrow[\"scale\"] ?>\"><br>
number:<input type=\"Text\" name=\"number\" value=\"<?php echo $myrow[\"number\"] ?>\"><br>
driver:<input type=\"Text\" name=\"driver\" value=\"<?php echo $myrow[\"driver\"] ?>\"><br>
sponsor:<input type=\"Text\" name=\"sponsor\" value=\"<?php echo $myrow[\"sponsor\"] ?>\"><br>
car_make:<input type=\"Text\" name=\" car_make\" value=\"<?php echo $myrow[\" car_make\"] ?>\"><br>
produced:<input type=\"Text\" name=\"produced\" value=\"<?php echo $myrow[\"produced\"] ?>\"><br>
serial:<input type=\"Text\" name=\"serial\" value=\"<?php echo $myrow[\"serial\"] ?>\"><br>
value:<input type=\"Text\" name=\"value\" value=\"<?php echo $myrow[\"value\"] ?>\"><br>
notes:<input type=\"Text\" name=\"notes\" value=\"<?php echo $myrow[\"notes\"] ?>\"><br>
<input type=\"Submit\" name=\"submit\" value=\"Enter information\">
</form>
} else {
// display list
$result = mysql_query(\"SELECT * FROM $select_table\",$db);
while ($myrow = mysql_fetch_array($result)) {
printf(\"<a href=\"%s?item=%s\"><br><b>Manufacturer: </b>%s<br><b>Year:
</b>%s<br><b>Scale: </b>%s<br><b>Product Name: </b>%s<br><b>Car Number: </b>%s<br>
</a><br>n\", $PHP_SELF,
$myrow[\"item\"],
$myrow[\"manufacturer\"], $myrow[\"year\"],$myrow[\"scale\"],$myrow[\"product_name\"], $myrow[\"number\"] );
}
}
?>
</body>
</html>