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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.