Hey, i'm new here and i need help.
I'm trying to write an update query so i can update mulitple items in a database, but it aint working..
Ive used the mysql_error() thingy, but it still does not display any errors. All it does is nothing, the web page doesnt update, and neither does the database in MySQL.
Is the syntax wrong or what?
My code:
<h1>Update Items</h1>
<p>Update items below.</p>
<?php
$db_host = 'X;
$db_user = 'X';
$db_pwd = 'X';
$database = 'X';
$table = 'pricelist';
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db(X))
die("Can't select database");
// sending query
$sql="SELECT * FROM $table";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="">
<tr>
<td>
<table width="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td align="center"><strong>Id</strong></td>
<td align="center"><strong>Item</strong></td>
<td align="center"><strong>Price</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $id[]=$rows['id']; ?><? echo $rows['id']; ?></td>
<td align="center"><input name="item[]" type="text" id="item" value="<? echo $rows['item']; ?>"></td>
<td align="center"><input name="price[]" type="text" id="price" value="<? echo $rows['price']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Update" value="Update"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
//define each variable
$item= $_POST['item'][$i];
$price = $_POST['price'][$i];
// Check if button name "Submit" is active, do this
if($Update){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $table SET item='$item', price='$price' WHERE id='$id[$i]'";
$result1=mysql_query($sql1);
mysql_error();
}
}
if($result1){
header("location:pricelistdata.php");
}
mysql_close();
?>
Cheers.