pdo mysql_num_rows_PHP-mysql_num_rows()期望参数1为资源,给定布尔...
当传递UPDATE查询时,mysql_query()返回boolean TRUE表示成功,否则返回FALSE表示失败,而mysql_num_rows()仅接受结果集资源作为其参数.为了确定UPDATE查询影响了多少行,请以连接资源作为参数调用mysql_affected_rows().
它并没有引起您现在遇到的问题,但是非常建议您在mysql_query()调用中附加或死掉(mysql_error()),以便捕获发生的任何MySQL错误.甚至建议您完全放弃mysql_ *函数,而转而使用PHP PDO扩展,如PHP手册中所建议的那样,并且这样做实际上不会招致更多的认知开销,以换取它在功能和性能上的巨大好处.安全.
抛开这些,下面是我如何更改您的代码,使其行为更像您所想的那样:
// obtain a database connection
$dbConn = mysql_connect($serverName, $user_name, $password)
or die("Cannot connect to server: " . mysql_error() . "
\n");
// mysql error number rarely adds enough information to be worth including
// select the database
mysql_select_db($db_name, $dbConn)
or die("Couldn't select $db_name: " . mysql_error() . "
\n");
// obtain escaped versions of query data for inclusion in update query
// it is imperative to use mysql_real_escape_string() or equivalent if you're
// going to use mysql_* functions instead of the far preferable PDO
// prepared statements; if you don't escape your data, you leave open the
// possibility of SQL injection, which someone will certainly soon use to
// screw up your website horribly
$id = mysql_real_escape_string($_GET['id']);
$additional_notes = mysql_real_escape_string($_GET['additional_notes']);
// assemble query to pass to mysql_query()
// no need for parentheses around the string; in fact i'm surprised that
// didn't result in a parse error
// also FYI re backticks, MySQL uses them to denote literal database/table/
// column names -- they're optional unless required to disambiguate between
// an entity name and a reserved word. for example, you can create a table
// containing a column named 'key', which is a MySQL reserved word, but you
// thereafter must refer to that column as `key`, with backticks, in any
// queries, to hint to MySQL's parser that you mean the column by that name
// and not the reserved word; otherwise, it's a parse error.
$sql = "UPDATE `rmstable2` SET `additional_notes` = '$additional_notes' WHERE `id` = '$id'";
// actually run the query
// this being an UPDATE query, the result is boolean and offers no
// additional useful information, so you need not capture it in a variable;
// the 'or die' clause will fire if it's false, and if it's true, you'll
// use mysql_affected_rows() to get the additional info you need.
mysql_query($sql)
or die(mysql_error());
// if the query failed, the script die()d on the previous line and didn't
// get here; if it did get here, you know the query succeeded
$resultcount = mysql_affected_rows($dbConn);
// this is technically correct but semantically odd; since you already included
// the 'additional_notes' value in the previous UPDATE query, and since
// that query certainly succeeded if we're evaluating this code at all,
// why run the same query again?
if ($resultcount == 1) {
mysql_query("UPDATE `rmstable2` SET `additional_notes` = '$additional_notes' WHERE `id` = '$id'")
or die(mysql_error());
}
// again, the 'or die' clauses mean that we can only have reached this point
// if the queries succeeded, so there's no need for an if() test here
echo "Update Successful!";
echo '
Your case has been updated.
';
// note the backslashes before the embedded double quotes; single quotes in
// tag attributes are technically invalid but most browsers will accept them,
// but you can use double quotes within a double-quoted string if you precede
// the embedded quotes with backslashes (called "escaping") to indicate that
// they're not to be taken as the end of the string
// (i.e., "\"\"" == '""')
echo "To see your changes please click here";
?>
pdo mysql_num_rows_PHP-mysql_num_rows()期望参数1为资源,给定布尔...相关推荐
- php 期望参数1为资源,php – imagesx()期望参数1是资源,给定布尔值
我使用的是图像缩略图库(Laravel的 resizer bundle),它从目录中获取jpg并使用imagesx()以不同的大小保存该图像.这在大多数情况下都可以正常工作. 问题:但有时当有一批图像 ...
- mysql_fetch_array()/ mysql_fetch_assoc()/ mysql_fetch_row()/ mysql_num_rows等…期望参数1为资源或结果
我正在尝试从MySQL表中选择数据,但收到以下错误消息之一: mysql_fetch_array()期望参数1为资源,给定布尔值 要么 mysqli_fetch_array()期望参数1为mysqli ...
- mysql_num_rows+报错_错误:警告:mysql_num_rows()期望参数1为资源,在第19行的C:\ xampp...
我不断收到使用的错误消息mysql_num_rows(),您能帮我弄清楚我的代码出了什么问题吗? 这是我的代码: //check if the user press submit if (isset( ...
- php 期望参数1为资源,PHP:mysql_fetch_array()期望参数1是资源,布尔给定
Possible Duplicate: 07000 我会在我的网站上的标题中显示,并且不会出现这种错误,我也不知道如何解决这个问题.谁能帮我? 这是add_answer.php文件: include( ...
- mysqli assoc php,关于php:mysqli_fetch_assoc()期望参数1为mysqli_result,给定布尔值
本问题已经有最佳答案,请猛点这里访问. Possible Duplicate: PHP: Warning: sort() expects parameter 1 to be array, resour ...
- STM32F030C8T6芯片参数和内部资源
产品参数 产品型号 内核 主频(MHz) Flash (Kbytes) STM32F030C8T6 Cortex-M0 48 64 RAM(Kbytes) E2PROM(Bytes) 封装 IO 8 ...
- mysqli mysql assoc_mysqli_fetch_assoc()期望参数1为mysqli_result或如何获取MySQLi
有时您的查询失败,您不知道原因.因此,配置PHP和mysqli以报告每个错误非常重要. 如何在mysqli中获取错误消息 首先,MySQLi在所有环境中连接之前总是有这条线:mysqli_report ...
- sendgrid html text,Laravel + SendGrid htmlspecialchars()期望参数1为字符串,给定对象
我已经在.env文件中设置了所有内容(尽管我还必须更新MAIL_HOST中的~/config/mail.php),并且能够发送测试电子邮件(在刀片内进行操作. 电子邮件模板本身的刀片与SendGrid ...
- python拟合威布尔参数_如何拟合威布尔分布?
我完全被拟合威布尔分布搞糊涂了weibull_params = sp.stats.exponweib.fit(df.speed, floc=0, f0=1) # Returns (1, 1.73581 ...
最新文章
- angularJS的controller之间如何正确的通信
- php无表单上传文件,php – 如何使用没有实体类的表单上传文件
- 010_CSS后代选择器
- 截断骨干用于检测,YOLO-ReT开源:边缘GPU设备上的高性能检测器
- Linux常用命令和服务器配置
- Java加入背景音乐
- 利用python爬虫(案例2)--X凰的一天
- 计算机二级证书在学校哪里领取,计算机二级证书去哪里领取
- django 利用PIL 保存图片
- android和linux操作系统的区别
- MYSQL安装和配置
- CVTE【嵌入式应用开发】【软件技术支持】面经【已拿offer】
- [ARM-Linux开发] 主设备号--驱动模块与设备节点联系的纽带
- SAP License:SD条件类型对应科目配置
- 技术系统优化还可以这样做?
- Android实现XML解析技术
- TCP模块如何处理数据包
- 2017 ACM/ICPC Asia Regional Beijing Online 记录
- mysql二进制安装shell脚本,一分钟就搞好linux上的mysql
- 启用iptables后,连接速度很慢