按下UPDATE按钮时没有任何反应。使用准备好的陈述

时间:2017-07-21 15:37:29

标签: php sql-update prepared-statement

将数据发送到php文件的表单如下:

<center>
<form action="update.php" method="post">
<fieldset style="width:50%"><legend>Please do the required changes</legend><br>
<label for="Name">Name :<br></label><input name="name" type="text" size="20" maxlength="40" value="<?php echo $data2[Name]?>"><br>
<label for="CNIC">CNIC :<br></label><input name="cnic" type="text" size="20" maxlength="15" value="<?php echo $data2[CNIC]?>"><br>
<label for="Date">Booking Date :<br></label><input name="booking-date" type="date" size="20" value="<?php echo $data2[Date]?>"><br>

<!-- <label for="Ocassion">Ocassion :<br></label> -->
<label for="Ocassion">Ocassion :<br></label><input name="ocassion" type="text" size="20" maxlength="15" value="<?php echo $data2[Ocassion]?>"><br>

<label for="Address">Address :<br></label><input name="address" type="text" size="20" maxlength="11" value="<?php echo $data2[Address]?>"><br>

<label for="Phone Number">Phone Number :<br></label><input name="phone-no" type="text" size="20" maxlength="11" value="<?php echo $data2[Phone_No]?>"><br>
<label for="Bride Mobile">Bride Mobile :<br></label><input name="bride-mobile" type="number" size="20" maxlength="11" value="<?php echo $data2[Bride_Mobile]?>"><br>
<label for="Groom Mobile">Groom Mobile :<br></label><input name="groom-mobile" type="number" size="20" maxlength="11" value="<?php echo $data2[Groom_Mobile]?>"><br>
<label for="Family Mobile">Family Mobile :<br></label><input name="family-mobile" type="number" size="20" maxlength="11" value="<?php echo $data2[Family_Mobile]?>"><br>
<label for="Email">Email :<br></label><input name="email" type="text" size="20" maxlength="30" value="<?php echo $data2[EMail]?>"><br>
<label for="Who may I Thank for Refering You?">Who may I Thank for Refering You? :<br></label><input name="refering" type="text" size="20" maxlength="40" value="<?php echo $data2[Referring]?>"><br>
<label for="Do you provide consent to share images on our official web page">Do you provide consent to share images on our official web page? :<br><br></label><input type="radio" name="share" <?php echo ($data2[Share]=='Yes')?'checked':'' ?> value="Yes">Yes<br>
<input type="radio" name="share" <?php echo ($data2[Share]=='No')?'checked':'' ?> value="No">No<br><br>
<label for="If yes, with Identity">If yes, with Identity? :<br><br></label><input type="radio" name="permission" <?php echo ($data2[Permission]=='Yes')?'checked':'' ?> value="Yes">Yes<br>
<input type="radio" name="permission" <?php echo ($data2[Permission]=='No')?'checked':'' ?> value="No">No<br><br>
<!-- To center the button i'm embedding the buttons in a paragraph with an id as well. the id is used for CSS in head -->
<p id="btn">
<input type="submit" value="Update Record" name="submit_display_data_form" style="font-size:16px"></p>
</fieldset>
</form>
</center>
</body>
</html>

php文件是:

<?php error_reporting(0);
$server="localhost";
$user="root";
$password="";
$database="camouflage_studio";

$con = mysqli_connect($server,$user,$password,$database);
if (mysqli_connect_errno())
  {
  echo "Connection Error: " . mysqli_connect_error();
  }
// Updation
$stmt = $con->prepare("UPDATE 'personal_detail' SET Name = ?, CNIC = ?, Date = ?, Ocassion = ?, Address = ?, Phone_No = ?, Bride_Mobile = ?, Groom_Mobile = ?, Family_Mobile = ?, EMail = ?, Referring = ?, Share = ?, Permission = ? WHERE CNIC = ?");

$stmt->bind_param('ssssssiiissss', $_POST['name'], $_POST['cnic'], $_POST['booking-date'], $_POST['ocassion'], $_POST['address'], $_POST['phone-no'], $_POST['bride-mobile'], $_POST['groom-mobile'], $_POST['family-mobile'], $_POST['email'], $_POST['refering'], $_POST['share'], $_POST['permission'], $_POST['cnic']);

if(mysqli_stmt_execute($stmt))
{
echo '<script language="javascript" type="text/javascript"> 
                alert("Record Updated Successfully");
                window.location = "admin.php";
        </script>';
}
else
echo "Prepare Error: ",$con->error;     //remove $con->error before making ONLINE THE CODE.

$stmt->close();
$con->close();
?>
<!DOCTYPE html>
<html>
<head>
<title>Record Updation</title>
</head>

<body>
</body>
</html>

问题是,当我按下UPDATE RECORD按钮时,只在浏览器中打开update.php文件,没有任何反应。既不会显示错误也不会记录更新。

1 个答案:

答案 0 :(得分:0)

2件事,Date是一个mysql保留字功能。为了将该单词作为col名称传递,您需要将其包含在反引号中。 Seconde的问题是反引号是“不是”。 (注意差异?)

Base String :"YHKKGFFADGIJJ"
Search String:"ADGFFF"

Output:"ADG"

让我知道这个怎么回事

另外,使用$ stmt-&gt;错误来跟踪sql错误(如果有的话)