Jump to content

Inserting records from database into form.


colleyboy

Recommended Posts

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...

Link to comment
Share on other sites

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 :D!

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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

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.