underv3 Posted November 8, 2008 Share Posted November 8, 2008 I'm not sure if that is the problem but I am getting this error: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /------------/example.php on line 124 The code is: function read(){ mysql_query("UPDATE table SET on = '1' WHERE id = $idstatus", $connection) or die("Error querying database. Please contact the webmaster about this issue."); header('Location: example.php'); } This is for one of the functions (the one that I am calling) the rest are just there for now but I am assuming that they don't matter if you don't call them. I essentially want to set the field "on" to 1 only where the id matches the selected "idstatus". Any help would be great! Thanks! Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted November 8, 2008 Share Posted November 8, 2008 You can't use variables defined outside of your function inside your function, like $connection. You have to make it global like this: function read(){ global $connection; global $idstatus; mysql_query("UPDATE table SET on = '1' WHERE id = $idstatus", $connection) or die("Error querying database. Please contact the webmaster about this issue."); header('Location: example.php'); } Also you should try to use as few globals as possible. Making your $connection global might be an exception, but you'll probably want to pass your $idstatus as an argument into the function. Quote Link to comment Share on other sites More sharing options...
underv3 Posted November 8, 2008 Author Share Posted November 8, 2008 Also you should try to use as few globals as possible. When would it be appropriate? but you'll probably want to pass your $idstatus as an argument into the function. I'm not really sure how. I found this article giving methods to pass information in and out of functions but i'm not really sure how to incorporate it. Just for the sake of testing my function I put all the variables inside my function and I still get an error :-\ function read(){ $connection = mysql_connect("localhost", "user", "pass") or die("Error connecting to the database. Please contact the webmaster about this issue."); mysql_query("UPDATE table SET on = '1' WHERE id = 25", $connection) or die("Error querying database. Please contact the webmaster about this issue."); header('Location: example.php'); } Would it matter that the "on" field in my database has a default value of "0"? And even with that code I'm getting the die error "Error querying database. Please contact the webmaster about this issue." ??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.