Jump to content

Login Code issues (mysql_fetch_assoc)


Foser

Recommended Posts

<?php
include("config.php");

$user = $_POST['user'];
$pw = md5(sha1(md5(md5($_POST['pw']))));

mysql_fetch_assoc(mysql_query("SELECT password FROM user_info WHERE username = $user"));

if ($pw == $user_info['password']){
mysql_fetch_assoc(mysql_query("SELECT rights FROM user_info WHERE username = $user")); 
echo "You are now logged in as a $user_info['rights']."; } // this is line 11
else {
echo "You have typed in an incorrect password or/and username. Please try again."; }

?>

 

The error I get is :

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\Login\login.php on line 11

 

 

thanks, im not sure if i am doing the mysql fetch assoc correctly.

Link to comment
Share on other sites

Ok i've done that but now I get

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\WAMP\www\Tutorials\PHP_MYSQL\Simple_MySQL\Login\login.php on line 7

 

also I have typed in correct password and user, and it says under the error that my info is not correct.

Link to comment
Share on other sites

mysql_fetch_assoc(mysql_query("SELECT password FROM user_info WHERE username = $user"));
mysql_fetch_assoc(mysql_query("SELECT rights FROM user_info WHERE username = $user")); 

Replace with

mysql_fetch_assoc(mysql_query("SELECT password FROM user_info WHERE username = '$user'"));
mysql_fetch_assoc(mysql_query("SELECT rights FROM user_info WHERE username = '$user'")); 

better you use die() wherever it is appropriate.

 

 

Link to comment
Share on other sites

Yes I have here is my registration code.

 

<?php
require("config.php");
//user data
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['mail']);
$password = md5(sha1(md5(md5($_POST['pw']))));
$rights = "user";

$check_user = mysql_query("SELECT user FROM user_info WHERE user = '$username'");
$check_email = mysql_query("SELECT email FROM user_info WHERE email = '$email'");



if ($username > 0 ) {
echo "This username has already been taken.<br>";}

if ($email > 0 ){
echo "This E-mail has already been registered.<br>.";}


else {
$qu = "INSERT INTO user_info (username, email, password, rights) VALUES('$username', '$email', '$password', '$rights')";
mysql_query($qu);
echo "You are now registered, you may now login.<br>";
echo "<a href=\"index.php\">Click Here To Go To The Login Page </a>";

}

?>

Link to comment
Share on other sites

I checked with mysql_real_escape_string() and still does not work! Ill put both scripts in one page

 

<?php
// registration


require("config.php");
//user data
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['mail']);
$password = md5(sha1(md5(md5($_POST['pw']))));
$rights = "user";

$check_user = mysql_query("SELECT user FROM user_info WHERE user = '$username'");
$check_email = mysql_query("SELECT email FROM user_info WHERE email = '$email'");



if ($username > 0 ) {
echo "This username has already been taken.<br>";}

if ($email > 0 ){
echo "This E-mail has already been registered.<br>.";}


else {
$qu = "INSERT INTO user_info (username, email, password, rights) VALUES('$username', '$email', '$password', '$rights')";
mysql_query($qu);
echo "You are now registered, you may now login.<br>";
echo "<a href=\"index.php\">Click Here To Go To The Login Page </a>";

}

?>

 

//login
<?php
require("config.php");

$user = mysql_real_escape_string($_POST['user']);
$pw = md5(sha1(md5(md5($_POST['pw']))));

mysql_fetch_assoc(mysql_query("SELECT password FROM user_info WHERE username = '$user'")) or die(mysql_error());

if ($pw == $user_info['password']){
mysql_fetch_assoc(mysql_query("SELECT rights FROM user_info WHERE username = '$user'")); 
echo "You are now logged in as a $user_info[rights]."; }
else {
echo "You have typed in an incorrect password or/and username. Please try again."; }

?>

Link to comment
Share on other sites

I checked with mysql_real_escape_string() and still does not work! Ill put both scripts in one page

 

<?php
// registration


require("config.php");
//user data
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['mail']);
$password = md5(sha1(md5(md5($_POST['pw']))));
$rights = "user";

$check_user = mysql_query("SELECT user FROM user_info WHERE user = '$username'");
$check_email = mysql_query("SELECT email FROM user_info WHERE email = '$email'");



if ($username > 0 ) {
echo "This username has already been taken.<br>";}

if ($email > 0 ){
echo "This E-mail has already been registered.<br>.";}


else {
$qu = "INSERT INTO user_info (username, email, password, rights) VALUES('$username', '$email', '$password', '$rights')";
mysql_query($qu);
echo "You are now registered, you may now login.<br>";
echo "<a href=\"index.php\">Click Here To Go To The Login Page </a>";

}

?>

 

//login
<?php
require("config.php");

$user = mysql_real_escape_string($_POST['user']);
$pw = md5(sha1(md5(md5($_POST['pw']))));

mysql_fetch_assoc(mysql_query("SELECT password FROM user_info WHERE username = '$user'")) or die(mysql_error());

if ($pw == $user_info['password']){
mysql_fetch_assoc(mysql_query("SELECT rights FROM user_info WHERE username = '$user'")); 
echo "You are now logged in as a $user_info[rights]."; }
else {
echo "You have typed in an incorrect password or/and username. Please try again."; }

?>

 

bump

Link to comment
Share on other sites

It means u wana say that u still cannot login to ur system using correct password and username.

Am i right to get ur point.

 

and yes, i am logging in wit the correct data and still execute the else statement not the if.

Link to comment
Share on other sites

I get my else statement.

 

//login
<?php
require("config.php");

$user = mysql_real_escape_string($_POST['user']);
$pw = md5(sha1(md5(md5($_POST['pw']))));

mysql_fetch_assoc(mysql_query("SELECT password FROM user_info WHERE username = '$user'")) or die(mysql_error());

if ($pw == $user_info['password']){
mysql_fetch_assoc(mysql_query("SELECT rights FROM user_info WHERE username = '$user'")); 
echo "You are now logged in as a $user_info[rights]."; }
else {
echo "You have typed in an incorrect password or/and username. Please try again."; }

?>

 

I get: You have typed in an incorrect password or/and username. Please try again.

 

 

Link to comment
Share on other sites

<?php
// registration


require("config.php");
//user data
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['mail']);
$password = md5(sha1(md5(md5($_POST['pw']))));
$rights = "user";

$check_user = mysql_query("SELECT user FROM user_info WHERE user = '$username'");
$check_email = mysql_query("SELECT email FROM user_info WHERE email = '$email'");



if ($username > 0 ) {
echo "This username has already been taken.<br>";}

if ($email > 0 ){
echo "This E-mail has already been registered.<br>.";}


else {
$qu = "INSERT INTO user_info (username, email, password, rights) VALUES('$username', '$email', '$password', '$rights')";
mysql_query($qu);
echo "You are now registered, you may now login.<br>";
echo "<a href=\"index.php\">Click Here To Go To The Login Page </a>";

}

?>

 

This is my registration code...I believe it is suited for the login too.

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.