Jump to content

else if login page trouble


sjslovechild

Recommended Posts

Ok here is what I'm trying to do.

 

There is a link in a email that is sent out to the people who use this app.

When they click on the email link they are brought to this site which is password protected.

So they have to enter their username and password. What I want to below script to do is to log them in while checking to see if the $id variable is set. If it is, then the script is to take them to the page in the email link. If not take them to the submit job page.

 

<?php
$id=$_POST["id"];
$cmd = $_POST['cmd'];
$connection = mysql_connect("host", "user", "pass");
mysql_select_db("database", $connection) or die(mysql_error());


switch($cmd) {
case "login":
	$u = $_POST['username'];
	$p = $_POST['password'];
	$query = "SELECT * FROM login WHERE username='$u' AND password='$p'";
	$result = mysql_query($query);
	$row = mysql_fetch_array($result);

	if (isset($id))($row){

		session_start();
		$_SESSION['user_id'] = $row[0];
		$_SESSION['residentname'] = $row[1];
		$_SESSION['unit_num'] = $row[2];
		setcookie("TestCookie", time()+3600);  /* expire in 1 hour */
		$resite = "submitjob.php?do=viewone&id=$id";
		header("Location:$resite");
		exit();

	} else if ($row){

		session_start();
		$_SESSION['user_id'] = $row[0];
		$_SESSION['residentname'] = $row[1];
		$_SESSION['unit_num'] = $row[2];
		setcookie("TestCookie", time()+3600);  /* expire in 1 hour */
		$resite = "submitjob.php";
		header("Location:$resite");
		exit();


	} else {
		echo "Sorry the app didn't find a match.";
	}
break;



}
?>

Link to comment
Share on other sites

You did not clearly state a problem, so this "solution" might not solve it;

 

This statement:

if (isset($id))($row){

does not seem to be syntactically correct to me. Did you, perhaps, mean:

if ((isset($id)) AND ($row)) {

 

However, isset($id) will always be true there, because you set it at the very first line. Perhaps a better test would be:

if ((!empty($id)) AND ($row)) {

 

Plus you have some duplicated code there. I would probably re-write the entire IF statement as:

	if ($row) {
	session_start();
	$_SESSION['user_id'] = $row[0];
	$_SESSION['residentname'] = $row[1];
	$_SESSION['unit_num'] = $row[2];
	setcookie("TestCookie", time()+3600);  /* expire in 1 hour */
	$resite = "submitjob.php";
	if (!empty($id)) $resite .= "?do=viewone&id=$id";
	header("Location: $resite");
	exit();
} else {
	echo "Sorry the app didn't find a match.";
} 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.