我想更新數據庫中的特定行。PHP/MYSQL UPDATE在數據庫中顯示0
更新過程的工作,但該領域的一個不更新{那麼它的更新,但是當我檢查數據庫就顯示爲0,我無法找出什麼是代碼中的問題}
任何幫助會很好。
問題其member_id。
member_id其在數據庫中的int數據類型。
更新代碼
if (isset($_POST['submitted']))
{
$plan_id=$_POST['plan_id'];
$member_id=$_POST['member_id'];
$trainer_id=$_POST['trainer_id'];
$exercise_id=$_POST['exercise_id'];
$Set=$_POST['Set'];
$weight=$_POST['weight'];
$comment=$_POST['comment'];
$memberadd="No";
$query = "UPDATE gym_plan SET ";
$query.= "exercise_id = {$exercise_id}, ";
$query.= "exercise_set = '{$Set}', ";
$query.= "trainer_id = {$trainer_id}, ";
$query.= "member_id = {$member_id}, ";
$query.= "comment = '{$comment}', ";
$query.= "member_id = '{$memberadd}', ";
$query.= "weight = '{$weight}' ";
$query.= "WHERE plan_id = {$plan_id}; ";
$result = mysql_query($query, $connect);
echo 'my SQL query is: '.$query;
echo "<br/>";
if ($result)
{
//header("Location:editex.php");
$message2="The Exercise Has Been Updated";
$_SESSION['edit-ex']=$message2;
}// to check if the query run then show this message
else
{
die(mysql_error());
}
}
和完整的代碼
<?php
session_start();
$message2="";
require_once("db_connection.php");
$id = $_SESSION['staff_id'];
if (isset($_SESSION ['username']))
{
if($_SESSION['access_level']==3)
{
$message= "welcome, ".$_SESSION['username']." !<br/>";
}
else
{
header("Location:index.php");
$goaway="You Don't Have Privilege To Check This Page";
$_SESSION['noway']=$goaway;
}
}
else
{
header("Location:index.php");
}
if(isset($_GET['edit']))
{
$id2 = $_GET['edit'];
$member_id=$_SESSION['member_id'];
$query= mysql_query("SELECT * FROM gym_plan WHERE member_id='$member_id' AND exercise_id='$id2'");
}
if (isset($_POST['submitted']))
{
$plan_id=$_POST['plan_id'];
$member_id=$_POST['member_id'];
$trainer_id=$_POST['trainer_id'];
$exercise_id=$_POST['exercise_id'];
$Set=$_POST['Set'];
$weight=$_POST['weight'];
$comment=$_POST['comment'];
$memberadd="No";
$query = "UPDATE gym_plan SET ";
$query.= "exercise_id = {$exercise_id}, ";
$query.= "exercise_set = '{$Set}', ";
$query.= "trainer_id = {$trainer_id}, ";
$query.= "member_id = {$member_id}, ";
$query.= "comment = '{$comment}', ";
$query.= "member_id = '{$memberadd}', ";
$query.= "weight = '{$weight}' ";
$query.= "WHERE plan_id = {$plan_id}; ";
$result = mysql_query($query, $connect);
echo 'my SQL query is: '.$query;
echo "<br/>";
if ($result)
{
//header("Location:editex.php");
$message2="The Exercise Has Been Updated";
$_SESSION['edit-ex']=$message2;
}// to check if the query run then show this message
else
{
die(mysql_error());
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$br="<br/>";
while ($row=mysql_fetch_array($query))
{
extract($row);
//echo $plan_id;
//echo $br;
//echo $exercise_id;
//echo $br;
//echo $exercise_set;
echo $br;
$query2=mysql_query("SELECT * FROM exercise WHERE exercise_id='$exercise_id'");
while ($row2=mysql_fetch_array($query2))
{
extract ($row2);
//echo $exercise_name;
}
}
?>
Exercise Name : <?php echo $exercise_name;?>
<form name="form1" method="post" action="edit-ex.php">
<input type="hidden" name="submitted" value="true"/>
<input type="hidden" name="plan_id" value="<?php echo $plan_id?>"/>
<input type="text" name="member_id" value="<?php echo $member_id;?>"/>
<input type="hidden" name="exercise_id" value="<?php echo $exercise_id;?>"/>
<input type="hidden" name="trainer_id" value="<?php echo $trainer_id;?>"/>
<p>Set: <input name="Set" type="text" /><br/></p>
<p>Weight: <input type="text" name="weight" /><br/></p>
<p>Comment: <input type="text" name="comment" /><br/></p>
<input type="submit" value ="Update The <?php echo $exercise_name;?>"/>
</form>
</body>
</html>
您不能發佈較少的代碼嗎?你不能再縮小它了嗎? –