Jump to content

Mysql_Fetch_Array() Expects Parameter 1 To Be Resource


Spanishearl

Recommended Posts

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>";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Spanishearl
Link to comment
Share on other sites

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 by CPD
Link to comment
Share on other sites

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 by Spanishearl
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.