[英]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource nationbuilder webhooks API
We are creating an app for our nationbuilder account using the webhooks API, I'm using a code found here : 我们正在使用webhooks API为我们的nationalbuilder帐户创建一个应用,我使用的代码位于:
https://gist.github.com/amwelles/5165395#file-webhooks-php https://gist.github.com/amwelles/5165395#file-webhooks-php
to connected and add tables to our database and I keep getting this error : 连接并向我们的数据库中添加表,我不断收到此错误:
Warning:
mysql_num_rows()
: supplied argument is not a valid MySQL result resource in /home/www/ran-methods.org/webhooks.php on line 41警告:
mysql_num_rows()
:在第41行的/home/www/ran-methods.org/webhooks.php中,提供的参数不是有效的MySQL结果资源
Below is my code. 下面是我的代码。 SUper big thanks in advance.
非常感谢。
<?php
// get the request
$data = $_REQUEST['payload'];
// sanitize the data
$unescaped_data = stripslashes($data);
// set up our object
$person = json_decode($unescaped_data);
// assign variables
$id = $person->signup->nationbuilder_id; // used as a unique identifier
$first_name = $person->signup->first_name;
$last_name = $person->signup->last_name;
$mobile_phone = $person->signup->mobile_number;
$work_phone = $person->signup->work_phone_number;
$other_phone = $person->signup->phone_number;
$email_1 = $person->signup->email1;
$email_2 = $person->signup->email2;
$email_3 = $person->signup->email3;
// connect to our DB
$connect = mysql_connect("localhost","username redacted","password redacted");
mysql_select_db("emmtal_targets", $connect);
// let's create this table if it doesn't exist
$sqltable = "CREATE TABLE IF NOT EXISTS webhook_backup
(
`first_name` varchar(80),
`last_name` varchar(80),
`nb_id` int,
`mobile_phone` varchar(20),
`work_phone` varchar(20),
`other_phone` varchar(20),
`email_1` varchar(255),
`email_2` varchar(255),
`email_3` varchar(255)
)";
// does this user exist in the DB already?
$query = "SELECT `nb_id` FROM `webhook_backup` WHERE `nb_id` = '". $id ."'";
$num_rows = mysql_num_rows($query);
// update if this user already exists
if ($num_rows > 0) {
$update = "UPDATE `webhook_backup` SET
`first_name` = '". $first_name ."'
`last_name` = '". $last_name ."'
`mobile_phone` = '". $mobile_phone. "'
`work_phone` = '". $work_phone. "'
`other_phone` = '". $other_phone. "'
`email_1` = '". $email_1 ."'
`email_2` = '". $email_2 ."'
`email_3` = '". $email_3 ."'
WHERE `nb_id` = '". $id ."'
LIMIT 1";
mysql_query($update, $connect);
}
// add a new row if this user does not yet exist
if ($num_rows == 0) {
$insert = "INSERT INTO `webhook_backup`
(`first_name`, `last_name`, `mobile_phone`, `work_phone`, `other_phone`,
`email_1`, `email_2`, `email_3`, `nb_id`)
VALUES ('". $first_name ."','". $last_name ."','". $mobile_phone ."','". $work_phone ."',
'". $other_phone ."','". $email_1 ."','". $email_2 ."','". $email_3 ."','". $id ."')";
mysql_query($insert, $connect);
}
?>
You need to run the query...you're trying to get the number of rows of a string. 您需要运行查询...您正在尝试获取字符串的行数。
$query = mysql_query("SELECT `nb_id` FROM `webhook_backup` WHERE `nb_id` = '". $id ."'");
$num_rows = mysql_num_rows($query);
However, don't use mysql_*
functions, they are deprecated. 但是,不要使用
mysql_*
函数,它们已被弃用。 Use mysqli_*
instead. 改用
mysqli_*
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.