Database table name is 'users'... Database set up as MySQL 4.0... User enters their info on a different page in a form and puts it into the db (this part works fine)... On the My Account page when I'm trying to echo out the details that they entered into the form, I get the "couldn't execute query" error. I have no idea what the problem is. Here is my code: <?php session_start(); if (!isset($_SESSION['user'])) { die ("Access Denied"); } //Database Code $host = "localhost"; //Host Name $dbuser = "**********"; //User Name $password = "******"; //Password $dbname = "********"; //Database Name $cxn = mysql_connect("$host","$dbuser","$password","$dbname") or die ("Couldn't connect to server."); $useit = $_SESSION['user']; $query = "SELECT * FROM users WHERE user_email=$useit"; $result = mysql_query($cxn,$query) or die ("Couldn't execute query"); $row = mysql_fetch_assoc($result); extract($row); ?> <h2>My Account </h2> <?php if (isset($_SESSION['user'])) { ?> <p>Logged as <?php echo $_SESSION['user']; ?> | <a href="settings.php">Settings</a> | <a href="logout.php">Logout</a> </p> <p>Country: <?php echo $country; ?> </p> <?php } ?> Anyone that could give me any tips would be greatly appreciated. Thanks.
Hi, I think that you need to change this lines $cxn = mysql_connect("$host","$dbuser","$password","$dbname") or die ("Couldn't connect to server."); Code (markup): to $cxn = mysql_connect ($host, $dbuser, $password) or die .('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ($dbname); Code (markup):
Yeh you need to select a database and also shouldn't $result = mysql_query($cxn,$query) be $result = mysql_query($query,$cxn)
$cxn = mysql_connect("$host","$dbuser","$password","$dbname") or die ("Couldn't connect to server."); PHP: change the cxn to that
$cxn = mysql_connect($host,$dbuser,$password); or die ("Couldn't connect to server."); mysql_select_db($dbname );