/    Sign up×
Community /Pin to ProfileBookmark

code debugging help

Hi

The below code is giving me some greif, when I use my form to post the info the code appears to do nothing, behaves like there is something missing from my php code

any help is great

[code=php]

<?php session_start(); ?>
<html>
<head>
<title>Secure Login Page</title>
</head>
<body>

<?
include ‘db.php’;

// Conver to simple variables
$username = $_POST[‘username’];
$password = $_POST[‘password’];

if((!$username) || (!$password)){
echo “Please enter ALL of the information! <br />”;
include ‘form_user_login.php’;
exit();
}

// Convert password to md5 hash
$password = md5($password);

// check if the user info validates the db
$sql = mysql_query(“SELECT * FROM users WHERE username=’$username’ AND password=’$password’ AND activated=’1′”);
$login_check = mysql_num_rows($sql);

if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$key = stripslashes( $val );
}
// Register some session variables!

$_SESSION[‘first_name’] = $first_name;

$_SESSION[‘last_name’] = $last_name;

$_SESSION[’email_address’] = $email_address;

$_SESSION[‘user_level’] = $user_level;

$_SESSION[‘username’] = $username;

mysql_query(“UPDATE users SET last_login=now() WHERE userid=’$userid'”);

header(“Location: login_success.php”);
} else {
echo “You could not be logged in! Either the username and password do not match or you have not validated your membership!<br />
Please try again!<br />”;
include ‘login_form.html’;
}
?>
<p><a href=”user_logout.php”>logout</a></p>
<p><a href=”all_database_enteries.php”>My Iformation</a></p>
<p><a href=”viewmyinfo.php”>Get My Info</a></p>

</body>
</html>
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@SheldonApr 23.2006 — why are you doing this?

[code=php]$login_check = mysql_num_rows($sql);

if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$key = stripslashes( $val );
}[/code]
Copy linkTweet thisAlerts:
@delr2691Apr 23.2006 — $login_check must be 1 if the username and password match and if the user is activated.. as you can see, that contains the number of results returned by the $sql query.. I don't see anything wrong.. What does it output when you submit valid credentials??
Copy linkTweet thisAlerts:
@delr2691Apr 23.2006 — [code=php]
$row = mysql_fetch_array($sql);
foreach ($row AS $key => $val){
$($key) = stripslashes($val);
}
[/code]

I think that may be the problem.. You weren't defining $first_name, $last_name and all those other variables.. so the session variables will be empty too..

With the above code, you will create a variable with the name of each key in the $row array with it's value.. In other words, you will have a variable with the name of every column of the table and with the values of the user that's loging in..
×

Success!

Help @kproc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...