Page 1 of 1
Login Code Need Extra Help...
Posted: Sun Dec 28, 2008 12:41 pm
by sw33tkilla
Here Is my Code, Im not sure what is wrong..
This is the error i get...
Parse error: parse error, unexpected T_STRING in /home/login.php on line 18
This Is Line 18 Itselft
$query = “select * from users where username=’$username’ and password=’$password’”;
My Full Code Is
<?php
//Database Information
$dbhost = "my database";
$dbname = "my username";
$dbuser = "my username";
$dbpass = "Passwoooord";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);
$query = “select * from users where username=’$username’ and password=’$password’”;
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
$error = “Bad Login”;
include “login.html”;
} else {
$_SESSION[‘username’] = “$username”;
include “memberspage.php”;
}
?>
Re: Login Code Need Extra Help...
Posted: Sun Dec 28, 2008 1:34 pm
by jobed
u should write
$query = "select * from users where username='$username' and password='$password' ";
in case of
$query = “select * from users where username=’$username’ and password=’$password’”;
( " ) and ( “ ) is different.php does not know “.
Re: Login Code Need Extra Help...
Posted: Sun Dec 28, 2008 1:38 pm
by sw33tkilla
yea thank you i figured that out after i read some tuts. But now im getting this error
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/n/o/r/norwalkcs/html/data/login.php on line 27
Line 27
$_SESSION['username'] = "$username";
<?php
//Database Information
$dbhost = "asgasg";
$dbname = "ss";
$dbuser = "ss";
$dbpass = "Frasgsgaasgon1gsagasg";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);
$query = "select * from users where username='$username' and password='$password"'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
include "login.html";
} else {
$_SESSION['username'] = "$username";
include "memberspage.php";
}
?>
Re: Login Code Need Extra Help...
Posted: Sun Dec 28, 2008 1:48 pm
by jobed
best of luck

Re: Login Code Need Extra Help...
Posted: Sun Dec 28, 2008 1:52 pm
by sw33tkilla
thanks for the help lol.. ill figure it out hopefully
Re: Login Code Need Extra Help...
Posted: Sun Dec 28, 2008 2:23 pm
by watson516
You only use " " with text. If you want to assign a variable to another variable, don't use the " ".
Code: Select all
<?php
$_SESSION['username']=$username;
?>
Oh, and use [ code=php] [ /code] for php.
Re: Login Code Need Extra Help...
Posted: Sun Dec 28, 2008 4:41 pm
by sw33tkilla
I still get same error i already replaced what u said but i still get
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/n/o/r/norwalkcs/html/data/login.php on line 27
Here is complete Code
Code: Select all
<?php
//Database Information
$dbhost = "st";
$dbname = "sgas";
$dbuser = "swsag";
$dbpass = "gasg";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);
$query = "select * from users where username='$username' and password='$password"'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
include "login.html";
} else {[color=#BF0000]
$_SESSION['username']=$username;[/color]
include "memberspage.php";
}
?>
Re: Login Code Need Extra Help...
Posted: Sun Dec 28, 2008 7:24 pm
by watson516
sw33tkilla wrote:I still get same error i already replaced what u said but i still get
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/content/n/o/r/norwalkcs/html/data/login.php on line 27
Here is complete Code
Code: Select all
<?php
//Database Information
$dbhost = "st";
$dbname = "sgas";
$dbuser = "swsag";
$dbpass = "gasg";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);
$query = "select * from users where username='$username' and password='$password"'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
include "login.html";
} else {[color=#BF0000]
$_SESSION['username']=$username;[/color]
include "memberspage.php";
}
?>
As you can see from the highlighting in the code box in your previous post, you have one too many " on L19.
That may or may not be the reason for that error, I'm not sure.
One last thing...
You should probably not put POST data straight into mysql statement. You should put it through
htmlentities or something similar to prevent bad people doing bad things.
Re: Login Code Need Extra Help...
Posted: Sun Dec 28, 2008 9:00 pm
by sw33tkilla
alright nothing fixed yet still same error.!!
i dont c anything wrong wit it...
http://norwalkcs.com/data/login.html
Enter anything youll see the error and this is my code its fine
Code: Select all
<?php
//Database Information
$dbhost = "s.net";
$dbname = "s12124w";
$dbuser = "112211";
$dbpass = "1o1o2";
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
session_start();
$username = $_POST['username'];
$password = md5($_POST['password']);
$query = "select * from users where username='$username' and password='$password"'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
$error = "Bad Login";
include "login.html";
} else {
$_SESSION['username']=$username;
include "memberspage.php";
}
?>
Re: Login Code Need Extra Help...
Posted: Sun Dec 28, 2008 11:46 pm
by watson516
I registered, logged in, logged out without any errors.
Re: Login Code Need Extra Help...
Posted: Mon Dec 29, 2008 12:05 am
by sw33tkilla
yea i fixed it i had to rewrite the whole code...
Now im trying to figure out how to be able to edit the profile..
any ideas please reply =)