Neosocrates Posted November 14, 2010 Share Posted November 14, 2010 Hey, I have been having a problem with this code for a while now where I connect to the MySQL database to retrieve the desired information, but always get an error message. I have tried to correct it myself by changing bits of the code and searched the internet, but still have no idea how to fix it. Any help would be appreciated. The error is as follows: Notice: An error occured1: in <filelocation> on line 18 Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in <filelocation> on line 21 Notice: An error occured2: in <filelocation> on line 15 My code as is follows: require_once('../mysqli_connect.php') ; $query = "SELECT * FROM database WHERE mem_id='".($_GET['id'])."'"; $result = @mysql_query($dbc, $query) OR trigger_error("An error occured1: " . mysql_error()); $row = mysql_fetch_array($result) OR trigger_error("An error occured2: " . mysql_error()); echo "<b>Date: </b> ".$row['date']; echo "<br><b>ID: </b> ".$row['mem_id']; Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/218626-mysql_fetch_array-issue/ Share on other sites More sharing options...
Neosocrates Posted November 15, 2010 Author Share Posted November 15, 2010 I still haven't had any luck solving this - completely clueless now. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/218626-mysql_fetch_array-issue/#findComment-1134486 Share on other sites More sharing options...
AbraCadaver Posted November 15, 2010 Share Posted November 15, 2010 Get rid of the error suppression crap @. Your problem is most likely: http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html Quote Link to comment https://forums.phpfreaks.com/topic/218626-mysql_fetch_array-issue/#findComment-1134490 Share on other sites More sharing options...
Neosocrates Posted November 15, 2010 Author Share Posted November 15, 2010 I removed that previously, and did so again, but still have exactly the same problem. If I establish a connection with the database using mysql_connect("localhost", "root", "password") or trigger_error("MySQL Connection Failed: " . mysql_error()); mysql_select_db("dbname") or trigger_error("MySQL Select DB Failed: " . mysql_error()); Then I have no problem retrieving the data. It is when I access the file through the require_once function that the problem occurs. Quote Link to comment https://forums.phpfreaks.com/topic/218626-mysql_fetch_array-issue/#findComment-1134504 Share on other sites More sharing options...
Pikachu2000 Posted November 15, 2010 Share Posted November 15, 2010 In this: mysql_query($dbc, $query), the first parameter should be the query, not the connection resource. Quote Link to comment https://forums.phpfreaks.com/topic/218626-mysql_fetch_array-issue/#findComment-1134506 Share on other sites More sharing options...
Neosocrates Posted November 15, 2010 Author Share Posted November 15, 2010 I then encounter the errors: Warning: mysql_query() expects parameter 2 to be resource, object given in <filename> on line 12 Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in <filename> on line 15 Quote Link to comment https://forums.phpfreaks.com/topic/218626-mysql_fetch_array-issue/#findComment-1134508 Share on other sites More sharing options...
PFMaBiSmAd Posted November 15, 2010 Share Posted November 15, 2010 You are mixing a mysqli database connection with mysql_ function calls. You cannot mix mysqli and mysql statements on a single connection. Quote Link to comment https://forums.phpfreaks.com/topic/218626-mysql_fetch_array-issue/#findComment-1134511 Share on other sites More sharing options...
Neosocrates Posted November 15, 2010 Author Share Posted November 15, 2010 You are mixing a mysqli database connection with mysql_ function calls. You cannot mix mysqli and mysql statements on a single connection. Ah, thank you so much! Appreciate the help, everyone. Quote Link to comment https://forums.phpfreaks.com/topic/218626-mysql_fetch_array-issue/#findComment-1134514 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.