Jump to content

[SOLVED] MySQL Query not working


Vivid Lust

Recommended Posts

This is my PHP:

 

<?php
@mysql_select_db( "inf_1235727_test", $conn )
or die( "could not select database" );
//stuff
@mysql_query( "SELECT id FROM topics WHERE id = '$_GET['id']'" )
or die( "could not select query" );
?>

Working...

 

The last MySQL Query doesnt work. Help please!

 

Link to comment
https://forums.phpfreaks.com/topic/79449-solved-mysql-query-not-working/
Share on other sites

I see a problem with it, but why are you suppressing the error with the @?

 

Change it to this

mysql_query( "SELECT id FROM topics WHERE id = '{$_GET['id']}'" )
or die(mysql_error());

 

EDIT: Also, it doesn't do you much good if you don't assign it to a variable.

 

$query = mysql_query( "SELECT id FROM topics WHERE id = '{$_GET['id']}'" )
or die(mysql_error());

<?php

$query = mysql_query( "SELECT id FROM topics WHERE id = '{$_GET['id']}'" )
or die(mysql_error());
$row = mysql_fetch_assoc($query);

echo $row['id'];

?>

 

If you expecting more than one result, then use a while loop

 

<?php

$query = mysql_query( "SELECT id FROM topics WHERE id = '{$_GET['id']}'" )
or die(mysql_error());

while ($row = mysql_fetch_assoc($query)){
   echo $row['id'].'<br>';
}

?>

 

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.