Jump to content

[SOLVED] What's wrong with this select statement?


chrisuk

Recommended Posts

I must be doing something really silly here, I am trying to get the players ID from their name based on selection from a dropdown menu:

 

$winner = $_POST['winner'];

$sql = "SELECT player_id FROM players WHERE player = '$winner'";

$result = mysql_query($sql)or die("error");
echo $sql;
echo $result;
$player_id = $player_id;
echo $player_id;

 

The output of the echos is:

 

SELECT player_id FROM players WHERE player = 'Joe "Nickname" Bloggs'id #3

 

So the select statement is picking up the name, but why is it not getting the player id?

 

I thought using the quotes would be athe probem so tried just "bloggs" - same problem

 

Thanks in advance..

mysql_query() just returns a resource id which points to your resultset.  you need to use an extraction function such as mysql_fetch_assoc() on that resource to retrieve the records.

 

have a look at a basic php/mysql tutorial to learn the difference and the different types of extraction functions that exist.  i believe there's one on the main phpfreaks website even.

try this:

 

$winner = $_POST['winner'];

$sql = "SELECT player_id FROM players WHERE player = '$winner'";

$result = mysql_query($sql)or die("error");

$player_details = mysql_fetch_assoc($result);

$player_id = $player_details['player_id'];

echo $player_id;

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.