2017-02-09 160 views
0

任何人都可以帮助我完成我的准备声明吗?准备好的声明

我无法弄清楚到底是怎么回事错在这里

$stmt = $dbCon->prepare("INSERT INTO rock_news (heading, subheading, description, author) VALUES (?, ?, ?, ?)"); 
$stmt->bind_param("sss", $heading, $subheading, $description, $author); 
$stmt->execute(); 


// set parameters and execute 
$heading = $_POST['heading']; 
$subheading = $_POST['subheading']; 
$description = $_POST['description']; 
$author = $_POST['author']; 
$stmt->execute(); 

这项工作?

$sql ="INSERT INTO rock_news (heading, subheading, description, author) VALUES ('$_POST[heading]','$_POST[subheading]','$_POST[description]','$_POST[author]')"; 
    if ($dbCon->query($sql) === TRUE) { 
     echo "New record created successfully"; 
    } else { 
     echo "Error: " . $sql . "<br>" . $dbCon->error; 
    } 

    ?> 

我得到这个错误,同时试图连接

注意:未定义的常量标题的使用 - 在/xxx/sandbox/royalRockFestival/pages/send_form.php摆出“标题”第6行ssaddas警告: mysqli_stmt :: bind_param():类型定义字符串中的元素数量与第9行中的/xxx/sandbox/royalRockFestival/pages/send_form.php中绑定变量的数量不匹配

这是什么意思?

+0

有什么代码之前'$语句= $ dbCon->准备(“INSERT INTO rock_news(标题,副标题,描述,作者)VALUES( ?,?,?,?)“);'? –

+0

问题与$ stmt-> bind_param(“sss”,$标题,$副标题,$描述,$作者); 替换为$ stmt-> bind_param(“ssss”,$ heading,$ subheading,$ description,$ author); –

回答

1

在行$stmt->bind_param("sss", $heading, $subheading, $description, $author);,
你有4个参数,但只有3个绑定类型("sss"),它代表了字符串,字符串,字符串。只需将其更改为"ssss"即可使用。

+0

这除去了一个以外的所有错误,非常感谢! –

+0

我现在得到这个错误 注意:使用未定义的常量标题 - 在第6行的/xxx/sandbox/royalRockFestival/pages/send_form.php中假设'标题'adsads –

+0

您的第一个'$ stmt-> execute() '在定义要绑定的变量之前触发。 –

0

这就是你需要绑定帕拉姆在准备发言

$stmt = $dbCon->prepare("INSERT INTO rock_news (heading, subheading, description, author) VALUES (?, ?, ?, ?)"); 

    $stmt->bind_param("ssss", $heading, $subheading, $description, $author); 

    // set parameters and execute 
    $heading = $_POST['heading']; 
    $subheading = $_POST['subheading']; 
    $description = $_POST['description']; 
    $author = $_POST['author']; 
    $stmt->execute();