CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Rendering MySQL output to edit in a form (http://www.codingforums.com/showthread.php?t=233018)

benji23 07-26-2011 01:58 AM

Rendering MySQL output to edit in a form
 
Im coding a form to upload items into MySQL database, everything works fine except when i click "edit" (to change details with that item) the data doesnt render in the form...

<?php
// Gather this product's full information for inserting automatically into the edit form below on page
if (isset($_GET['pid'])) {
$targetID = $_GET['pid'];
$sql = mysql_query("SELECT * FROM products WHERE id='$targetID' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){

$product_name = $row["product_name"];
$price = $row["price"];
}
} else {
echo "Item doesnt exist!";
exit();
}
}
?>

BluePanther 07-26-2011 09:25 AM

Because you are limiting your query to 1 result, you don't actually need a while loop, so remove the while to leave you with this inside the if:
PHP Code:

$row mysql_fetch_array($sql); 
$product_ name $row["product_ name "];
$price $row["price "]; 

You Should add 'or die(mysql_error())' to the end of your query to catch any errors.

Also, could you post your form code?

tangoforce 07-26-2011 01:53 PM

You're only showing php code there. You're not showing us any code that actually puts the data directly into the form or even tries to do so.


All times are GMT +1. The time now is 01:30 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.