简体   繁体   English

mysqli bind_param更新查询不起作用

[英]mysqli bind_param update query Not Working

<?php
include_once 'dbconnect.php';
$flds= "UPDATE OFFICE SET OADD02=? WHERE OFFNO=$OFFNO";
$stmt = $mysqli->prepare($flds);
$stmt->bind_param('s',$OADD02);
$stmt->execute();
$stmt->close();

I execute the above and at the bind_param it fails. 我执行以上操作,并在bind_param失败。 My process is as such: 我的过程是这样的:

  • The user goes into the form to update the information (information is display via mysqli queries); 用户进入表单以更新信息(通过mysqli查询显示信息);
  • They click submit. 他们单击提交。

Initializing and populating $stmt works, however when I get to bind_param the page goes blank. 初始化和填充$stmt是可行的,但是当我进入bind_param该页面将变为空白。 Here is the URL: http://gccitech.com/iclub/office.php?ONO=4&ftype=m 这是网址: http : //gccitech.com/iclub/office.php?ONO=4&ftype=m

Try to bind both parameters: 尝试绑定两个参数:

$flds= "UPDATE OFFICE SET OADD02=? WHERE OFFNO=?";
$stmt = $mysqli->prepare($flds);
$stmt->bind_param('ss',$OADD02, $OFFNO);

I presumed, that $OFFNO is a string. 我以为$ OFFNO是一个字符串。 If it's an integer, use this: 如果是整数,请使用以下命令:

$stmt->bind_param('si',$OADD02, $OFFNO);

After reading through this I have noticed a couple of things. 阅读完这篇文章后,我注意到了几件事。 You have required a file but there you have not declared $mysqli meaning that the connection string might not work. 您需要一个文件,但尚未声明$ mysqli,这意味着连接字符串可能无法正常工作。

Also have you done checks around it to see if there is any errors that are going to show up? 您是否也检查过它,看看是否会出现任何错误? Try this code to check for errors and you will have a better idea of what is going on 尝试使用此代码检查错误,您将对发生的事情有更好的了解

if ($sql = $mysqli->prepare($query)){
            $sql->bind_param("s",$OADD02);
            $sql->execute();
        } else {
            echo "Failed prepare statement" . $this->conn->error . $this->conn->error;
        }

This way you'll be able to print out the MySQL errors. 这样,您就可以打印出MySQL错误。 Once you have done this put the errors up and I can try and help. 完成此操作后,请提出错误,我会尽力帮助您。

Also you have not declared $OFFNO meaning that the query won't properly execute either. 另外,您还没有声明$ OFFNO,这意味着查询也不会正确执行。 If you declare the connection of both $mysqli and $OFFNO and make sure you do error checking using the if statement above you should be able to see why it isn't working. 如果声明$ mysqli和$ OFFNO都已连接,并确保使用上面的if语句进行错误检查,则应该可以看到为什么它不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM