Jump to content

Warning: mysql_fetch_array():


bravo81

Recommended Posts

Hi all, im getting this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/southern/public_html/newshf/admin/admincp.php on line 46

 

 

When trying to put MySQL content onto my site, but it works on another page fine?

 

Heres the code:

 

$welcome=mysql_query("SELECT * FROM welcome WHERE active='1'") or die ('Error, Please contact Dean.');

 

 

<?
while ($row=mysql_fetch_array($welcome)){
echo " ".$row['title']."\r\n<br>".$row['content']."";
}
?>

 

The DB is fine as my index.php works on:

www.southernheavenflorida.com/newshf/

 

 

Any help would be appreciated!

 

Thanks,

 

Dean.

Link to comment
https://forums.phpfreaks.com/topic/103905-warning-mysql_fetch_array/
Share on other sites

What code is between those two parts? Are you sure $welcome isn't getting overwritten? Can we see more code?

 

If you move the query to right before the loop, you shouldn't have a problem:

<?php
$welcome=mysql_query("SELECT * FROM welcome WHERE active='1'") or die ('Error, Please contact Dean.');
while ($row=mysql_fetch_array($welcome)){
  echo " ".$row['title']."\r\n<br>".$row['content']."";
}
?>

Thanks for the replys!

 

It is a numeric field yes, I will remove the ' ' but it worked on index.php

 

Heres the full code:

 

<?php
session_start();
include "../includes/db_connect.php";
include "../includes/functions.php";
$username=$_SESSION['username'];
$message="";

$fetch=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'"));
if ($fetch->userlevel = "0"){
echo "
<div align=center>
<font color=red size=20>
You Have No Rights Here.
</font></div>
";
}if (strip_tags($_GET['op']) == "welcome"){
if(strip_tags($_POST['content'])){
$content=strip_tags($_POST['content']);
$title=strip_tags($_POST['title']);
$check = mysql_num_rows(mysql_query("SELECT content FROM welcome WHERE active='1'"));
$welcome=mysql_query("SELECT * FROM welcome WHERE active='1'") or die ('Error, Please contact Dean.');




if ($check == "0") {
echo "No such content";
}elseif ($check != "0") {

$update = "UPDATE welcome SET content = '$content'". "WHERE active = '1'";

mysql_query($update) or die('Error, query failed');

$message="<strong><font color=green>Done!</font></strong>";


}} ?>
<br><br><br><br><br><br><br><br><br>
<?
echo "<center>$message</center>";
?>
<div align=center>
<br>
Current Content:<br><br>
<?
while ($row=mysql_fetch_array($welcome)){
echo " ".$row['title']."\r\n<br>".$row['content']."";
}
?>
<br><br>
<form name="form1" method="post" action="?op=welcome">

          <strong>Edit the Welcome note</strong> </center><br>
               Title:<br><input name="title" type="text" id="title" value="Welcome"> 
<br><br>
             Content:<br>
             <textarea name="content" cols="40" rows="7" id="content">
		 Enter Your Content Here.</textarea>
        <br><br>
            <input name="Welcome" type="submit" id="Welcome" value="Save">
          
</form>
<p><br>
  <br>
</p>
</body>
</html>

 

 

There is more, but it has nothing to do with the part im having problems with.

Anyone? Really need this fixed..Its stopping the whole website in its tracks.

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/southern/public_html/newshf/admin/admincp.php on line 62

Line 62:
while ($row=mysql_fetch_array($welcome)){

$welcome:
$welcome=mysql_query("SELECT * FROM welcome WHERE active='1'") or die('<div align=center><br><img src=../images/error.jpg width=470 height=28><br><br><br><a href=index.php><img src=../images/lmenu.jpg border=0><img src=../images/home.jpg border=0><img src=../images/rmenu.jpg border=0></a></div>');

It is supposed to display the "title" and "content" field like it does on:

www.southernheavenflorida.com/newshf/index.php

 

but, It just errors instead?

But after submitting the form (Which updates the fields) it works fine, displaying the text inside the fields like on index.php.

 

Why?

Your query is inside of a conditional statement but the while() loop is not. Anytime the code is executed and the conditional statement is not true, the while() loop will produce that error because it is referencing a result set that won't exist.

 

You need to go through your code and make it logically what you intended. It would help if you formatted the source so that it used indentation to show which lines of code belong at the same level in the logic.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.