Spanishearl Posted January 2, 2013 Share Posted January 2, 2013 I'm trying to get a script running which used to be on a different site, and I've been modifying bits and pieces (so far basically the link to the new location, and adding a new MySQL database to work with this), everything is starting to finally work, but then I got this error. I'm a newbie to PHP, and I can't seem to figure out what I need to fix. This code worked perfectly previously, and google isn't being too helpful. Any chance someone knows what I'm missing? Error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/content/45/9484341/html/recruiting/recruitment.php on line 66 Line 66 to 79 while($row = mysql_fetch_array($result)) { $tempName = $row['Name']; $tempLink = $row['Link']; $tempMS = $row['MessageSent']; if ($tempMS == 0) { echo "<tr>"; echo "<td onclick=\"parent.location='deleteEntry.php?link=$tempLink&un=$userName&pw=$password'\">" . $tempName . "</td>"; echo "<td> <a href=" . $tempLink . " target=\"_blank\">" . $tempLink . "</a> </td>"; echo "</tr>"; } } echo "</table>"; Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 2, 2013 Share Posted January 2, 2013 See the link in my signature. Quote Link to comment Share on other sites More sharing options...
Beeeeney Posted January 2, 2013 Share Posted January 2, 2013 I'm trying to get a script running which used to be on a different site, and I've been modifying bits and pieces (so far basically the link to the new location, and adding a new MySQL database to work with this), everything is starting to finally work, but then I got this error. I'm a newbie to PHP, and I can't seem to figure out what I need to fix. This code worked perfectly previously, and google isn't being too helpful. Any chance someone knows what I'm missing? Error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/content/45/9484341/html/recruiting/recruitment.php on line 66 Line 66 to 79 while($row = mysql_fetch_array($result)) { $tempName = $row['Name']; $tempLink = $row['Link']; $tempMS = $row['MessageSent']; if ($tempMS == 0) { echo "<tr>"; echo "<td onclick=\"parent.location='deleteEntry.php?link=$tempLink&un=$userName&pw=$password'\">" . $tempName . "</td>"; echo "<td> <a href=" . $tempLink . " target=\"_blank\">" . $tempLink . "</a> </td>"; echo "</tr>"; } } echo "</table>"; Well according to that error, you've passed a boolean into your mysql_fetch_array() function. More specifically, $result. Show me the code where you declared $result. Quote Link to comment Share on other sites More sharing options...
Spanishearl Posted January 2, 2013 Author Share Posted January 2, 2013 Well according to that error, you've passed a boolean into your mysql_fetch_array() function. More specifically, $result. Show me the code where you declared $result. That's line 58, just looking now, I'm not sure where "gv_recruitment" actually is. Where should I be putting that? $result = mysql_query("SELECT * FROM gv_recruitment"); Quote Link to comment Share on other sites More sharing options...
Beeeeney Posted January 2, 2013 Share Posted January 2, 2013 That's line 58, just looking now, I'm not sure where "gv_recruitment" actually is. Where should I be putting that? $result = mysql_query("SELECT * FROM gv_recruitment"); It's a table in your database. I don't know where you should be putting that. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 2, 2013 Share Posted January 2, 2013 You're not checking for errors. Read the link about debugging SQL, it shows you how to check for SQL errors. Quote Link to comment Share on other sites More sharing options...
Spanishearl Posted January 2, 2013 Author Share Posted January 2, 2013 You're not checking for errors. Read the link about debugging SQL, it shows you how to check for SQL errors. Thanks Jessica, I'll try out that debugging right away. Quote Link to comment Share on other sites More sharing options...
Spanishearl Posted January 2, 2013 Author Share Posted January 2, 2013 (edited) Jessica, You have the following in the debugging: $sql = "Your SQL statement here";$result = mysqli_query($sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error(), E_USER_ERROR); I presume I need to use "$result = mysqli_query($sql)", however, I don't have the $sql deal... I apologize, I'm still pretty new to php. <?php $userName = $_REQUEST["username"]; $password = $_REQUEST["password"]; if ($userName == "[default username]" && $password == "[default password]") { //run java code $testval = system('java readNationsFounded',$retval); //begin webpage code echo " [A Bunch of Information Posted on the Page]"; echo "<br> <br> <br>"; $con = mysql_connect("[myhost]","[mydatabase]","[mypassword]"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("nations_founded", $con); $result = mysql_query("SELECT * FROM gv_recruitment"); echo "<table border='1'> <tr> <th>Name</th> <th>Link</th> </tr>"; while($row = mysql_fetch_array($result)) { $tempName = $row['Name']; $tempLink = $row['Link']; $tempMS = $row['MessageSent']; if ($tempMS == 0) { echo "<tr>"; echo "<td onclick=\"parent.location='deleteEntry.php?link=$tempLink&un=$userName&pw=$password'\">" . $tempName . "</td>"; echo "<td> <a href=" . $tempLink . " target=\"_blank\">" . $tempLink . "</a> </td>"; echo "</tr>"; } } echo "</table>"; mysql_close($con); } else { echo "Log In Failed."; } ?> EDIT: I had a chat with the guy who used to run this, and he can't remember anything of how he had it set up since he hasn't ran the script in over a year. Edited January 2, 2013 by Spanishearl Quote Link to comment Share on other sites More sharing options...
cpd Posted January 2, 2013 Share Posted January 2, 2013 (edited) Your query has failed and returned false therefore you're passing false to mysql_fetch_array resulting in your error. If you'd read Jessica's post I'm 100% you'd of understood as it explains it clearly, I clarified what was going on by looking at the return values for http://php.net/mysql_query/ - an amazing resource to assist in debugging . People ask you to read other posts so they don't have to re-write the same god damn simple tasks over and over again. Edited January 2, 2013 by CPD Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 2, 2013 Share Posted January 2, 2013 (edited) If you don't understand what $sql is supposed to hold, then you need to hire someone to fix the script for you, or learn PHP and MySQL. Edited January 2, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
Spanishearl Posted January 2, 2013 Author Share Posted January 2, 2013 (edited) CPD, I am reading it, as well as checking other resources. I believe that what's throwing me off is that the error she speaks about in her post is "mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given", while mine is "mysqli_fetch_array() expects parameter 1 to be resource, boolean given". I fully understand that to you and all the other guru's on here, that this may be the "same god damn simple tasks", but remember that not everyone is a super hero at these things. I asked a question for clarification, and just in case, I posted the full script rather than little parts in case there is something to be seen that without, I'm directing (and being directed) to the wrong information. In the mean time, I am reading up on everything. Thanks for the link to the website. I have no doubt that it'll prove an invaluable resource. EDIT: Thanks Jessica, I most likely will be chatting with a friend that I think knows a little more php than I do, as well as reading up more. Edited January 2, 2013 by Spanishearl Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 2, 2013 Share Posted January 2, 2013 Your error is the mysql version. The post is about mysqli. The practice of checking for errors is exactly the same, except you use the mysql functions instead of the mysqli ones. Quote Link to comment Share on other sites More sharing options...
Spanishearl Posted January 2, 2013 Author Share Posted January 2, 2013 Thanks, Just made the edits for the $sql according to another site: This: $sql = "SELECT * FROM gv_recruitment"; $result = mysql_query($sql) or trigger_error(mysql_error().$sql); Provided this: Notice: No database selectedSELECT * FROM gv_recruitment in /home/content/45/9484341/html/recruiting/recruitment.php on line 59 So, I'm running it down, but I'll run with that info as well. Thanks Jessica 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.