Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-26-2011, 01:58 AM   PM User | #1
benji23
New Coder

 
Join Date: May 2011
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
benji23 is an unknown quantity at this point
Cool 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();
}
}
?>
benji23 is offline   Reply With Quote
Old 07-26-2011, 09:25 AM   PM User | #2
BluePanther
Senior Coder

 
Join Date: Jul 2011
Posts: 1,226
Thanks: 3
Thanked 171 Times in 171 Posts
BluePanther is on a distinguished road
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?
BluePanther is offline   Reply With Quote
Old 07-26-2011, 01:53 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,503
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Tags
cart, mysql, php, render

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:39 PM.


Advertisement
Log in to turn off these ads.