Jump to content

Likely a Newb Question


JosiaMFire2

Recommended Posts

Hey, Im still learning to use PHP. I would apreciate it if someone with 5 mins spare would help me out, tell me what I have done wrong.
<? Session_start() ?>
<HTML>
<HEAD>
<TITLE>Admin Login</TITLE/>
<HEAD>
<BODY>
<H2>Admin Login</H2>
<BR>
<?
$links = "<A HREF='Admin_panel.php'>Click here to goto main page</A><BR><BR>";
If($name && $password) {
If($logged_in_user == $name) {
  echo $user.", you are already logged in.<BR><BR>";
    echo $links;
    exit;
}
$db = mysql_connect("localhost");
mysql_select_db("Login", $db);
$result = mysql_query("SELECT * FROM Name where name = '".$user."'";
AND password = PASSWORD('".$password.")"');
if (!$result) {
  echo "sorry, there has been a technical glitch. We cannot enter your details";
  exit;
 
}
If (mysql_num_rows($result) > 0) {
  $logged_in_user = $user;
  session_register("logged_in_user");
  echo "Welcome, ".$logged_in_user.".<BR><BR>";
  echo $links;
  exit;
  } else {
    echo "invalid login. Please try again.<BR>.<BR>";
}
)
}
?>
<FORM METHOD=POST ACTION="Login.php">
Your Admin login name:
<BR>
<INPUT NAME="name" TYPE=TEXT MAXLENGTH=20 SIZE=20>
<BR>
<BR>
Your Admin password: 
<BR>
<INPUT NAME="password" TYPE=password MAXLENGTH=20 SIZE=20>
<BR>
<BR>
<Input type=submit value="login">
</FORM>
</Body>
</HTML>
Link to comment
Share on other sites

Why you using caps all the time

PHP is case sensative (Depending on the settings)
If and if are different functions

Where the the top variables coming from???
$name  $password  $logged_in_user
I am guessing $logged_in_user is a sesssion
and the other 2 are from the form

[code]

<?php Session_start() ?>
<html>
<head>
<title>Admin Login</title>
<head>
<body>
<h2>Admin Login</h2>

<?php
  $links = "<a href='Admin_panel.php'>Click here to goto main page</a><br /><br />";
  If($_POST["name"] && $_POST["password"]) {
      If($_SESSION["logged_in_user"] == $_POST["name"]) {
  //Where has $user come from?????????
          echo $user.", you are already logged in.<BR><BR>";
          echo $links;
          exit;
      }
      $db = mysql_connect("localhost","username","password");
      mysql_select_db("Login", $db);
      $result = mysql_query("SELECT * FROM Name where name = '".$user."'";
                  AND `password` = PASSWORD('".$password.")"');
  //password is a defind word in MySQL and should not really name fields password, try pwd or something
                  if (!$result) {
                    echo "sorry, there has been a technical glitch. We cannot enter your details";
                    exit;
                 
                  }
                  if (mysql_num_rows($result) > 0) {
                    $logged_in_user = $user;
                    $_SESSION["logged_in_user"] = $logged_in_user;
//This is the best practice for naming sessions
                    echo "Welcome, ".$logged_in_user.".<br /><br />";
                    echo $links;
                    exit;
                    } else {
                      echo "invalid login. Please try again.<br />.<br />";
                  }
                  )
  }
?>
<FORM METHOD=POST ACTION="Login.php">
Your Admin login name:
<BR>
<INPUT NAME="name" TYPE=TEXT MAXLENGTH=20 SIZE=20>
<BR>
<BR>
Your Admin password:
<BR>
<INPUT NAME="password" TYPE=password MAXLENGTH=20 SIZE=20>
<BR>
<BR>
<Input type=submit value="login">
</FORM>
</body>
</head>
[/code]
Link to comment
Share on other sites

[quote author=onlyican link=topic=104062.msg414892#msg414892 date=1155459775]
Why you using caps all the time

PHP is case sensative (Depending on the settings)
If and if are different functions
[/quote]

Uhrr? Did I miss something? I thought only variables, constants and properties where case sensitive?
Link to comment
Share on other sites

So you're saying you get echoed:

[quote]       
echo $links;
          exit;
      }
      $db = mysql_connect("localhost");
      mysql_select_db("Login", $db);
      $result = mysql_query("SELECT * FROM Name where name = '".$user."'";
                  AND password = PASSWORD('".$password.")"');
    etc etc.
?>[/quote]

With 'echo $links' included?
Link to comment
Share on other sites

What you should get, is a parsing error.

[u][b]It's got plenty of them.[/b][/u]

Check your level of error reporting in php.ini
For now, simply add [u][i]ini_set('error_reporting',E_ALL);[/i][/u] to the top op your file. That should ensure you get errors reported.

I'll ask one last time to avoid confusion:

This does not show:
[quote]?php
  $links = "<a href='Admin_panel.php'>Click here to goto main page</a><br /><br />";
  If($_POST["name"] && $_POST["password"]) {
      If($_SESSION["logged_in_user"] == $_POST["name"]) {
  //Where has $user come from?????????
          echo $user.", you are already logged in.<BR><BR>";[/quote]

This (and everything below it) does show:
[quote]        echo $links;
          exit;
      }
      $db = mysql_connect("localhost","username","password");
      mysql_select_db("Login", $db);
      $result = mysql_query("SELECT * FROM Name where name = '".$user."'";[/quote]

If so, it's probably an uncaught parsing error. Fix your parsing errors, have look at the content of $links (something seems fishy about it) and then we'll talk.
Link to comment
Share on other sites

Ok, I´m in a good mood, so I took the parsing errors out of your script for you.
Note that didn't change anything else, although I don't agree with most of the things you're doing in this script.. :o

One thing at the time I guess. Good luck with that.

[code]<? Session_start() ?>
<HTML>
<HEAD>
<TITLE>Admin Login</TITLE/>
<HEAD>
<BODY>
<H2>Admin Login</H2>
<BR>
<?
$links = "<A HREF='Admin_panel.php'>Click here to goto main page[/url]<BR><BR>";
if($name && $password) {
if($logged_in_user == $name) {
echo $name.", you are already logged in.<BR><BR>";
echo $links;
exit;
}
$db = mysql_connect("localhost");
mysql_select_db("Login", $db);
$result = mysql_query('SELECT * FROM Name where name = "'.$name.'" AND password = PASSWORD("'.$password.'")');
if (!$result) {
echo "sorry, there has been a technical glitch. We cannot enter your details";
exit;
}
if (mysql_num_rows($result) > 0) {
$logged_in_user = $user;
session_register("logged_in_user");
echo "Welcome, ".$logged_in_user.".<BR><BR>";
echo $links;
exit;
} else {
echo "invalid login. Please try again.<BR>.<BR>";
}
}
?>
<FORM METHOD=POST ACTION="Login.php">
Your Admin login name:
<BR>
<INPUT NAME="name" TYPE=TEXT MAXLENGTH=20 SIZE=20>
<BR>
<BR>
Your Admin password:
<BR>
<INPUT NAME="password" TYPE=password MAXLENGTH=20 SIZE=20>
<BR>
<BR>
<Input type=submit value="login">
</FORM>
</Body>
</HTML>[/code]
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.