每次我使用PHP进行INSERT查询时,都会收到此错误:“提供的参数不是有效的MySQL-Link资源”
即使这样,查询也能完美运行,数据总是插入数据库中。
我应该担心吗?
提前致谢!
编辑 - >这是查询
的functions.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;
}
promoter.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')");
答案 0 :(得分: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);
答案 1 :(得分: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
在将数据作为规则提交到数据库之前,您应始终转义数据:)
希望这有帮助!