Hello.
I'm having a problem with a query I'm trying to run against a database.
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #3' at line 1"
Here is the code:
<?php
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
header ("Location: login.php");
}
//Connect and select database
mysql_connect("192.168.254.000", "user", "pass") or die(mysql_error());
mysql_select_db("tutorial") or die(mysql_error());
$username = $_SESSION['username'];
echo $username;
$query = mysql_query("SELECT * FROM profiles WHERE user = $username" );
mysql_query($query) or die(mysql_error());
while ($result = mysql_fetch_array($query)){
?>
<table>
<tr><td><b><?php echo $result['email']; ?> </b></td></tr>
</table>
<?php
}
?>
When I echo $username; it has the correct info for that variable. When I put single quotes around $username in the $query string, it gives me this error. When I take the quotes away, it gives me "Query was empty" even though there is a row in the database that matches. When I take the select query and run it in the mysql query browser, it lists the expected output. Can someone here spot what I am doing wrong? Thanks for any help!