I found a tutorial with a template to use, I have modified it with the information I need, it shows up fine but when I press submit it's not updating the database.
Can someone take a look at my code and see what i've done wrong please
I have the username, password etc but removed them for the sake of this post.
Code: Select all
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$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>products_id</strong></td>
<td align="center"><strong>language_id</strong></td>
<td align="center"><strong>products_name</strong></td>
<td align="center"><strong>products_description</strong></td>
<td align="center"><strong>bullet_1</strong></td>
<td align="center"><strong>bullet_2</strong></td>
<td align="center"><strong>bullet_3</strong></td>
<td align="center"><strong>bullet_4</strong></td>
<td align="center"><strong>batteries</strong></td>
<td align="center"><strong>size</strong></td>
<td align="center"><strong>material</strong></td>
<td align="center"><strong>waterproof</strong></td>
<td align="center"><strong>products_url</strong></td>
<td align="center"><strong>products_viewed</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><? $products_id[]=$rows['products_id']; ?><? echo $rows['products_id']; ?></td>
<td align="center"><? $language_id[]=$rows['language_id']; ?><? echo $rows['language_id']; ?></td>
<td align="center"><? $products_name[]=$rows['products_name']; ?><? echo $rows['products_name']; ?></td>
<td align="center"><input name="products_description[]" type="text" id="products_description" value="<? echo $rows['products_description']; ?>"></td>
<td align="center"><input name="bullet_1[]" type="text" id="bullet_1" value="<? echo $rows['bullet_1']; ?>"></td>
<td align="center"><input name="bullet_2[]" type="text" id="bullet_2" value="<? echo $rows['bullet_2']; ?>"></td>
<td align="center"><input name="bullet_3[]" type="text" id="bullet_3" value="<? echo $rows['bullet_3']; ?>"></td>
<td align="center"><input name="bullet_4[]" type="text" id="bullet_4" value="<? echo $rows['bullet_4']; ?>"></td>
<td align="center"><input name="batteries[]" type="text" id="batteries" value="<? echo $rows['batteries']; ?>"></td>
<td align="center"><input name="size[]" type="text" id="size" value="<? echo $rows['size']; ?>"></td>
<td align="center"><input name="material[]" type="text" id="material" value="<? echo $rows['material']; ?>"></td>
<td align="center"><input name="waterproof[]" type="text" id="waterproof" value="<? echo $rows['waterproof']; ?>"></td>
<td align="center"><input name="products_url[]" type="text" id="products_url" value="<? echo $rows['products_url']; ?>"></td>
<td align="center"><? $products_viewed[]=$rows['products_viewed']; ?><? echo $rows['products_viewed']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
// Check if button name "Submit" is active, do this
if($Submit){
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET products_description='$products_description[$i]', bullet_1='$bullet_1[$i]', bullet_2='$bullet_2[$i]', bullet_3='$bullet_3[$i]', bullet_4='$bullet_4[$i]', batteries='$batteries[$i]', size='$size[$i]', material='$material[$i]', waterproof='$waterproof[$i]', products_url='$products_url[$i]', products_viewed='$products_viewed[$i]', WHERE products_id='$products_id[$i]'";
$result1=mysql_query($sql1);
}
}
if($result1){
header("location:update_multiple.php");
}
mysql_close();
?>