UPDATE SET PHP代码无法正常工作

时间:2013-06-14 09:51:13

标签: php html forms sql-update field

不确定为什么这不起作用。有什么建议?试图更新mysql数据库中的字段。另外,我添加了错误选项,它无法显示任何错误!

 <?php
  $email=trim($_REQUEST["x_email"]);
  $primaryname=trim($_REQUEST["x_name"]);

  if (isset($_POST['submit'])) {

 /** The name of the database for WordPress */
 define('DB_NAME', 'MYDBNAME');

 /** MySQL database username */
 define('DB_USER', 'MYUSERNAME');

 /** MySQL database password */
 define('DB_PASSWORD', 'MYPASSWORD');

 /** MySQL hostname */
 define('DB_HOST', 'localhost');

 // Connect to the database
 $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

 $acceptance = "Yes, I agree to the Terms and Conditions";

 // Insert the info into the database
    mysqli_query("UPDATE reservations SET acceptance = '$acceptance' WHERE email = '$email'"); 

   mysqli_error();
 } 
 ?>

我也有HTML

 <form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">  
 <p>  
 <input type="hidden" name="is_submitted" value="1" /> 
 <input type="checkbox" name="acceptance" class="checkbox" value="Yes, I Agree To The      
 Terms and Conditions" /> Yes, I <?php echo $primaryname; ?>, Agree to the Terms and 
 Conditions</p>   

 <p><input type="reset" value="No, I do not Accept" name="reset" />  <input 
 type="submit" value="I Accept" name="submit" /></p>  

 </form>

2 个答案:

答案 0 :(得分:1)

你忘了连接链接变量

mysqli_query($dbc, "UPDATE reservations SET acceptance = '$acceptance' WHERE email = '$email'");
             ^^^^^^^

答案 1 :(得分:0)

您的代码中有一个错误:

mysqli_query($dbc, "UPDATE reservations SET acceptance = '$acceptance' WHERE email = '$email'");

在这一行中你需要在第一个参数中传递连接对象。

Reference is here