I am trying to use a mssql Query to retrieve an id from a table row.
This is the code I am trying to use:
$username = $_COOKIE['ID_my_site'];
$sql ="SELECT id FROM users WHERE username = ".$username."";
$query = mssql_query($sql, $conn);
$array = mssql_fetch_assoc($query);
$acc_id=stripslashes($array['id']);
var_dump ($sql);
echo '<script>
alert("'.$acc_id.'");
</script>';
When I use this though, the sql is correct, from what I see using var_dump. But the alert from JavaScript is blank.
How can I get the alert to display the data from the id column?
The id data should be 5.
Thank you for any help, all help is appreciated.
If you +1 my question I will +1 your answer.
I will +1 an answer if I choose it as best answer, regardless if you +1 my question or not!
$usernamevariable is not enclosed in quotes in your query. Also, this is vulnerable to SQL injection - use parameters in your queries.Serial upvoting reversedon me :) -70 rep. Still its a net gain. :) That was a fun ride.