Jump to content

Archived

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

wesleypipes

Help with creating simple php LOGIN session?

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

Share this post


Link to post
Share on other sites
Hi, you did forget a ";"

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

if (mysql_num_rows($result) > 0) {

$_SESSION["authenticatedUser"] = $appusername;

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Thankyou very much huggiebear. This has solved the my problem. Was it my php opening tags that confused the program. CHEERS. Ive only been doing this for 2 weeks and im not that good at it, but as i said THANKYOU VERY MUCH !

Share this post


Link to post
Share on other sites
If you're putting quotes around table names they should really be backticks ( ` ) not single quotes ( ' ) and your values should be enclosed in single quotes.

Regards
Huggie

Share this post


Link to post
Share on other sites

×

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.