Reputation: 1063
Everytime I make a INSERT query using PHP, I get this error: "supplied argument is not a valid MySQL-Link resource"
Even so, the query works perfectly and the data is always inserted in the database.
Should I worry about that?
Thanks in advance!
EDIT-> here is the query
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')");
Upvotes: 0
Views: 150
Reputation: 9754
Try:
$connection = mysql_connect($h, $un, $pw);
Try:
$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);
Upvotes: 1
Reputation: 718
Are you escaping the data you insert?
Look at this if using MYSQLi: https://www.php.net/manual/en/mysqli.real-escape-string.php
otherwise, look here: https://www.php.net/manual/en/function.mysql-real-escape-string.php
You should always escape data before submitting it to a database as a rule :)
Hope this helps!
Upvotes: 0