Jump to content

!mysql_query not working


The14thGOD

Recommended Posts

I can't seem to find the mistake in this code:

 

<?php
$com_query = "SELECT * FROM comments WHERE picID='$_GET[id]' AND status='enabled' ";
					$com_result = mysql_query($com_query);
					if(!mysql_query($com_query)) {
							echo "<p class=\"nocomments\">There are no comments yet.</p>";
					}?>

 

It's not echoing hi, it appears to not be getting inside that if statement.

 

That reads if no mysql_query (meaning query returned nothing) then do this right? or have i been gone from php that long...hah

 

Thanks in advance

 

Justin

Link to comment
https://forums.phpfreaks.com/topic/98304-mysql_query-not-working/
Share on other sites

Try this:

 

<?php
$com_query = "SELECT * FROM `comments` WHERE `picID`='".mysql_real_escape_string($_GET['id'])."' AND `status`='enabled'";
$com_result = mysql_query($com_query)
  or die("Query error: ".mysql_error());
if(mysql_num_rows($com_result)) {
  while($row = mysql_fetch_array($com_result)){
    //Print Comments Here
  }
}else{
  echo '<p class="nocomments">There are no comments yet.</p>';
}
?>

Ah, alright. I swear I've used that same code before though... ha. Oh well.

 

Conker87, I tried that already, I noticed that wasn't right and changed it but for the reason Boom.dk said it didn't work.

 

Thanks again,

 

I'd hit the topic solved button but I can never find the damn thing. I found it once...haha

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.