Question: I have no idea what's going on. I usually have simple sign in pages like this done very quickly but this one isn't working and I cannot spot the error.

```
<?php
$con=mysql_connect("db_server","db_user","db_pass","db");
if (!$con)
{
   echo "Failed to connect to MySQL: " . mysql_error();
}
$username = $_GET['username'];
$password = $_GET['password'];

$query="SELECT username FROM users ";
//$query.="WHERE `username`=".$username;
//$query.=" AND `password`=".$password;
echo "query=".$query."<br/>";
$result = mysql_query($query, $con);
echo "result=".$result."<br/>";
if($result){
    $row = mysql_fetch_assoc($result);
    $data = $row['username'];
    echo "data=".$data;
}else{
    echo "something went wrong:".mysql_error();
}
mysql_close($con);
?>

```

im using `mysql_*` instead of `mysqli_*` as the server im running it on is 5.2; not sure if that is relevant but I was getting an unrecognized function error originally.

There is only one entry in the database. As I said, I use the regular SQL code through phpmyadmin and i get the results i need.

Also not sure if relevant. I'm echoing $result and nothing comes out. Isnt it supposed to echo **"false"**?

Answer: 
You have a major error in your logic, for one. If there is an error connecting to MySQL, you print the error, but yet proceed to query the broken connection - you are also not selecting a database.

Also, this approach is for PHP4. Unless you are stuck in PHP4 on this project, moving into the PHP5 world would be a good idea.

I recommend looking into PDO:
<http://www.php.net/manual/en/book.pdo.php>

As for not getting errors, check your error\_reporting and display\_errors settings in your .ini
Try this one.

```
<?php
$con=mysql_connect("db_server","db_user","db_pass");
mysql_select_db("db");

if (!$con)
{
   echo "Failed to connect to MySQL: " . mysql_error();
}
$username = $_GET['username'];
$password = $_GET['password'];

$query=mysql_query("SELECT username FROM users");
if($query){
    $row = mysql_fetch_assoc($query);
    $data = $row['username'];
    echo $data;
}else{
    echo "something went wrong:".mysql_error();
}
mysql_close($con);
?>

```