Jump to content

Help with creating simple php LOGIN session?


wesleypipes

Recommended Posts

Basically this is what i would like to do i will also post the code ive made. With a php program i would like to connect to my database, collect data from a form and save it into variables and create a query to search the user table to see if the user can basically login or not.  I have create my Form, php program and database. Below is the copy of my php code:

<?
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("memberdir") or die(mysql_error());
?>

<?
$appusername=$_POST['login_name'];
$apppassword=$_POST['password'];

$result = mysql_query(" SELECT * FROM 'user' WHERE username = $appusername AND password = $apppassword ")

if (mysql_num_rows($result) > 0) {

$_SESSION["authenticatedUser"] = $appusername;

header("Location: loggedon.php");

}

else

{

$_SESSION["message"] = "Could not connect as  $appusername ";

header("Location: login.php");

}

?>

i really wish you can help. BAsically when i submit my 'login' form i get a parse error at line 12
That's not the problem, the code should look like this:

[code]<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("memberdir") or die(mysql_error());

$appusername = $_POST['login_name'];
$apppassword = $_POST['password'];

$result = mysql_query("SELECT * FROM `user` WHERE username = '$appusername' AND password = '$apppassword'");
if (mysql_num_rows($result) > 0) {
  $_SESSION['authenticatedUser'] = $appusername;
  header("Location: loggedon.php");
}
else {
  $_SESSION['message'] = "Could not connect as $appusername";
  header("Location: login.php");
}
?>[/code]

Regards
Huggie

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.