Sam Powers Sam Powers - 5 months ago 11
SQL Question

When creating a multi row entry I get the error: Could not take attendence Unknown column '‘FName’' in 'field list'

I was looking at the previous questions such as unknown column in list But found it to not help in my case.

I have a form that will take the attendance(which is calling the names and classes from my database table 'records' and is inserting it into the table called 'attendence'. My issue is when inserting into the database it turns up to be blank. Any ideas?

My code:

attendence-form.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>





insertmulti.php



<?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); ?>




Answer

Don't use a word processor to edit your code:

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

Those aren't valid quotes in ANY programming language. Since they're not valid quotes, the DB is free to interpret them as being part of the field identifier, and obviously you don't have a field whose name contains the "curly quotes".

Comments