Jump to content

Post Query into Form


cassy01

Recommended Posts

Hi There,

 

i am trying to get the following query into a form;

$query = "SELECT * FROM products WHERE itemID = '$_POST[itemID]'";

 

i am then trying to put each field in that row into a form so the user can edit it and submit it back to the database, i have tried the following;

 

$result=mysql_query($query);

$row = mysql_fetch_array($result)

$itemID =  $result['itemID']

$itemName =  $result['itemName']

 

<input name="itemID" type="text" id="itemID" value="$itemID" />

 

please help

Link to comment
Share on other sites

The actual code lines I gave as example would need end with ;

 

Fx:

 

$itemID =  $row['itemID'];
$itemName =  $row['itemName'];

 

Can't fix what we can't see  ;D

 

If you still have problems, post the relevant parts of the form processor code

Link to comment
Share on other sites

right ive got the correct code at the top;

 

<?php $query = "SELECT * FROM products WHERE itemID = '$_POST[itemID]'";

$result=mysql_query($query);

$row = mysql_fetch_array($result);

?>

 

now how can i get the row of data to be entered as values to the form? i have at the moment;

 

<input name="itemName" type="text" id="itemName" value="<?php $row['itemName'];?>" />

Link to comment
Share on other sites

thats what ive already got :S

 

i can get the data from the database using the above query but cannot get each field to be inserted into the form.

 

Look good at how I posted the code in the query at the end with different quotes. Makes a difference. If that does not work, try:

<?php
$query = "SELECT * FROM products WHERE itemID = ".$_POST['itemID'];

?>

Link to comment
Share on other sites

changed code to:

 

$query = "SELECT * FROM products WHERE itemID = ".$_POST['itemID'];

$result=mysql_query($query);

$row = mysql_fetch_array($result);

 

Now trying to put that row of data into a form as values;

 

<input name="itemName" type="text" id="itemName" value="<?php $row['itemName'];?>"  />

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.