0

每次我使用 PHP 进行 INSERT 查询时,都会收到此错误:“提供的参数不是有效的 MySQL-Link 资源”

即便如此,查询也能完美运行,并且数据始终插入到数据库中。

我应该担心吗?

提前致谢!

编辑->这里是查询

函数.php

function connect(){

    $h='myip';

    $un='popguest';

    $pw='mypassword';

    $connection = mysql_connect($h, $un, $pw, false);

    if(!$connection){

            die('Error connecting to database: ' . mysql_error());

    }

    mysql_set_charset('uf8',$connection);

    return $connection;

}

启动子.php

require_once("../functions/functions.php");
$f = new functions();
$f->connect();

$username=$_COOKIE["username"];
$p=$_GET['p'];

mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_results=utf8');
$result3 = mysql_query("INSERT IGNORE INTO popguest.guest (username, promoter) VALUES ('$username', '$p')");
4

2 回答 2

1

尝试:

$connection = mysql_connect($h, $un, $pw);

尝试:

$f = new functions();
$link = $f->connect();
$username = mysql_real_escape_string($_COOKIE['username']);
$p = mysql_real_escape_string($_GET['p']);
$result3 = mysql_query("INSERT IGNORE INTO popguest.guest (username, promoter) VALUES ('$username', '$p')",$link);
于 2012-11-24T17:00:56.663 回答
0

您是否正在转义您插入的数据?

如果使用 MYSQLi,请查看:http: //uk1.php.net/manual/en/mysqli.real-escape-string.php

否则,请看这里: http ://uk1.php.net/manual/en/function.mysql-real-escape-string.php

通常,您应该始终在将数据提交到数据库之前对其进行转义:)

希望这可以帮助!

于 2012-11-24T14:37:47.330 回答