
August 28th, 2003
01:03 PM
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
}
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> </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
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:

August 28th, 2003
01:17 PM
Neverside Newbie
Status: Offline!
Sigh, you should ALWAYS have an error reporting to tell you exactly what is wrong.
<?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
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


August 28th, 2003
05:06 PM
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

August 29th, 2003
12:04 AM
funk masta
Status: Offline!
it is set all the way up the top

August 29th, 2003
01:56 AM
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

August 29th, 2003
09:21 AM
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)

August 29th, 2003
10:33 PM
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

August 30th, 2003
03:15 AM
funk masta
Status: Offline!
what you mean print the query? i did up top on my 1st post

August 30th, 2003
03:20 AM
funk masta
Status: Offline!
mkay i 'escaped' more and i still get the same error
$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> </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
}
?>

August 30th, 2003
04:14 PM
with Mr. Jones
Status: Offline!
Read the stickies.
ERROR:
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