Jump to content


Photo

Help with creating simple php LOGIN session?


  • Please log in to reply
4 replies to this topic

#1 wesleypipes

wesleypipes
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 October 2006 - 03:18 PM

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


#2 ruano84

ruano84
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationVenezuela

Posted 30 October 2006 - 03:25 PM

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;
Alexis RR

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 30 October 2006 - 03:32 PM

That's not the problem, the code should look like this:

<?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");
}
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 wesleypipes

wesleypipes
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 October 2006 - 03:40 PM

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 !

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 30 October 2006 - 03:43 PM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users