0

I am building a site which has a user database where the users can log in and sign up. When I test the PHP code for login, it says “parse error” once and invalid { in line 16. What is worng in my code?

<?php

$user = $_REQUEST['user'];
$pass = $_REQUEST['pass'];
$con = mysql_connect("localhost","root","xxxxxxxxxx") or die('Could not connect:'.mysql_error());
$test = mysql_select_db("users",$con)or die("unable to connect");

$result = "SELECT  * FROM users where username='$user' AND password='$pass'";
$alpha = @mysql_query($result,$con);

if($alpha==1)
{
     $expire=time()+60*60*24*30;
     setcookie("id",$row['id'],$expire);
     echo "Logged in. as <b>".$row['username']."</b>";
     $userID = $row['id'];
     header("index map.html")
 }
 else
 {
     echo "<b>Username or password  is wrong</b><br><br>";
     header("index.html")
 }

 mysql_close($con);

 ?>
1
  • 1
    mysql is deprecated use MYSQLi Commented Aug 4, 2014 at 8:44

4 Answers 4

1

There are a couple of issues with your PHP here.

  1. header needs a semi-colon closing it
  2. header needs a location set.. i.e header('location: index.html');

you should replace

header("index map.html")

with

header("location: map.html");

Also you need to replace

header("index.html")

with

header("Location: index.html");
Sign up to request clarification or add additional context in comments.

Comments

0

What the hell ? Where is row comes from ? you didnt call any mysql_fecth_array or some thing related to traverse the result int a row .. at least u code have used

$row = mysql_fetch_result/array($result,$conn);

then use row as my suggestion ...

if($alpha==1)
{
     $expire=time()+60*60*24*30;
     setcookie("id",$row['id'],$expire);
     echo "Logged in. as <b>".$row['username']."</b>";
     $userID = $row['id'];
     header("index map.html")
 }

Comments

-1

first of all your code is very unsecure ! We can easily do some SQL Injection. Try to use at least: mysql_real_escape. (How to use mysql_real_escape_string function in PHP). Also using PDO will be better (in my point of view).

The you forgot the dots in

$result = "SELECT * FROM users WHERE username='.$user.' AND password='.$pass.'"; (line 7)

And you forgot to put the semi-colons and the field keyname (line 21) should be header("location: index.html");

Best regards.

Comments

-2

your header() function is calling incorrectly correct it with

header("location:index-map.html");

2 Comments

what is header('index supposed to do?
there's no header called index.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.