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);
$pssword = trim($_POST);
$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 == $usrnam;
header("location: outlace-main.php");
} else {
print "Incorrect!";
}
?>

Recommended Answers

All 5 Replies

I didn't study this long, but I'm pretty sure your issue is this line:

$loggered = mysql_num_rows($oogaboooga) or die(mysql_error())

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.

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
include("conn.php");
@mysql_select_db($forum_db, $conn) or die(mysql_error());
?>
<?php include("style.php"); ?><head>
<script language="javascript" type="text/javascript">
		function closeandrefresh() {
			window.close();
			opener.document.location="<?php print $portal_index; ?>";
		}
		</SCRIPT></head>
<div align="center">
<?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 "<br> You are now logged in.<br><a href='#' onClick='closeandrefresh()'>Close Window</a><br>";
?>
<?php
} else {
$error = "Incorrect username or password!";
}
}
?>
<div align="center">
<?php
if ($error) {
print $error;
}
?>
<?php if (!$_SESSION['user'] AND !$_GET['login']) { ?>
<table width="324" border="0" cellspacing="1" bgcolor="#666666">
<tr>
<td width="341" align="center" valign="top" background="lines.gif" bgcolor="#EAEAEA">(top grphc) Login </td>
</tr>
<tr>
<td align="center" valign="top" bgcolor="#EAEAEA"><form name="form1" method="post" action="?login=true">
UserName: 
<input name="user" type="text" id="user" style="background-color:#666666; border:0; color:#EAEAEA;">
<br>
PassWord: 
<input name="pass" type="password" id="pass"style="background-color:#666666; border:0; color:#EAEAEA;">
<br>
<input type="submit" name="Submit" value="- Login -" style="background-color:#666666; border:0; color:#EAEAEA;">
<br>
</form></td>
</tr>
<tr>
<td align="center" valign="top" background="lines.gif" bgcolor="#EAEAEA">(btm grphc) </td>
</tr>
</table>
<?php } elseif(!$_GET['login'] AND $_SESSION['user']) { print "<br>You are already logged in!<br>"; } ?>
</div>

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.

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.

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.