Forum Moderators: coopster

Message Too Old, No Replies

Parse error

         

punk86

4:40 pm on Jan 6, 2010 (gmt 0)

10+ Year Member



I have this login codings.
which it have a parsing error at line 9 which starts from the $query.
can anyone help? i have problems with parsing errors. :(

<?php

session_start ();

$username = $_POST['username'];
$password = $_POST['password'];

$link = mysqli_connect ($HOST,$USERNAME,$PASSWORD,$DB);
$query = "SELECT id,username, FROM StarGazer WHERE username='"$username."'AND password = SHA1 ('".$password."')";$result = mysql_query($link,$query) or die (mysqli_error($link));

if (mysqli_num_rows($result) == 1) {
$row = mysqli_fetch_array($result);
$_SESSION['user_id'] = $row['id'];
$_SESSION['username'] = $row['username'];
$msg = '<p><i>You are logged in as '.$SESSION['username'].'<br/><a href="index.php">Home</p>';

}else {
$msg = <p class ="error"> Sorry, you must enter a valid username and password to log in. <a href ="login.html">Back</a></p>;
}

?>

topr8

5:30 pm on Jan 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you've got a dot missing just before $username

Psychopsia

5:37 pm on Jan 6, 2010 (gmt 0)

10+ Year Member



Hi!

Add "." between username='" and $username.

Should be:

WHERE username='".$username."'

punk86

6:26 pm on Jan 6, 2010 (gmt 0)

10+ Year Member



Hey Topr8 & Psychopsia,
i manage to solve the problem.
Really thanks for your help :)

But now i bump into this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM stars WHERE username=''AND password = SHA1 ('')' at line 1

i did some editing so the latest code is as follow:

<?php
session_start ();
$HOST = 'localhost';
$USERNAME = 'root';
$PASSWORD = '';
$DB = 'c203';
$username = $_POST['username'];
$password = $_POST['password'];

$link = mysqli_connect ($HOST,$USERNAME,$PASSWORD,$DB)or die(mysqli_connect_error());
$sql = "SELECT id,username, FROM stars WHERE username='".$username."'AND password = SHA1 ('".$password."')";
$result = mysqli_query($link,$sql) or die (mysqli_error($link));

if (mysqli_num_rows($result) == 1) {
$row = mysqli_fetch_array($result);
$_SESSION['user_id'] = $row['id'];
$_SESSION['username'] = $row['username'];
$msg = '<p><i>You are logged in as '.$SESSION['username'].'<br/><a href="index.php">Home</p>';

}else {
$msg = '<p class ="error"> Sorry, you must enter a valid username and password to log in. <a href ="login.html">Back</a></p>';
}

?>

I cant get the meaning where its wrong....

rocknbil

8:40 pm on Jan 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're missing a space before your "and".

..... name='".$username."' AND <-- like this.

In the future, when you get mySQL errors, echo the select statements to the screen, they become very obvious.

Psychopsia

8:43 pm on Jan 6, 2010 (gmt 0)

10+ Year Member



Remove comma between 'username' and FROM

Like:

id, username FROM

punk86

4:58 am on Jan 7, 2010 (gmt 0)

10+ Year Member



Rocknbil : How to do the echo-ing you said?

Psychopsia & Rocknbil : Thanks alot for both your help :)

rocknbil

8:12 pm on Jan 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$sql = "SELECT id,username FROM stars WHERE username='".$username."' AND password = SHA1 ('".$password."')";
//echo $sql; // Uncomment the previous if you have problems

punk86

11:52 pm on Jan 7, 2010 (gmt 0)

10+ Year Member



Ok, tks alot Rocknbil :)