BigRob250 BigRob250 - 1 year ago 101
MySQL Question

Match user IP address with sql database entry in PHP

Can't figure out what's wrong with this code, but it is not returning anything for $result:

// check to see if user has already voted
$current_user = $_SERVER['REMOTE_ADDR'];
$select_query = "SELECT * FROM w_poll_counter WHERE user_IP = " . $current_user;
echo $select_query;

$result = mysql_query($select_query);
echo $result;

//user already voted - show results page
header("Location: show_results.php");

The echo statements are for debugging purposes and will be removed once I've (or you've!) solved this problem. echo $select_query is returning that variable how I expect it, but echo $result is returning nothing at all. I'm able to cast multiple votes from my same IP address during testing. This is undesirable!

Please help!


Answer Source

Try quoting properly you query

 $select_query = "SELECT * FROM w_poll_counter WHERE user_IP = '" . $current_user ."';";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download