0

Hey guys

I'm hoping someone can help me out. I have an admin page with the ability to update existing data from a table, I have textboxes being created for each record(this works) but its the submit/update script that doesnt work. What it does right now is nothing, i hit the submit button and no data is updated. I suspect that its because the textboxes are generated so no id is set to each textbox.

This is my update script:

<?php
//connection code

mysql_select_db("machacho_rupe", $con);
$car_id = $POST['car_id'];
$car_manufacture_id= $POST['car_manufacture_id'];
$car_year = $POST['car_year'];
$car_model = $POST['car_model'];
$car_hp = $POST['car_hp'];
$car_torque = $POST['car_torque'];
$car_engine = $POST['car_engine'];
$car_mpg = $POST['car_mpg'];
$car_type = $POST['car_type'];
$car_starting_price = $POST['car_starting_price'];
$i = 0;


mysql_select_db("machacho_rupe", $con);

while($i < count($car_id))
{
	
	$sql = mysql_query("UPDATE cars SET 
	car_id = '{$car_id[$i]}',
	car_manufacture_id='{$car_manufacture_id[$i]}',
	car_year = '{$car_year[$i]}',
	car_model = '{$car_model[$i]}',
	car_hp = '{$car_hp[$i]}',
	car_torque ='{$car_torque[$i]}',
	car_engine ='{$car_engine[$i]}',
	car_mpg = '{$car_mpg[$i]}',
	car_type ='{$car_type[$i]}',
	car_starting_price '{$car_starting_price[$i]}'");

	
}


 
?>

<p><a href="../db/update-data.php">Back</a></p>

and this is my form with the dynamic textboxes.

<?php
$con = mysql_connect("connection data");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("dbname", $con);

$result = mysql_query("SELECT * FROM cars ORDER BY car_id");


?>

    

<table width ="30%" align ="center">
	<tr>
<th>car_id</th>
<th>car_manufacture_id</th>
<th>car_year</th>
<th>car_model</th>
<th>car_hp</th>
<th>car_torque</th>
<th>car_engine</th>
<th>car_mpg</th>
<th>car_type</th>
<th>car_starting_price</th>
</tr>
</
<?php
while($row = mysql_fetch_array($result)) {
	

	?> 
    <table width ="30%" align ="center">
	<tr>

		<tr>
       <td><input name="" type="text" value = "<?php echo $row['car_id'] ?>"/> </td>
       
       <td><input name="" type="text" value = "<?php echo $row['car_manufacture_id'] ?>"/> </td>
       <td><input name="" type="text" value = "<?php echo $row['car_year'] ?>"/> </td>
       <td><input name="" type="text" value = "<?php echo $row['car_model'] ?>"/> </td>
       <td><input name="" type="text" value = "<?php echo $row['car_hp'] ?>"/> </td>
       <td><input name="" type="text" value = "<?php echo $row['car_torque'] ?>"/> </td>
       <td><input name="" type="text" value = "<?php echo $row['car_engine'] ?>"/> </td>
       <td><input name="" type="text" value = "<?php echo $row['car_mpg'] ?>"/> </td>
       <td><input name="" type="text" value = "<?php echo $row['car_type'] ?>"/> </td>
       <td><input name="" type="text" value = "<?php echo $row['car_starting_price'] ?>"/> </td>
	   </tr>
	   </table>
       <?php
}
mysql_close($con);
?>

<form action="update-querrie.php" method="post">

 <p>
    <input type="submit" />
  </p>
</form>

<p><a href="../db">Back</a></p>
<p><a href="./logout.php">Logout</a></p>

feel free to give any other pointer on how to do this better, im very new to php.

2
Contributors
1
Reply
6
Views
6 Years
Discussion Span
Last Post by nuttyniall
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.