PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
gaogier
Forum Contributor
Posts: 391 Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:
Post
by gaogier » Thu May 01, 2008 4:43 am
Warning: mysql_real_escape_string() expects parameter 2 to be resource, null given in /home/gaogier/mysql_connect.php on line 11 pops up every time i try and update my database
Code: Select all
<?php
$dbh=mysql_connect ("localhost", "USER", "PASS") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("DATABASE");
function escape_data ($data){
global $dbh;
if (ini_get('magic_quotes_gpc')){
$data = stripslashes($data);
}
return mysql_real_escape_string (trim ($data), $dbh);
}
?>
kaszu
Forum Regular
Posts: 749 Joined: Wed Jul 19, 2006 7:29 am
Post
by kaszu » Thu May 01, 2008 4:59 am
I had similar problem, add
at the beginning of the file.
gaogier
Forum Contributor
Posts: 391 Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:
Post
by gaogier » Thu May 01, 2008 5:14 am
do you mean the mysql connect file or the admin file (where you update your databases)?
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Thu May 01, 2008 6:12 am
Don't use global. Pass the database connection to the function as a parameter.
gaogier
Forum Contributor
Posts: 391 Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:
Post
by gaogier » Thu May 01, 2008 8:12 am
how?
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Thu May 01, 2008 8:52 am
Same way as you're passing $data.