Php Syntax Error

Reply

Join Date: Jul 2005
Posts: 3
Reputation: nightmare666 is an unknown quantity at this point 
Solved Threads: 0
nightmare666 nightmare666 is offline Offline
Newbie Poster

Php Syntax Error

 
0
  #1
Jul 14th, 2005
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!";
}
?>
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Php Syntax Error

 
0
  #2
Jul 14th, 2005
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 Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 3
Reputation: nightmare666 is an unknown quantity at this point 
Solved Threads: 0
nightmare666 nightmare666 is offline Offline
Newbie Poster

Re: Php Syntax Error

 
0
  #3
Jul 14th, 2005
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]
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Php Syntax Error

 
0
  #4
Jul 15th, 2005
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.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 3
Reputation: nightmare666 is an unknown quantity at this point 
Solved Threads: 0
nightmare666 nightmare666 is offline Offline
Newbie Poster

Re: Php Syntax Error

 
0
  #5
Jul 16th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Php Syntax Error

 
0
  #6
Jul 17th, 2005
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 Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC