Login Code Need Extra Help...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sw33tkilla
Forum Newbie
Posts: 6
Joined: Sun Dec 28, 2008 12:37 pm

Login Code Need Extra Help...

Post 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”;
}

?>
jobed
Forum Newbie
Posts: 2
Joined: Sun Dec 28, 2008 1:24 pm

Re: Login Code Need Extra Help...

Post 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 “.
sw33tkilla
Forum Newbie
Posts: 6
Joined: Sun Dec 28, 2008 12:37 pm

Re: Login Code Need Extra Help...

Post 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";
}

?>
jobed
Forum Newbie
Posts: 2
Joined: Sun Dec 28, 2008 1:24 pm

Re: Login Code Need Extra Help...

Post by jobed »

best of luck :wink:
sw33tkilla
Forum Newbie
Posts: 6
Joined: Sun Dec 28, 2008 12:37 pm

Re: Login Code Need Extra Help...

Post by sw33tkilla »

thanks for the help lol.. ill figure it out hopefully
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Login Code Need Extra Help...

Post 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.
sw33tkilla
Forum Newbie
Posts: 6
Joined: Sun Dec 28, 2008 12:37 pm

Re: Login Code Need Extra Help...

Post 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";
}
 
?>
 
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Login Code Need Extra Help...

Post 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.
sw33tkilla
Forum Newbie
Posts: 6
Joined: Sun Dec 28, 2008 12:37 pm

Re: Login Code Need Extra Help...

Post 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";
 }
  
 ?>
 
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Login Code Need Extra Help...

Post by watson516 »

I registered, logged in, logged out without any errors.
sw33tkilla
Forum Newbie
Posts: 6
Joined: Sun Dec 28, 2008 12:37 pm

Re: Login Code Need Extra Help...

Post 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 =)
Post Reply