UPDATE doesn't work...
Posted: Sat Nov 08, 2008 9:24 am
Hey I'm trying to use the code below to update a mysql table, but it doesn't seem to work for some reason.
Would appreciate any assistance.
Here is the code:
update_all.php
update_all_ac.php
Would appreciate any assistance.
Here is the code:
update_all.php
Code: Select all
<?php
include_once "db_conn.php";
?>
<?php
$sql="SELECT * FROM $tbl_name ORDER BY cat_id, menu_id";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
?>
<?php
include_once "html_start.php";
?>
<h1>Update All Records</h1>
<table width="700" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="update_all_ac.php">
<tr>
<td>
<table width="700" border="0" cellspacing="1" cellpadding="3">
<tr>
<td><strong>Cat ID</strong></td>
<td><strong>Menu ID</strong></td>
<td><strong>Cat Title</strong></td>
<td><strong>File Name</strong></td>
<td><strong>Class Name</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><input name="id" type="hidden" id="id" value="<? $id=$rows['id']; ?>">
<input name="cat_id" type="text" id="cat_id" value="<? echo $rows['cat_id']; ?>"></td>
<td><input name="menu_id" type="text" id="menu_id" value="<? echo $rows['menu_id']; ?>"></td>
<td><input name="cat_title" type="text" id="cat_title" value="<? echo $rows['cat_title']; ?>" style="direction:rtl"></td>
<td><input name="file_name" type="text" id="file_name" value="<? echo $rows['file_name']; ?>"></td>
<td><input name="class_name" type="text" id="class_name" value="<? echo $rows['class_name']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<?php
include_once "html_end.php";
?>
Code: Select all
<?php
include_once "db_conn.php";
?>
<?php
$id = $_POST['id'];
$cat_id = $_POST['cat_id'];
$menu_id = $_POST['menu_id'];
$cat_title = $_POST['cat_title'];
$file_name = $_POST['file_name'];
$class_name = $_POST['class_name'];
$sql1 = "UPDATE $tbl_name SET cat_id='$cat_id', menu_id='$menu_id', cat_title='$cat_title', file_name='$file_name', class_name='$class_name' WHERE id='$id'";
$result1 = mysql_query($sql1);
?>
<?php
include_once "html_start.php";
?>
<?php
if($result1){
echo "Saved!<br /><a href=\"update_all.php\">Click here to go back</a>";
}
else {
echo "ERROR!";
}
mysql_close();
?>
<?php
include_once "html_end.php";
?>