【问题标题】:Unknown column 'submittedby' in 'field list'“字段列表”中的未知列“提交者”
【发布时间】:2017-11-07 00:22:03
【问题描述】:

我对 PHP 和 MySQL 还很陌生,但我无法弄清楚这一点。一世 搜索了整个论坛,但没有找到我能理解的答案。

我收到以下错误:'字段列表'中的未知列'submittedby',问题出在这行代码 -

$update="update users set enrol_Date='".$enrol_Date."', username='".$username."', firstname='".$firstname."', lastname='".$lastname."', identificationCard='".$identificationCard."', email='".$email."',contact='".$contact."', submittedby='".$submittedby."' where id='".$id."'"; 

整个代码是:

<?php
  require('db.php');
  include("auth.php");
  $id=$_REQUEST['id'];
  $query = "SELECT * from users where id='".$id."'"; 
  $result = mysqli_query($con, $query) or die ( mysqli_error());
  $row = mysqli_fetch_assoc($result);
?>

<?php
  $status = "";
  if(isset($_POST['new']) && $_POST['new']==1)
  {
    $id=$_REQUEST['id'];
    $enrol_Date = date("Y-m-d H:i:s");
    $username =$_REQUEST['username'];
    $firstname =$_REQUEST['firstname'];
    $lastname =$_REQUEST['lastname'];
    $identificationCard =$_REQUEST['identificationCard'];
    $email =$_REQUEST['email'];
    $contact =$_REQUEST['contact'];
    $submittedby = $_SESSION["username"];
    $update="update users set enrol_Date='".$enrol_Date."', username='".$username."', firstname='".$firstname."', lastname='".$lastname."', identificationCard='".$identificationCard."', email='".$email."',contact='".$contact."', submittedby='".$submittedby."' where id='".$id."'"; 
    mysqli_query($con, $update) or die(mysqli_error($con));
    $status = "Profile Updated Successfully. </br></br>
    <a href='view.php'>View Updated Record</a>";
    echo '<p style="color:#FF0000;">'.$status.'</p>';
  }else {
?>

这是我的表单代码:

<form name="form" method="post" action=""> 
  <input type="hidden" name="new" value="1" />
  <input name="id" type="hidden" value="<?php echo $row['id'];?>" />
  <label for="username"> Username : </label>
  <p><input type="text" name="username" placeholder="Username"
  required value="<?php echo $row['username'];?>" /></p>
  <label for="firstname"> Firstname : </label>
  <p><input type="text" name="firstname" placeholder="Firstname" 
  required value="<?php echo $row['firstname'];?>" /></p>
  <label for="lastname"> Lastname : </label>
  <p><input type="text" name="lastname" placeholder="Lastname" 
  required value="<?php echo $row['lastname'];?>" /></p>
  <label for="i/cno"> I/C No : </label>
  <p><input type="text" name="identificationCard" placeholder="I/C" 
  required value="<?php echo $row['identificationCard'];?>" /></p>
  <label for="email"> Email : </label>
  <p><input type="text" name="email" placeholder="Email" 
  required value="<?php echo $row['email'];?>" /></p>
  <label for="contact"> Contact : </label>
  <p><input type="text" name="contact" placeholder="Contact" 
  required value="<?php echo $row['contact'];?>" /></p>
  <p><input name="submit" type="submit" value="Submit" /></p>
</form>

谢谢。

【问题讨论】:

  • 您是否检查过submittedby 是否真的存在于您的表中?
  • 显示你的数据库架构
  • 分享你的表users结构

标签: php html mysql forms email


【解决方案1】:

检查"submittedby" 字段是否存在于您的用户表中

【讨论】:

    【解决方案2】:

    这意味着您的“用户”表不包含“提交者”列。您需要将此列添加到您的表中,此脚本才能正常工作。

    【讨论】:

      【解决方案3】:

      很明显,submitby 不是表中的列。

      FWIW,我觉得这更容易阅读......

      update="
      update users 
         set enrol_Date = '$enrol_Date'
           , username = '$username'
           , firstname = '$firstname'
           , lastname = '$lastname'
           , identificationCard = '$identificationCard'
           , email '$email'
           , contact = '$contact'
           , submittedby = '$submittedby' 
       where id = '$id'
      "; 
      

      ...但是,您确实应该在 mysqli 中使用参数化查询,所以也请参阅。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-09
        • 2023-03-14
        • 2020-10-27
        相关资源
        最近更新 更多