colleyboy Posted September 19, 2010 Share Posted September 19, 2010 Hi. When a record is added its done via a form and processed via inserts.php. I need to use the same form but to recall the data (by id) so it can be editted. Cant work it out though. Help would be well appreciated! edit.php: <CENTER><B>Update a Vehicle</B></CENTER> <BR> <?php $query="SELECT * FROM cars"; $result=mysql_query($query); $i=0; while ($i < $num) { $carname=mysql_result($result,$i,"CarName"); $cartitle=mysql_result($result,$i,"CarTitle"); $carprice=mysql_result($result,$i,"CarPrice"); $carmiles=mysql_result($result,$i,"CarMiles"); $cardesc=mysql_result($result,$i,"CarDescription"); ?> <form action="showroomedit.php" method="post"> <CENTER>Vehicle Name:</CENTER> <CENTER><input type="text" name="CarName" value="<?php echo $carname; ?>"></CENTER> <br> <CENTER>Vehicle Type:</CENTER> <CENTER><input type="text" name="CarTitle" value="<?php echo $cartitle; ?>"></CENTER> <br> <CENTER>Vehicle Price:</CENTER> <CENTER><input type="text" name="CarPrice" value="<?php echo $carprice; ?>"></CENTER> <br> <CENTER>Vehicle Mileage:</CENTER> <CENTER><input type="text" name="CarMiles" value="<?php echo $carmiles; ?>"></CENTER> <br> <CENTER>Vehicle Description:</CENTER> <CENTER><textarea name="CarDescription" rows="10" cols="30" value="<?php echo $cardesc; ?>"></textarea></CENTER> <br> <CENTER><input type="Submit"></CENTER> </form> </TD> cant work out why it isnt working... Quote Link to comment https://forums.phpfreaks.com/topic/213833-inserting-records-from-database-into-form/ Share on other sites More sharing options...
litebearer Posted September 19, 2010 Share Posted September 19, 2010 1. where are you defining the specific car id? 2. where are your defining $num? Quote Link to comment https://forums.phpfreaks.com/topic/213833-inserting-records-from-database-into-form/#findComment-1112912 Share on other sites More sharing options...
colleyboy Posted September 19, 2010 Author Share Posted September 19, 2010 erm... pass? in the database I have 5 fields: id ---- CarName ---- CarType ---- CarPrice ---- CarMiles ---- CarDescription in the showroom.php page theres a link that will go to edit.php?id="number" so edit knows which record to show. the edit page will have the form and will be filled with the values of which id it is. Need help to find out how to insert the data and update it. Thanks hope to hear a solution ! Quote Link to comment https://forums.phpfreaks.com/topic/213833-inserting-records-from-database-into-form/#findComment-1112915 Share on other sites More sharing options...
litebearer Posted September 19, 2010 Share Posted September 19, 2010 perhaps... <?php $what_id=$_GET['id']; $query="SELECT * FROM cars WHERE id = '$what_id'"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { $carname = $row['CarName']; $cartitle = $row['CarTitle']; $carprice = $row['CarPrice']; carmiles = $row['CarMiles']; $cardesc = $row['CarDescription']; } ?> <form action="showroomedit.php" method="post"> <CENTER>Vehicle Name:</CENTER> <br><CENTER><input type="text" name="CarName" value="<?php echo $carname; ?>"></CENTER><br> <CENTER>Vehicle Type:</CENTER><br><CENTER><input type="text" name="CarTitle" value="<?php echo $cartitle; ?>"></CENTER><br> <CENTER>Vehicle Price:</CENTER><br><CENTER><input type="text" name="CarPrice" value="<?php echo $carprice; ?>"></CENTER><br> <CENTER>Vehicle Mileage:</CENTER><br><CENTER><input type="text" name="CarMiles" value="<?php echo $carmiles; ?>"></CENTER><br> <CENTER>Vehicle Description:</CENTER><br> <CENTER><textarea name="CarDescription" rows="10" cols="30" value="<?php echo nl2br($cardesc); ?>"></textarea></CENTER><br> <CENTER><input type="Submit"></CENTER> </form> Quote Link to comment https://forums.phpfreaks.com/topic/213833-inserting-records-from-database-into-form/#findComment-1112922 Share on other sites More sharing options...
colleyboy Posted September 19, 2010 Author Share Posted September 19, 2010 I have been messing around and i think i nearly cracked it!!! NEARLY tho. In each box it is putting the ID (I.E: 22) and not the other fields like CarName. Any idea... <?php $query="SELECT * FROM cars"; $result=mysql_query($query); $carname=mysql_result($result,"CarName"); $cartitle=mysql_result($result,"CarTitle"); $carprice=mysql_result($result,"CarPrice"); $carmiles=mysql_result($result,"CarMiles"); $cardesc=mysql_result($result,"CarDescription"); ?> <form action="showroomedit.php" method="post"> <CENTER>Vehicle Name:</CENTER> <CENTER><input type="text" name="CarName" value="<?php echo $carname; ?>"></CENTER> <br> <CENTER>Vehicle Type:</CENTER> <CENTER><input type="text" name="CarTitle" value="<?php echo $cartitle; ?>"></CENTER> <br> <CENTER>Vehicle Price:</CENTER> <CENTER><input type="text" name="CarPrice" value="<?php echo $carprice; ?>"></CENTER> <br> <CENTER>Vehicle Mileage:</CENTER> <CENTER><input type="text" name="CarMiles" value="<?php echo $carmiles; ?>"></CENTER> <br> <CENTER>Vehicle Description:</CENTER> <CENTER><textarea name="CarDescription" rows="10" cols="30" value="<?php echo $cardesc; ?>"></textarea></CENTER> <br> <CENTER><input type="Submit"></CENTER> </form> Quote Link to comment https://forums.phpfreaks.com/topic/213833-inserting-records-from-database-into-form/#findComment-1112925 Share on other sites More sharing options...
litebearer Posted September 19, 2010 Share Posted September 19, 2010 did you try what I posted? Quote Link to comment https://forums.phpfreaks.com/topic/213833-inserting-records-from-database-into-form/#findComment-1112927 Share on other sites More sharing options...
colleyboy Posted September 19, 2010 Author Share Posted September 19, 2010 yeah i did but i got this error... Parse error: syntax error, unexpected '=' in /home/wormste1/public_html/tilburywebdesign/shop/FTPServers/barryottley/edit.php on line 61 did you manage to find out why it was putting the ID in each box and not the correct value? Quote Link to comment https://forums.phpfreaks.com/topic/213833-inserting-records-from-database-into-form/#findComment-1112928 Share on other sites More sharing options...
colleyboy Posted September 19, 2010 Author Share Posted September 19, 2010 aha... your code worked-ish!!! (missing $ was problem). It shows the database details fine but when i press submit it does not save the changes in to the database. What do i need to do this? Quote Link to comment https://forums.phpfreaks.com/topic/213833-inserting-records-from-database-into-form/#findComment-1112929 Share on other sites More sharing options...
PFMaBiSmAd Posted September 20, 2010 Share Posted September 20, 2010 when i press submit it does not save the changes in to the database. It would take seeing the code that you wrote to save the changes. The code posted so far in this thread only produces the form. Edit: I'm going to guess that is what this other thread is for - http://www.phpfreaks.com/forums/index.php/topic,310456.0.html Quote Link to comment https://forums.phpfreaks.com/topic/213833-inserting-records-from-database-into-form/#findComment-1113071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.