bravo81 Posted May 2, 2008 Share Posted May 2, 2008 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 More sharing options...
rhodesa Posted May 2, 2008 Share Posted May 2, 2008 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'].""; } ?> Link to comment https://forums.phpfreaks.com/topic/103905-warning-mysql_fetch_array/#findComment-531942 Share on other sites More sharing options...
revraz Posted May 2, 2008 Share Posted May 2, 2008 If you use mysql_error after your query, then you'll probably see the sql error. Is Active a Numeric field? Try removing the single quotes around '1' Link to comment https://forums.phpfreaks.com/topic/103905-warning-mysql_fetch_array/#findComment-531957 Share on other sites More sharing options...
bravo81 Posted May 3, 2008 Author Share Posted May 3, 2008 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. Link to comment https://forums.phpfreaks.com/topic/103905-warning-mysql_fetch_array/#findComment-532324 Share on other sites More sharing options...
bravo81 Posted May 3, 2008 Author Share Posted May 3, 2008 Ok, im still getting the error. But after submiting the form it displays correctly. What in the world? Link to comment https://forums.phpfreaks.com/topic/103905-warning-mysql_fetch_array/#findComment-532339 Share on other sites More sharing options...
bravo81 Posted May 3, 2008 Author Share Posted May 3, 2008 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>'); Link to comment https://forums.phpfreaks.com/topic/103905-warning-mysql_fetch_array/#findComment-532359 Share on other sites More sharing options...
BrianM Posted May 3, 2008 Share Posted May 3, 2008 What sort of problem are you having with it? Link to comment https://forums.phpfreaks.com/topic/103905-warning-mysql_fetch_array/#findComment-532365 Share on other sites More sharing options...
bravo81 Posted May 3, 2008 Author Share Posted May 3, 2008 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? Link to comment https://forums.phpfreaks.com/topic/103905-warning-mysql_fetch_array/#findComment-532367 Share on other sites More sharing options...
PFMaBiSmAd Posted May 3, 2008 Share Posted May 3, 2008 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. Link to comment https://forums.phpfreaks.com/topic/103905-warning-mysql_fetch_array/#findComment-532406 Share on other sites More sharing options...
bravo81 Posted May 5, 2008 Author Share Posted May 5, 2008 That really confused me, but I think I understand. I will try that, thanks. Link to comment https://forums.phpfreaks.com/topic/103905-warning-mysql_fetch_array/#findComment-533810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.