bravo81 Posted May 27, 2008 Share Posted May 27, 2008 Hi all, I have the following code: $querywelcome=mysql_query("SELECT * FROM welcome WHERE active='1'"); while ($row=mysql_fetch_array($querywelcome)){ echo " ".$row['title']."\r\n<br>".$row['content'].""; } That works fine, displaying the text inside the fields chosen. I have set up and editing panel for the Admin, It uses the exact same code to show the Admin what is there at the moment. But errors? Invalid MySQL Resource I belive (I have removed the code now) But then I am using a text box to change it, which works fine..after submiting the form the error is gone and shows the text? Help! Regards, Dean. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 27, 2008 Share Posted May 27, 2008 that error can mean several things, typically that the query failed or there is no connection to the database. need to see the code that is causing the error. always use or die or mysql_query(): $result = mysql_query($sql) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
bravo81 Posted May 27, 2008 Author Share Posted May 27, 2008 Ok, Index.php: <? session_start(); include './includes/db_connect.php'; include './includes/counter.php'; include './includes/functions.php'; $username=$_SESSION['username']; $query2=mysql_query("SELECT * FROM users WHERE username='$username' LIMIT 1"); $fetch2=mysql_fetch_object($query2); $querywelcome=mysql_query("SELECT * FROM welcome WHERE active='1'"); ?> <? while ($row=mysql_fetch_array($querywelcome)){ echo " ".$row['title']."\r\n<br>".$row['content'].""; } ?> Works fine. admin.php: <?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> "; exit(); } ?> <? 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 * FROM welcome WHERE active='1'")); if ($check == "0") { echo "No such content"; }elseif ($check != "0") { $update = "UPDATE welcome SET content = '$content'". "WHERE active = '1'"; mysql_query($update) 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>'); $message="<img src='../images/savecomplete.jpg' width='154' height='28' alt='Your content has been saved'"; }} echo "<br><br><center>$message</center>"; ?> <div align="center"> <br><br> <form name="form1" method="post" action="?op=welcome"><br> Title:<br><input name="title" type="text" id="title" value='Enter your title here.'> <br><br> Content:<br> <textarea name="content" cols="40" rows="7" id="content">Enter your content here.</textarea> <br><br> <input type="image" src="../images/save.jpg" alt="Click here to Save your content." name="Welcome"> </form> <p><br> <br> </p> </body> </html> <? }else{ ?> You can not enter this page directly,<br> Please go back. <? } ?> <p> <? logincheck(); ?> Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 27, 2008 Share Posted May 27, 2008 check for errors $sql = "SELECT * FROM users WHERE username='$username'"; $result = mysql_query($sql) or die(mysql_error()); $fetch=mysql_fetch_object($result); Quote Link to comment Share on other sites More sharing options...
bravo81 Posted May 27, 2008 Author Share Posted May 27, 2008 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/southern/public_html/newshf/admin/admincp.php on line 65 Line 65 is: while ($row=mysql_fetch_array($info)){ from: while ($row=mysql_fetch_array($info)){ echo " ".$row['title']."\r\n<br>".$row['content'].""; } Your code I entered: $sql = "SELECT * FROM welcome WHERE active='1'"; $result = mysql_query($sql) or die(mysql_error()); $info=mysql_fetch_object($result); Any ideas? This is annoying. 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.