954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Php Syntax Error

Ok, i have a login process page... There is a problem though, whenever the user/pass is correct, it will do an action, but with the } else { or } elseif{ the following actions never take place and its just a blank page if the user/pass is incorrect... whats wrong with my syntax?

---------------------------------------------------------------------------
------------------
<?php session_start();?>
<?php
$usrnam = trim($_POST['usernamer']);
$pssword = trim($_POST['passingword']);
$conn = mysql_connect("localhost", "brandon7", "brandon") or die("Unable to connect!");
mysql_select_db("brandon7", $conn) or die("Unable to connect to database!");

$loginger = "SELECT * FROM outlace_users WHERE user = '$usr' AND pass = '$pss'";
$oogaboooga = mysql_query($loginger) or die(mysql_error());
$loggered = mysql_num_rows($oogaboooga) or die(mysql_error());
if ($loggered == 1) {
$_SESSION['username'] == $usrnam;
header("location: outlace-main.php");
} else {
print "Incorrect!";
}
?>

nightmare666
Newbie Poster
3 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

I didn't study this long, but I'm pretty sure your issue is this line:
[php]
$loggered = mysql_num_rows($oogaboooga) or die(mysql_error())
[/php]
You see, if $loggered is zero, your die() will happen, but since there isn't actually a mysql error, you'll see nothing. Just remove the die() part--you don't need it there.

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

Ooops, I got the wrong script, I already figured that out already. It is this login script, after I enter a correct user and password, it still says that it is incorrect.

[PHP]
<?php
include("conn.php");
@mysql_select_db($forum_db, $conn) or die(mysql_error());
?>
<?php include("style.php"); ?>

<?php
if ($_GET['login']) {
$user = $_POST['user'];
$pass = md5($_POST['pass']);
$sql = mysql_query("SELECT * FROM ".$forum_table_prefix."users WHERE username = '$user' AND user_password = '$pass'", $conn) or die(mysql_error());
if (mysql_num_rows($sql) == 1) {
$error = false;
$_SESSION['user'] = $user;
setcookie("user", $user, 0, "/", "chrome-arrow.com");
print "
You are now logged in.
Close Window
";
?>
<?php
} else {
$error = "Incorrect username or password!";
}
}
?>

<?php
if ($error) {
print $error;
}
?>
<?php if (!$_SESSION['user'] AND !$_GET['login']) { ?>
(top grphc) Login

UserName:


PassWord:



(btm grphc)

<?php } elseif(!$_GET['login'] AND $_SESSION['user']) { print "
You are already logged in!
"; } ?>

[/PHP]

nightmare666
Newbie Poster
3 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

When posting code, please use the BB codes to display program code.
http://www.daniweb.com/techtalkforums/announcement17-4.html

To debug your code, I recommend liberally using echo() statements to check the value of variables and the state of your various conditions. Both for your own troubleshooting, and for posting your question to a forum, you should strip your code down to the bare essentials to reproduce the problem. Many times, this exercise will help you spot the problem yourself anyway. The code you posted has a lot of extraneous stuff that has nothing to do with the problem thus making it tedious to help you.

For an example of how to handle sessions and a good login.php example, check out my PHP Session class at http://www.troywolf.com/articles .

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

I have no knowledge what so ever at PHP. My friend made this for my site. I am looking for somebody to correct or help me correct this script.

nightmare666
Newbie Poster
3 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

Programmer's forums are typically for programmers. People on their journey to becoming a skilled programmer post questions in the forums as they run into things they do not understand. We help each other out--it's give and take.

On the contrary, non-programmers just looking for someone to fix some code or provide some functionality should hire somebody. It does not make a lot of sense for people to spend time responding to your question since, as a non-programmer, you most likely will not know how to implement any answers you receive.

To find a programmer who is able and willing to be paid to develop a solution for you, check out Daniweb's IT Water Cooler / Web Scripting Job Offers forum.
http://www.daniweb.com/techtalkforums/forum94.html


Since you have a friend who was able to code what you have so far, why not have that friend help you?

Troy
Posting Whiz
362 posts since Jun 2005
Reputation Points: 36
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You