Php 只能通过引用传递变量(mysqli_stmt_bind_param)
我有这个代码,我真的不知道哪里有错误。 我已经阅读了PHP手册,显然(在我看来)一切都很好,有什么建议吗 我得到了一个错误: 致命错误:在第39行的C:\xampp\htdocs…\connect.inc.php中,只能通过引用传递变量: 第39行是:Php 只能通过引用传递变量(mysqli_stmt_bind_param),php,mysqli,Php,Mysqli,我有这个代码,我真的不知道哪里有错误。 我已经阅读了PHP手册,显然(在我看来)一切都很好,有什么建议吗 我得到了一个错误: 致命错误:在第39行的C:\xampp\htdocs…\connect.inc.php中,只能通过引用传递变量: 第39行是:mysqli\u stmt\u bind\param($stmt,“ssss”,“$name”,“$tmclocation”,“$nontmlocation”,“$countrycode”,“$ooffset”,“$toffset”,“$stime
mysqli\u stmt\u bind\param($stmt,“ssss”,“$name”,“$tmclocation”,“$nontmlocation”,“$countrycode”,“$ooffset”,“$toffset”,“$stime”,“$etime”,“$updated”,“$created”,“$alertc”,“$rcoby”,“$note”,“$rcogroup”,“$action”,“$workedby”)代码>
希望你能帮助我
问候!
迭戈。这就是问题所在:
mysqli_stmt_bind_param($stmt, "ssssssssssssssss", '$name','$tmclocation','$nontmclocation','$countrycode','$ooffset','$toffset','$stime','$etime','$updated','$created','$alertc','$rcoby','$note','$rcogroup','$action','$workedby');
您正确地传入了变量“stmt”
但是,您需要传递不带单引号的“$nontmclocation”
原因:
- “$nontmclocation”传入对变量值的引用(您需要的)
- “$nontmclocation”传入字符串文字“dollar-n-o-t-m-…-n”。(不是你想要的!)
这里有一个很好的例子:
删除该行变量周围的单引号。非常感谢您抽出时间回答这个问题(非常详细!)。我犯了一个相当业余的错误。此外,我将查看您与我分享的文件。这是必须传递的参考资料,而不是文件。。。你知道,“精确”和“精确”是有区别的。。。和“肛门”。措辞更新。。。
mysqli_stmt_bind_param($stmt, "ssssssssssssssss", '$name','$tmclocation','$nontmclocation','$countrycode','$ooffset','$toffset','$stime','$etime','$updated','$created','$alertc','$rcoby','$note','$rcogroup','$action','$workedby');
<?php
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt = mysqli_prepare($link, "INSERT INTO CountryLanguage VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent);
$code = 'DEU';
$language = 'Bavarian';
$official = "F";
$percent = 11.2;
/* execute prepared statement */
mysqli_stmt_execute($stmt);
printf("%d Row inserted.\n", mysqli_stmt_affected_rows($stmt));
/* close statement and connection */
mysqli_stmt_close($stmt);
/* Clean up table CountryLanguage */
mysqli_query($link, "DELETE FROM CountryLanguage WHERE Language='Bavarian'");
printf("%d Row deleted.\n", mysqli_affected_rows($link));
/* close connection */
mysqli_close($link);
?>