尝试在表中插入会话变量时在If语句上解析错误

时间:2018-08-06 09:33:44

标签: php

<?php
    $_SESSION['sdate'] = $_POST['sdate'];
    $_SESSION['edate'] = $_POST['edate'];
    //assigning the variables in sessions


    $sdate = $_POST['sdate'];
    $edate = $_POST['edate'];

    $query = mysqli_query($conn,"INSERT INTO subscribers (username, password, sdate, edate, day ) 
            VALUES ('".$_SESSION['username']."','".$_SESSION[md5(password-1)]."','".$sdate."', '".$edate."', 50");
    //inserting into the table subscribers
                    ''
    if ($conn -> $query === TRUE) {
        $_SESSION['message'] = "subscription Complete!";
        header("location: ../register/error.php");
        //success location
    }
    else{
      $_SESSION['message'] = "subscription  Failed!";
        header("location: ../register/error.php");
    }
?>

我一直试图在表中插入会话变量,但它会带来解析错误:

  

“解析错误:语法错误,第15行的C:\ xampp \ htdocs \ bennett \ subscription \ function.php中出现意外的'if'(T_IF)”

2 个答案:

答案 0 :(得分:0)

$_SESSION[md5(password-1)]放入变量中,为什么还要使用密码传递-1?

就这样吧

$password = $_SESSION["password"];

$query = mysqli_query($conn,"INSERT INTO subscribers (username, password, sdate, edate, day ) 
    VALUES ('".$_SESSION['username']."','".md5($password)."','".$sdate."', '".$edate."', 50");

希望这会有所帮助。

答案 1 :(得分:0)

$query = mysqli_query($conn,"INSERT INTO subscribers (username, password, sdate, edate, day ) 
            VALUES ('".$_SESSION['username']."','".$_SESSION[md5(password-1)]."','".$sdate."', '".$edate."', 50");
    //inserting into the table subscribers
                    ''

if进行代码解析以引发错误之前,这两个单引号