Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

72 users online



Wrong code placement or careless error?

Wrong code placement or careless error?

Currently viewing this thread: 1 (0 members and 1 guests)


Page 1 out of 2
FunkyDwarf

FunkyDwarf

funk masta
Status: Offline!

Wrong code placement or careless error?

Hey guys,

Im still workin on my cpanel script and im up to the pm system, and all the complicated crap works, but the simple things displays the stupidest errors:

for this code:

PHP:

<?php

}
 else if(
$section == pminbox) { 
$section trim($_GET['section']); 
echo 
'<table width="400" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
      <center><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Inbox<br>
        <br>
        <img src="bar.jpg" width="300" height="1" border="1"> </font></center>
    </td>
  </tr>
</table>
<form name="deletemsg" method="post" action="usercp.php?pminbox">
  <br>
  <table width=400 border=0 >
    <tr> 
      <td width="100"> 
        <center><font size="1" face="Verdana, Arial, Helvetica, sans-serif">From</font></center>
      </td>
      <td width="100"> 
        <center><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Title</font></center>
      </td>
      <td width="100"> 
        <center><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Date</font></center>
      </td>
      <td> 
        <center><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Delete</font></center>
      </td>
    </tr>
  </table>'
;
$user =  $_COOKIE['cname'];
mysql_connect("localhost","soaxorg_funkydwa","pwd"); 
mysql_select_db("soaxorg_articles"); 
$inbox mysql_query("SELECT * FROM messages WHERE to = '$user'"); 
while(
$in=mysql_fetch_array($inbox)) 
{     
    
$from=$in["title"]; 
       
$to=$in["to"]; 
   
$message=$in["message"]; 
      
$id=$in["id"]; 
      
      echo 
"<table width=400 border=0 >
    <tr> 
      <td> 
        <div align=center>$from</center>
      </td>
      <td> 
        <center>$title</center>
      </td>
      <td> 
        <center>$date</center>
      </td>
      <td> 
        <center><input type='checkbox' name='.$id.' value='checkbox'></center>
      </td>
    </tr>
  </table>
  "
;
         }
  
  
  
 echo 
'<p>&nbsp;</p><table width="400" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td> 
        <div align="right">
          <input type="submit" name="Submit" value="Delete Selected">
        </center>
      </td>
    </tr>
  </table>
  <br>
  <table width=400 border=0 >
    <tr>
      <td>
        <center><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><img src="bar.jpg" width="300" height="1" border="1"></font></center>
      </td>
    </tr>
  </table>
</form>'
;

}
?>

I get this big fat error

Code:


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/soaxorg/public_html/usercp.php on line 243

it displays all the tables except the one thats in that while loop :S

Thanks
-Funky
::classic:

Motorspin

Motorspin

Neverside Newbie
Status: Offline!

Sigh, you should ALWAYS have an error reporting to tell you exactly what is wrong.

PHP:

<?php

$inbox 
mysql_query("SELECT * FROM messages WHERE to = '$user'") or die('Error in query: ' $inbox '. ' mysql_error());

?>


Now if you get an error you know why.

On if/'else statements and html content, the program logic and html stuff should always be somewhat apart (hence templating) but in this case, even to make it the slightest bit easier... do things like this

PHP:


<?php
if(isset($i))
{
  
?>
  // some html stuff
  // blah blah
  <?php
}
else
{
  
?>
  // again....
  <?php
}
?>


It's better then trying to escape every character you have in there, and it's often a 'trick' that often people don't know about. You'll find it a lot easier.

The only reason I can think of of why you are getting an error is your query is incorrect.

___________________

Travis Farrell
http://motorspin.com/stuff/images/avasig/m_enterprisesig.gif

killa_kid

killa_kid

Status: Offline!

You should also check for sure that $user is set. There could have been a problem and you want to make sure you get everything from the cookie

___________________

ProBB - The Best Thing to Happen to BBs Since YaBB

FunkyDwarf

FunkyDwarf

funk masta
Status: Offline!

it is set all the way up the top

killa_kid

killa_kid

Status: Offline!

are you sure it is actually getting everything from the cookies tho.

try outputting the query in an echo and see if that spot is blank or filled in

___________________

ProBB - The Best Thing to Happen to BBs Since YaBB

FunkyDwarf

FunkyDwarf

funk masta
Status: Offline!

used the error thing and the cookie does work because look it prints :

Error in query: . You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'to = 'FunkyDwarf'' at line 1

so it is getting the cookie (i also echoed it to check)

Phil

Phil

with Mr. Jones
Status: Offline!

print the query, lets see it.

escpae in and out of php for more readability and less parse errors

___________________

http://www.philbrodeur.com - Expert PHP Development and Tutorials

FunkyDwarf

FunkyDwarf

funk masta
Status: Offline!

what you mean print the query? i did up top on my 1st post

FunkyDwarf

FunkyDwarf

funk masta
Status: Offline!

mkay i 'escaped' more and i still get the same error

PHP:


$user = $_COOKIE['cname'];
mysql_connect("localhost","soaxorg_funkydwa","pwd"); 
mysql_select_db("soaxorg_articles"); 
$inbox = mysql_query("SELECT * FROM messages WHERE to = '$user'") or die('Error in query: ' . $inbox . '. ' . mysql_error());

while($in=mysql_fetch_array($inbox)) 
{     
    $from=$in["title"]; 
       $to=$in["to"]; 
   $message=$in["message"]; 
      $id=$in["id"]; 
      
?> <table width=400 border=0 >
    <tr> 
      <td> 
        <div align=center>$from</center>
      </td>
      <td> 
        <center>$title</center>
      </td>
      <td> 
        <center>$date</center>
      </td>
      <td> 
        <center><input type='checkbox' name='.$id.' value='checkbox'></center>
      </td>
    </tr>
  </table>
<?php
         
}
  
  
?>
  
<p>&nbsp;</p><table width="400" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td> 
        <div align="right">
          <input type="submit" name="Submit" value="Delete Selected">
        </center>
      </td>
    </tr>
  </table>
  <br>
  <table width=400 border=0 >
    <tr>
      <td>
        <center><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><img src="bar.jpg" width="300" height="1" border="1"></font></center>
      </td>
    </tr>
  </table>
</form>

<?php
}
?> 

Phil

Phil

with Mr. Jones
Status: Offline!

Read the stickies.

Quote:


ERROR:

Quote:


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site228/fst/var/www/html/adminrate/p.php on line 9

This means the result your trying to give it to a) doesn't exist b-c) has 0 rows. This could be either because it worked and selected no querys pr because the script never executed. Again, remember
always mysql_query() or die(mysql_error());

___________________

http://www.philbrodeur.com - Expert PHP Development and Tutorials

Page 1 out of 2
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0116 seconds.