cassy01 Posted March 2, 2008 Share Posted March 2, 2008 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 https://forums.phpfreaks.com/topic/93994-post-query-into-form/ Share on other sites More sharing options...
monkeybidz Posted March 2, 2008 Share Posted March 2, 2008 Try this: <?php $query = "SELECT * FROM products WHERE itemID = ".$_POST[itemID]; ?> Link to comment https://forums.phpfreaks.com/topic/93994-post-query-into-form/#findComment-481549 Share on other sites More sharing options...
cassy01 Posted March 2, 2008 Author Share Posted March 2, 2008 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. Link to comment https://forums.phpfreaks.com/topic/93994-post-query-into-form/#findComment-481552 Share on other sites More sharing options...
AndyB Posted March 2, 2008 Share Posted March 2, 2008 $itemID = $result['itemID'] $itemName = $result['itemName'] should be $itemID = $row['itemID'] $itemName = $row['itemName'] $row is the array you abstracted $result into! Link to comment https://forums.phpfreaks.com/topic/93994-post-query-into-form/#findComment-481553 Share on other sites More sharing options...
cassy01 Posted March 2, 2008 Author Share Posted March 2, 2008 now i have changed it to row it comes up with; Parse error: syntax error, unexpected T_VARIABLE Link to comment https://forums.phpfreaks.com/topic/93994-post-query-into-form/#findComment-481556 Share on other sites More sharing options...
AndyB Posted March 2, 2008 Share Posted March 2, 2008 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 If you still have problems, post the relevant parts of the form processor code Link to comment https://forums.phpfreaks.com/topic/93994-post-query-into-form/#findComment-481558 Share on other sites More sharing options...
cassy01 Posted March 2, 2008 Author Share Posted March 2, 2008 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 https://forums.phpfreaks.com/topic/93994-post-query-into-form/#findComment-481562 Share on other sites More sharing options...
monkeybidz Posted March 2, 2008 Share Posted March 2, 2008 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 https://forums.phpfreaks.com/topic/93994-post-query-into-form/#findComment-481566 Share on other sites More sharing options...
cassy01 Posted March 2, 2008 Author Share Posted March 2, 2008 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 https://forums.phpfreaks.com/topic/93994-post-query-into-form/#findComment-481572 Share on other sites More sharing options...
AndyB Posted March 2, 2008 Share Posted March 2, 2008 <input name="itemName" type="text" id="itemName" value="<?php $row['itemName'];?>" /> should be: <input name="itemName" type="text" id="itemName" value="<?php echo $row['itemName'];?>" /> Link to comment https://forums.phpfreaks.com/topic/93994-post-query-into-form/#findComment-481574 Share on other sites More sharing options...
cassy01 Posted March 2, 2008 Author Share Posted March 2, 2008 thanks guys works perfectly Link to comment https://forums.phpfreaks.com/topic/93994-post-query-into-form/#findComment-481577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.