php - 创建多行条目时出现错误 : Could not take attendence Unknown column '‘FName’' in 'field list'

标签 php html mysql sql-insert

我在看之前的问题比如unknown column in list但发现它对我的情况没有帮助。

我有一个表格可以记录出勤情况(从我的数据库表“records”中调用姓名和类(class),并将其插入到名为“attendence”的表中。我的问题是插入数据库时​​出现留空。有什么想法吗?

我的代码:

考勤表.php

<?php include( "dbconfig.php"); session_start(); if(!isset($_SESSION[ 'login_user'])) { header( "Location: default.php"); } ?>
<!DOCTYPE html>
<html>

<head>
  <link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
  <meta charset="UTF-8">
  <title>User Area|SparkAcad</title>
  <style>
    body {
      background-size: cover;
      font-family: Montserrat;
    }
    .logo {
      width: 213px;
      height: 36px;
      margin: 30px auto;
    }
    .login-block {
      width: 320px;
      padding: 20px;
      background: #fff;
      border-radius: 5px;
      border-top: 5px solid #ff656c;
      margin: 0 auto;
    }
    .login-block h1 {
      text-align: center;
      color: #000;
      font-size: 18px;
      text-transform: uppercase;
      margin-top: 0;
      margin-bottom: 20px;
    }
    .login-block input {
      width: 100%;
      height: 42px;
      box-sizing: border-box;
      border-radius: 5px;
      border: 1px solid #ccc;
      margin-bottom: 20px;
      font-size: 14px;
      font-family: Montserrat;
      padding: 0 20px 0 50px;
      outline: none;
    }
    .login-block input#username {
      background: #fff url('http://i.imgur.com/u0XmBmv.png') 20px top no-repeat;
      background-size: 16px 80px;
    }
    .login-block input#username:focus {
      background: #fff url('http://i.imgur.com/u0XmBmv.png') 20px bottom no-repeat;
      background-size: 16px 80px;
    }
    .login-block input#password {
      background: #fff url('http://i.imgur.com/Qf83FTt.png') 20px top no-repeat;
      background-size: 16px 80px;
    }
    .login-block input#password:focus {
      background: #fff url('http://i.imgur.com/Qf83FTt.png') 20px bottom no-repeat;
      background-size: 16px 80px;
    }
    .login-block input:active,
    .login-block input:focus {
      border: 1px solid #ff656c;
    }
    .login-block button {
      width: 100%;
      height: 40px;
      background: #ff656c;
      box-sizing: border-box;
      border-radius: 5px;
      border: 1px solid #e15960;
      color: #fff;
      font-weight: bold;
      text-transform: uppercase;
      font-size: 14px;
      font-family: Montserrat;
      outline: none;
      cursor: pointer;
    }
    .login-block button:hover {
      background: #ff7b81;
    }
    table#header {
      width: 100%;
      background-color: #ff3366;
    }
    tr:hover {
      background-color: #f5f5f5
    }
  </style>
</head>

<body>

  <div class="logo">
    <table id="header" align="center">
      <tr>
        <td>
          <a href="welcome-home.php">Home</a>
        </td>
        <td>
          <a href="students.php">Student Managment</a>
        </td>
        <td>
          <a href="transcript.php">Transcript/SSL</a>
        </td>
        <td>
          <a href=""></a>
        </td>
      </tr>

    </table>
  </div>
  <div class="login-block">

    <!---uper boundAll content should go between these --->
    <?php if(isset($_POST[ 'search'])) { $valueToSearch=$ _POST[ 'valueToSearch']; // search in all table columns // using concat mysql function $query="SELECT * FROM `records` WHERE CONCAT(`FName`, `LName`) LIKE '%" .$valueToSearch. "%'"; $search_result=f
    ilterTable($query); } else { $query="SELECT * FROM `records`" ; $search_result=f ilterTable($query); } // function to connect and execute the query function filterTable($query) { $connect=m ysqli_connect( "host", "user",
    "password", "db"); $filter_Result=mysqli_query($connect, $query); return $filter_Result; } ?>
    <form action="insertmulti.php" method="post" align="center">


      <table border="1" align="center">
        <tr>

          <th>First Name</th>
          <th>Last Name</th>
          <th>Mark</th>

        </tr>

        <!-- populate table from mysql database -->
        <?php while($row=m ysqli_fetch_array($search_result)):?>
        <tr>
          <td>
            <?php echo $row[ 'FName'];?>
          </td>
          <td>
            <?php echo $row[ 'LName'];?>
          </td>
          <td>
            <input type="text" placeholder="Present/Absent/Tardy" id="Mark" value="Present">
          </td>

        </tr>

        <?php endwhile;?>
      </table>
      <input type="Submit" value="Take Attedence">
    </form>

    <!---lower bound All content should go between these --->
    <br>
    <br>
    <a href="logout.php">Logout</a>
  </div>
</body>

</html>

插入多文件

<?php /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link=m ysqli_connect( "mysql.hostinger.co.uk", "u733142706_root", "Summer$2000", "u733142706_user"); // Check connection
if($link===f alse){ die( "ERROR: Could not connect. " . mysqli_connect_error()); } // Escape user inputs for security $FName=m ysqli_real_escape_string($link, $_POST[ 'FName']); $LName=m ysqli_real_escape_string($link, $_POST[ 'LName']); $Mark=m ysqli_real_escape_string($link,
$_POST[ 'Mark']); // attempt insert query execution $sql="INSERT INTO attendence  (FName, LName, Mark)

SELECT  ‘FName’ ,1

UNION ALL

SELECT  ‘LName’ ,2

UNION ALL

SELECT  ‘Mark’ ,3" ; if(mysqli_query($link, $sql)){ echo "Records added successfully."; } else{ echo "ERROR: Could not take attendence " . mysqli_error($link); } // close connection mysqli_close($link); ?>

最佳答案

不要使用文字处理器来编辑您的代码:

SELECT  ‘FName’ ,1
        ^-----^--- 

这些在任何编程语言中都不是有效的引用。由于它们不是有效引号,数据库可以自由地将它们解释为字段标识符的一部分,显然您没有名称包含“大引号”的字段。

关于php - 创建多行条目时出现错误 : Could not take attendence Unknown column '‘FName’' in 'field list' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37954892/

相关文章:

php - PHP 的 MySQL 语法错误

php - 使用 Puppet 自动进行 Composer self 更新

javascript - 从 Controller 中的 View 读取 HTML 值

javascript - 我在哪里可以下载 eclipse 的基本服务器配置?

php - INSERT 请求在没有错误消息的情况下不起作用

php - Magento Ajax 购物车删除时重定向到删除页面

php - PHP的解释器文件是什么?

jquery - 需要在具有这些 ID 的点击事件上添加类 'select1'

MySQL查询另一个表中的多个日期

mysql - 提取查询中的所有数据和另一个查询中的一些数据