gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 10:41:22 24 4
gpt4 key购买 nike

我在看之前的问题比如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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com