Hi All,
I have a problem in getting this update form to work. The query to call the record works fine and when clicking submit it redirects correctly and echo's (record updated) but the database is not updated. When i change the value variables in the update script it correctlu updates the record in the database.
Please check what I am doing wrong.
<?php
include("include/session.php");
$id="1";
$username="root";
$password="";
$database="cmms";
mysql_connect(localhost,$username,$password);
$query=" SELECT * FROM menuone WHERE id='$id'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$item = mysql_result($result,$i,"item");
$level1 = mysql_result($result,$i,"level1");
$level2 = mysql_result($result,$i,"level2");
$level3 = mysql_result($result,$i,"level3");
$level4 = mysql_result($result,$i,"level4");
$level5 = mysql_result($result,$i,"level5");
$level6 = mysql_result($result,$i,"level6");
$level7 = mysql_result($result,$i,"level7");
$level8 = mysql_result($result,$i,"level8");
$level9 = mysql_result($result,$i,"level9");
?>
<form action="up.php" method="post">
Id <input type="text" name="u_id" value="<?php echo $id; ?>">
Item <input type="text" name="u_id" value="<?php echo $item; ?>">
Level1 <input type="text" name="u_level1" value="<?php echo $level1; ?>"><br>
Level2 <input type="text" name="u_level2" value="<?php echo $level2; ?>"><br>
Level3 <input type="text" name="u_level3" value="<?php echo $level3; ?>"><br>
Level4 <input type="text" name="u_level4" value="<?php echo $level4; ?>"><br>
Level5 <input type="text" name="u_level5" value="<?php echo $level5; ?>"><br>
Level6 <input type="text" name="u_level6" value="<?php echo $level6; ?>"><br>
Level7 <input type="text" name="u_level7" value="<?php echo $level7; ?>"><br>
Level8 <input type="text" name="u_level8" value="<?php echo $level8; ?>"><br>
Level9 <input type="text" name="u_level9" value="<?php echo $level9; ?>"><br>
<input type="Submit" value="Update">
</form>
<?php
$p_id = $_POST['$u_id'];
$p_item = $_POST['$u_item'];
$p_level1 = $_POST['$u_level1'];
$p_level2 = $_POST['$u_level2'];
$p_level3 = $_POST['$u_level3'];
$p_level4 = $_POST['$u_level4'];
$p_level5 = $_POST['$u_level5'];
$p_level6 = $_POST['$u_level6'];
$p_level7 = $_POST['$u_level7'];
$p_level8 = $_POST['$u_level8'];
$p_level9 = $_POST['$u_level9'];
++$i;
}
?>
Here is the update script.
up.php
<?php
$username="root";
$password="";
$database="cmms";
mysql_connect(localhost,$username,$password);
$p_id = $_POST['$u_id'];
$p_item = $_POST['$u_item'];
$p_level1 = $_POST['$u_level1'];
$p_level2 = $_POST['$u_level2'];
$p_level3 = $_POST['$u_level3'];
$p_level4 = $_POST['$u_level4'];
$p_level5 = $_POST['$u_level5'];
$p_level6 = $_POST['$u_level6'];
$p_level7 = $_POST['$u_level7'];
$p_level8 = $_POST['$u_level8'];
$p_level9 = $_POST['$u_level9'];
$query="UPDATE `cmms`.`menuone` SET `level9` = '$p_level9',
`level8` = '$p_level8',
`level7` = '$p_level7',
`level6` = '$p_level6',
`level5` = '$p_level5',
`level4` = '$p_level4',
`level3` = '$p_level3',
`level2` = '$p_level2',
`level1` = '$p_level1' WHERE `menuone`.`id` =$p_id;";
mysql_query($query);
echo "Record Updated";
mysql_close();
?>
Thank you
Max