944,161 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 9629
  • PHP RSS
Jul 14th, 2005
0

Php Syntax Error

Expand Post »
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!";
}
?>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nightmare666 is offline Offline
3 posts
since Jul 2005
Jul 14th, 2005
0

Re: Php Syntax Error

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.
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Jul 14th, 2005
0

Re: Php Syntax Error

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"); ?><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>
[/PHP]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nightmare666 is offline Offline
3 posts
since Jul 2005
Jul 15th, 2005
0

Re: Php Syntax Error

When posting code, please use the BB codes to display program code.
http://www.daniweb.com/techtalkforum...ement17-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.
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Jul 16th, 2005
0

Re: Php Syntax Error

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nightmare666 is offline Offline
3 posts
since Jul 2005
Jul 17th, 2005
0

Re: Php Syntax Error

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?
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Learning php
Next Thread in PHP Forum Timeline: Trying to create a login system





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC