【发布时间】:2016-06-22 00:00:19
【问题描述】:
我刚刚解决了我的字段列表的一个问题(我承认这很粗心),但我找不到解决这个问题的方法。我已经查看了error-column-count-doesn't-match-value,但找不到适用于我的代码的解决方案。有什么建议吗?
参加表格.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( "mysql.hostinger.co.uk", "u733142706_root",
"Summer$2000", "u733142706_user"); $filter_Result=m ysqli_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>
插入multi.php
<?php
/*
Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password)
*/
$link = mysqli_connect("mysql.hostinger.co.uk", "u733142706_root", "Summer$2000", "u733142706_user");
// Check connection
if ($link === false)
{
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Escape user inputs for security
$FName = mysqli_real_escape_string($link, $_POST['FName']);
$LName = mysqli_real_escape_string($link, $_POST['LName']);
$Mark = mysqli_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);
?>
【问题讨论】:
-
<?php while($row=m ysqli_fetch_array($search_result)):?>m和ysqli之间的空格 -
if($link===f alse)f和alse之间的空格 -
SELECT 'Mark' ,3"之后insertmulti.php中的封装错误 -
对不起 Sam,这里有很多非常基本的语法错误。花时间正确缩进所有内容是值得的,这将解决这里的很多问题。