dongmibeng5885 2015-12-03 18:28
浏览 29
已采纳

将多个会话变量从PHP插入到mySQL数据库中,为什么不能正常工作[关闭]

Hi I cannot get the below query to work in order to insert the session data into the database, Could anyone please tell me what is wrong with it or what I can do to fix it? Thanks in advance.

<?php
session_start();
 if (isset($_POST['sub'])) {
$host='localhost';
$user='root';
$pass='';
$db='theatre_booking';

$con=mysqli_connect($host,$user,$pass,$db);

$row = $_POST['row'];
$_SESSION["row"]=$row;  

$zone = $_POST['zone'];
$_SESSION["zone"]=$zone;

$quantity = $_POST['numberOfTickets'];
$_SESSION["numberOfTickets"]=$quantity;



$sql="INSERT INTO booking(PerfDate, PerfTime, Name, Email, RowNumber) 
VALUES 
    '{$_SESSION['date']}',
    '{$_SESSION['time']}',
    '{$_SESSION['name']}',
    '{$_SESSION['email']}',
    '{$_SESSION['row']}')";

    if ($con->query($sql) === TRUE) {
    echo "Booking successful";
} else {
    echo "Error: " . $sql . "<br>" . $con->error;
}
 }





?>
  • 写回答

2条回答 默认 最新

  • duanca3415 2015-12-03 18:32
    关注

    you are missing opening bracket '(' after values in insert statement.

    $sql="INSERT INTO booking(PerfDate, PerfTime, Name, Email, RowNumber) 
    VALUES (
        '{$_SESSION['date']}',
        '{$_SESSION['time']}',
        '{$_SESSION['name']}',
        '{$_SESSION['email']}',
        '{$_SESSION['row']}')";
    
        if ($con->query($sql) === TRUE) {
        echo "Booking successful";
    } else {
        echo "Error: " . $sql . "<br>" . $con->error;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合