| | |
Php Syntax Error
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2005
Posts: 3
Reputation:
Solved Threads: 0
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!";
}
?>
---------------------------------------------------------------------------
------------------
<?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!";
}
?>
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.
[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.
•
•
Join Date: Jul 2005
Posts: 3
Reputation:
Solved Threads: 0
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]
[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]
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.
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.
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?
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?
![]() |
Similar Threads
- syntax error, unexpected $end in ndex.php on line 127 (PHP)
- PHP testing server no syntax error just blank web page (PHP)
- Invalid Syntax Error (Viruses, Spyware and other Nasties)
- UPDATE syntax error (MySQL)
Other Threads in the PHP Forum
- Previous Thread: Learning php
- Next Thread: Trying to create a login system
| Thread Tools | Search this Thread |
5.2.10 action apache api array beginner beneath binary broken cakephp checkbox class classes cms code cron curl database date destroy display dynamic echo echo$_get[x]changingitintovariable... email encode error fcc file files folder form forms function functions google header howtowriteathesis href htaccess html image images include insert ip javascript joomla limit link local login mail memberships menu mlm mod_rewrite multiple multipletables mysql mysqlquery neutrality oop open passwords paypal pdf php provider query radio random record remote rss script search server sessions sockets source space sql strip_tags syntax system table template thesishelp tutorial update upload url validator variable video voteup web window.onbeforeunload=closeme; youtube





