Jump to content


PHP MySQL Error


6 replies to this topic

#1 bfva

    Young Padawan

  • Members
  • Pip
  • 42 posts

Posted 11 May 2007 - 03:15 PM

I have been trying to fix this script but it gives me a mysql error.

mysql array error on line 16

here is the line

$nummessages = mysql_num_rows($get); 

here is my code

  $get = mysql_query("SELECT * FROM pmessagesout WHERE from = '$logged[username]'"); 
echo(" 
<center>
<table bgcolor=\"#dddddd\" border=\"0\" width=\"100%\" cellspacing=\"0\"> 
<tr> 
<td align=\"center\">Subject</td> 
<td align=\"center\" width=\"125\">Sent To</td> 
<td align=\"center\" width=\"97\">Date</td> 
<td width=\"25\">Delete</td>
</tr> 
</table> 
</center>
"); 
$nummessages = mysql_num_rows($get); 
if ($nummessages == 0) 
{ 
echo ("You have sent 0 messages!"); 
} 
else 
{ 
echo("<table border=\"0\" width=\"100%\" cellspacing=\"1\">"); 
while ($messages = mysql_fetch_array($get)) 
{ 
//the above lines gets all the messages sent to you, and displays them with the newest ones on top 
echo (" 
<tr> 
<td><a href=\"?page=view&msgid=$messages[id]\">"); 
echo ("$messages[title]</a></td> 
<td width=\"125\">$messages[touser]</td> 
<td width=\"97\">$messages[date]</td> 
<td width=\"25\"><a href=\"?page=delete2&msgid=$messages[id]\">Delete</a></td> 
</tr>"); 
echo ("</table>"); 
}
}
  

Thanks for your help

#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 11 May 2007 - 03:33 PM

This drives me crazy, seriously...

Whenever you use a MySQL query, ALWAYS USE mysql_error()!!!

Simple as this.
$query = mysql_query($sql) or die(mysql_error());

That will give you the error MySQL is sending back, and will allow you to work from there easily.

#3 Case

    Young Padawan

  • Members
  • Pip
  • 207 posts
  • Gender:Male
  • Location:Birmingham, UK

Posted 11 May 2007 - 05:22 PM

My first guess would be that the $get query is failing and so when you try and mysql_num_rows it isnt a valid datatype and is failing but as Demonslay pointed out, you really need the full error reporting on to find out.

#4 bfva

    Young Padawan

  • Members
  • Pip
  • 42 posts

Posted 12 May 2007 - 06:30 AM

[quote name='Demonslay' post='215652' date='May 11 2007, 03:33 PM']This drives me crazy, seriously...

Whenever you use a MySQL query, ALWAYS USE mysql_error()!!!

Simple as this.


#5 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 12 May 2007 - 06:36 AM

Well lets sort out the syntax etc, although technically the line should work.

$get = mysql_query("SELECT * FROM `pmessagesout` WHERE `from` = '{$logged['username']}'") or die(mysql_error());

Matt

#6 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 12 May 2007 - 08:46 AM

Just what I expected. FROM is a keyword in SQL, in the command SELECT FROM, so of course it will give a parse error. Always use ` marks around columns and tables to avoid conflicts.

#7 bfva

    Young Padawan

  • Members
  • Pip
  • 42 posts

Posted 13 May 2007 - 05:08 AM

View PostMatthew., on May 12 2007, 06:36 AM, said:

Well lets sort out the syntax etc, although technically the line should work.

$get = mysql_query("SELECT * FROM `pmessagesout` WHERE `from` = '{$logged['username']}'") or die(mysql_error());

Matt

Thanks mate, it worked perfectly.

View PostDemonslay, on May 12 2007, 08:46 AM, said:

Just what I expected. FROM is a keyword in SQL, in the command SELECT FROM, so of course it will give a parse error. Always use ` marks around columns and tables to avoid conflicts.

Next time, i'm working with mysql queries i'll remember to use marks around the columns and tables.

Thanks for the tip.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users