dtwncxs3547 2015-01-25 20:24
浏览 24

我的pdo语句中的错误

For my project i'm trying to predict a paststudent's A level maths grade by using past student's data in my database. So paststudent1 got an A in maths A level. In year one exams they got an A in Computing, B in Physics, A in Chemistry, Male and 97% attendance. If the current student in Year 1 got the same grades, same subjects, male and same attendance i want to say they will get the same grade.

My error in my code says: "Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' grade1 = 'Maths', 'A'' at line 1' in /home/u717042829/public_html/predicter.php:70 Stack trace: #0 /home/u717042829/public_html/predicter.php(70): PDOStatement->execute() #1 {main} thrown in /home/u717042829/public_html/predicter.php on line 70"

Line 70 is:

            $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>

Right now i'm taking it in small steps matching subject 1 with grade 1 then doing subject 2 grade 2 as i get it too work.

</div>
  • 写回答

2条回答 默认 最新

  • doushui3061 2015-01-25 20:27
    关注

    This part of your query looks incorrect:

    WHERE subject1, grade1 = :subject1, :grade1
    

    you most likely meant it to be altered to look like this:

    WHERE subject1 = :subject1 AND grade1 = :grade1
    

    so your final version of that line should read:

    $query = $db->prepare(  " SELECT * FROM paststudent "
                          . " WHERE subject1 = :subject1 AND grade1 = :grade1");
    

    I recommend reading some tutorials on SQL basics.

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行