Hi
I have made a login page with the help from the tutorial on this site at http://www.phpcomplete.com/tutorials.ph ... adTutorial
i have added a field to the database which i have called firstName but seem to not beable to carry that over to the next page. Here is the code that i have written
<?php
session_start();
$user_name = $_POST['user_name'];
$password = $_POST['password'];
// Open connection to the database
$connection = mysql_connect("localhost", "cctvcity", "ccpass02") or die("Failure to communicate with database");
mysql_select_db('cctvcity', $connection) or die(mysql_error());
//set up the query
$query = "SELECT * FROM users
WHERE user_name='$user_name' AND password='$password'";
//run the query and get the number of affected rows
$result = mysql_query($query, $connection) or die('error making query');
$affected_rows = mysql_num_rows($result);
$firstName = $affected_rows["firstName"];
//if there's exactly one result, the user is validated. Otherwise, he's invalid
if($username == $row["username"] && $user_password == $row["user_password"]) {
print 'validated <a href="verifyLogin.php">Click here to check</a>';
//add the user to our session variables
session_register("username","firstName");
$_SESSION['username'] = $user_name;
$_SESSION['firstName'] = $firstName;
}
else {
print 'not valid';
}
?>
<html>
<head>
<title>validate.php</title>
</head>
<body>
<?php
$user_name = $_POST['user_name'];
$password = $_POST['password'];
?>
</body>
</html>
any tips would be gratefully received. Thanks
Sessions and mySQL queries
Moderator: General Moderators
Do not use superglobals w/session_register() i.e. $_SESSION
from the manual
http://www.php.net/manual/en/function.s ... gister.php
from the manual
http://www.php.net/manual/en/function.s ... gister.php
If you want your script to work regardless of register_globals, you need to use the $_SESSION array. All $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where register_globals is disabled.
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister().
_
yeah i did have a session_start code on the next and have taking the register_session line off bu thave the same problem. in which i seem to be only able to take $_SESSION['username'] = $username; over to the next page.
What i have now done is picked the value up from there, checked it against database and then retrieved the values i wanted to anyway (with the same code i was trying in the first place). here the code i am now using on the following page for anyone interested.
//following code gets database details from $username row that i want
$sqlcheck = "SELECT * FROM users
WHERE username='$username'";
$result = mysql_query($sqlcheck, $connection) or die('error making query');
$row = mysql_fetch_array($result);
$firstName = $row["firstName"];
$users_detail1 = $row["users_detail1"];
$users_detail2 = $row["users_detail2 "];
thanks
Deej
What i have now done is picked the value up from there, checked it against database and then retrieved the values i wanted to anyway (with the same code i was trying in the first place). here the code i am now using on the following page for anyone interested.
//following code gets database details from $username row that i want
$sqlcheck = "SELECT * FROM users
WHERE username='$username'";
$result = mysql_query($sqlcheck, $connection) or die('error making query');
$row = mysql_fetch_array($result);
$firstName = $row["firstName"];
$users_detail1 = $row["users_detail1"];
$users_detail2 = $row["users_detail2 "];
thanks
Deej