对于我的项目,我试图通过使用我数据库中过去学生的数据来预测一个过去学生的A级数学成绩。所以,paststudent1获得了数学A级的A。在第一年的考试中,他们获得了计算机A,物理B,化学A,男性和97%的出勤率。如果当前1年级的学生得到相同的成绩,相同的科目,男性和相同的出勤率,我想说他们将获得相同的成绩。
我的代码中的错误说: "致命错误:未捕获的异常' PDOException' with message' SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;查看与您的MariaDB服务器版本对应的手册,以获得正确的语法,以便在附近使用#39;等级1 ='数学',' A''在第1行'在/home/u717042829/public_html/predicter.php:70堆栈跟踪:#0 /home/u717042829/public_html/predicter.php(70):PDOStatement->执行()#1 {main}抛出/ home / u717042829 /public_html/predicter.php在第70行"
第70行是:
$query->execute();

。
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
require("includes/config.php");
//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: login.php'); }
//define page title
$title = "Predict a Student's Grade";
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Past Student</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<?php
if (isset($_POST['name'])) {
$name = $_POST['name'];
$subject1 = $_POST['subject1'];
$grade1 = $_POST['grade1'];
$subject2 = $_POST['subject2'];
$grade2 = $_POST['grade2'];
$subject3 = $_POST['subject3'];
$grade3 = $_POST['grade3'];
$subject4 = $_POST['subject4'];
$grade4 = $_POST['grade4'];
$attendance = $_POST['attendance'];
$gender = $_POST['gender'];
$query = $db->prepare("SELECT * FROM paststudent WHERE subject1, grade1 = :subject1, :grade1");
$query->bindParam(':subject1', $subject1);
$query->bindParam(':grade1', $grade1);
$query->execute();
}
?>
<h1> Your predicted grade is <?php echo $query ?> </h1>
</body>
</html>
&#13;
现在我按小步骤将主题1与1级相匹配,然后进行2级2级,因为我太干了。
答案 0 :(得分:2)
您的查询的部分看起来不正确:
WHERE subject1, grade1 = :subject1, :grade1
你很可能意味着要改变它看起来像这样:
WHERE subject1 = :subject1 AND grade1 = :grade1
所以你的最终版本应为:
$query = $db->prepare( " SELECT * FROM paststudent "
. " WHERE subject1 = :subject1 AND grade1 = :grade1");
我建议阅读一些关于SQL基础知识的教程。
答案 1 :(得分:0)
这不是您从PDO获得结果的方法,请尝试
<body>
<table>
....
$query->execute();
}
while($row = $query->fetch(PDO::FETCH_ASSOC)){
echo "<tr><td>".$row['user']."</td></tr>"; --change user to what the column is actually called
}
?>
</table>
</body>
</html>