dongma6326 2017-02-10 05:56
浏览 48
已采纳

会话错误值无法插入到DB中

i have a php code that insert session value into database,but i get this error when trying to insert Error: INSERT INTO tbale name (amount,bankname) VALUES ( 20000.00,gtbank) Unknown column 'gtbank' in 'field list'.the session has the value GTBANK below is my code that insert session value to database

    <?php

    session_start(); {



    //Include database connection details
    include('../../dbconnect.php');

    if($_SESSION["bn"]) {

}

$amount =  strip_tags($_POST['cat']);
$field1amount = $_POST['cat'];
$field2amount = $field1amount + ($field1amount*0.5);


$sql = "INSERT INTO provide_help (amount,bankname) VALUES ( $field1amount,".$_SESSION['bn'].")";
if (mysqli_query($conn, $sql)) 


$sql = "INSERT INTO gh (ph_id, amount) VALUES (LAST_INSERT_ID(), $field2amount)";
if (mysqli_query($conn, $sql)) 

 {
    $_SESSION['ph'] ="<center><div class='alert alert-success' role='alert'>Request Accepted.</div></center>";
   header("location: PH.php");
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
}
?>

anyone who can help please?.thanks

  • 写回答

2条回答 默认 最新

  • duanchu0031 2017-02-10 05:59
    关注

    bankname field is type of varchar I think. So you need to pass string with quotes ''. See below your code should be like this.

    $sql = "INSERT INTO provide_help (amount,bankname)
         VALUES ( $field1amount,'".$_SESSION['bn']."')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?