Php 警告:mysql_num_rows():提供的参数不是有效的mysql结果资源nationbuilder webhooks API
我们正在使用webhooks API为我们的nationbuilder帐户创建一个应用程序,我正在使用以下代码: 要连接并将表添加到数据库,我经常遇到以下错误: 警告:Php 警告:mysql_num_rows():提供的参数不是有效的mysql结果资源nationbuilder webhooks API,php,mysql,webhooks,Php,Mysql,Webhooks,我们正在使用webhooks API为我们的nationbuilder帐户创建一个应用程序,我正在使用以下代码: 要连接并将表添加到数据库,我经常遇到以下错误: 警告:mysql\u num\u rows():第41行的/home/www/ran-methods.org/webhooks.php中提供的参数不是有效的mysql结果资源 下面是我的代码。非常感谢你 <?php // get the request $data = $_REQUEST['payload']; // san
mysql\u num\u rows()
:第41行的/home/www/ran-methods.org/webhooks.php中提供的参数不是有效的mysql结果资源
下面是我的代码。非常感谢你
<?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);
}
?>
您需要运行查询…您正在尝试获取字符串的行数
$query = mysql_query("SELECT `nb_id` FROM `webhook_backup` WHERE `nb_id` = '". $id ."'");
$num_rows = mysql_num_rows($query);
但是,不要使用mysql.*
函数,它们已被弃用。改为使用mysqli.*
。rtfm ok Now I在用mysqli替换所有mysql并替换这两行之后,我收到以下错误。警告:mysqli_select_db()预期参数1为mysqli,第23行/home/www/ran-methods.org/webhooks.php中给出的字符串警告:mysqli_query()预期至少有2个参数,第40行/home/www/ran-methods.org/webhooks.php中给出1警告:mysqli_num_rows()期望参数1为mysqli_结果,第41行/home/www/ran-methods.org/webhooks.php中给出null警告:mysqli_query()期望参数1为mysqli,第67I行/home/www/ran-methods.org/webhooks.php中给出的字符串我没有说“用‘mysqli_u’替换‘mysql_u’,它会神奇地工作。”我说“使用mysqli_u*”。阅读文档。