Jump to content

PHP $row - Works on one page but not the other?


bravo81

Recommended Posts

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.

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();
?>

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.

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.