Hi all,

<?php
$con = mysql_connect('localhost','root','');

if (!$con)
	{
	die("Could not connect: " . mysql_error());
	}

mysql_select_db('users',$con);

$sql="SELECT username FROM users_info";
$user = $_POST[username]
if($sql != $user)
	{
	die("Error: Username is not in our database! Make sure you check the spelling.");
	}
else
	{
	redirect('/users/' ->$user);
	}
mysql_close($con);

?>

The problem is when i type in a username on my form and it comes to this code, it says:

Parse error: syntax error, unexpected T_IF in ***/login.php on line 13

i know the user i typed in is correct.
Thanks for any help

Recommended Answers

All 10 Replies

where du you execute your query? I think you missed it.
and at the end og your 12th line you missed semicolon.

<?php
$con = mysql_connect('localhost','root','');

if (!$con)
	{
	die("Could not connect: " . mysql_error());
	}

mysql_select_db('users',$con);

$sql= mysql_query("SELECT username FROM user_info");
$user = "$_POST[username]";
if($sql != $user)
	{
	die("Error: Username is not in our database! Make sure you check the spelling.");
	}
else
	{
	redirect('/user/' . $user . '.php');
	}
mysql_close($con);

?>

I updated the code but it comes back with "Error: Username is not in our database! ...". it dies then posts that because APPARENTLY the user im using is not in the data base. HELP :S

1. remove quotes in $user = "$_POST[username]";

$user = $_POST['username'];

2. $sql= mysql_query("SELECT username FROM user_info"); ===> It seems you don't know what you are doing (copy and paste?). Check this and come back if you have any question!

<?php
$con = mysql_connect('localhost','root','');

if (!$con)
	{
	die("Could not connect: " . mysql_error());
	}

mysql_select_db('users',$con);

$sql= mysql_query("SELECT * FROM users_info");
$user = $_POST['username'];
if($sql['username'] != $user)
	{
	die("Error: Username is not in our database! Make sure you check the spelling.");
	}
else
	{
	redirect('/user/' . $user . '.php');
	}
mysql_close($con);

?>

Is that how its meant to be?
It executes 'die' when the username is correct... HELP?

I have changed select query.
Check this.

<?php
$con = mysql_connect('localhost','root','');

if (!$con)
{
	die("Could not connect: " . mysql_error());
}

mysql_select_db('users',$con);
$user = $_POST['username'];
$result= mysql_query("SELECT * FROM users_info WHERE username='".$user."'");
if (mysql_num_rows($result) == 0)
{
	die("Error: Username is not in our database! Make sure you check the spelling.");
}
else
{
	redirect('/user/' . $user . '.php');
}
mysql_close($con);

?>

try this

<?php
    $con = mysql_connect('localhost','root','');
     
    if (!$con)
    {
    die("Could not connect: " . mysql_error());
    }
     
    mysql_select_db('users',$con);
     
    $sql= mysql_query("SELECT * FROM users_info where username='".$_POST['username']."'");
    $nor = mysql_num_rows($sql);
    if($nor > 0)
    {
    	redirect('/user/' . $user . '.php');
    }
    else
    {
    	die("Error: Username is not in our database! Make sure you check the spelling.");
    }
    mysql_close($con);
     
?>

and you need to practice more... refer this http://www.w3schools.com/php/default.asp

Vibha, I haven't see your post. I think we posted in the same time.

NP karthik :)

Thanks for you help, It works..

:)

ok.. Mark as solved if your problem solved..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.