0

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

Edited by wilko1995: n/a

4
Contributors
10
Replies
12
Views
6 Years
Discussion Span
Last Post by karthik_ppts
0

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

Edited by karthik_ppts: n/a

0
<?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

Edited by wilko1995: n/a

0

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!

Edited by Stefano Mtangoo: n/a

0
<?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?

0

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);

?>
0

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

0

Thanks for you help, It works..

:)

Edited by wilko1995: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.