Hi. I have a register/login script (Very Simple one). The one I had was just a simple username, password, and confirm password type. Well, I inserted Name, Address, City, ect. into it. It all works expect I can't see any of the options I added in the database after they fill the form out. I can see where they are suppose to go.
Here are the codes:
functions.php
<?php
// Salt Generator
function generate_salt ()
{
// Declare $salt
$salt = '';
// And create it with random chars
for ($i = 0; $i < 3; $i++)
{
$salt .= chr(rand(35, 126));
}
return $salt;
}
function user_register($username, $password)
{
// Get a salt using our function
$salt = generate_salt();
// Now encrypt the password using that salt
$encrypted = md5(md5($password).$salt);
// And lastly, store the information in the database
$query = "insert into user (username, password, salt) values ('$username', '$encrypted', '$salt')";
mysql_query ($query) or die ('Could not create user.');
}
function user_login($username, $password)
{
// Try and get the salt from the database using the username
$query = "select salt from user where username='$username' limit 1";
$result = mysql_query($query);
$user = mysql_fetch_array($result);
// Using the salt, encrypt the given password to see if it
// matches the one in the database
$encrypted_pass = md5(md5($password).$user['salt']);
// Try and get the user using the username & encrypted pass
$query = "select userid, username from user where username='$username' and password='$encrypted_pass'";
$result = mysql_query($query);
$user = mysql_fetch_array($result);
$numrows = mysql_num_rows($result);
// Now encrypt the data to be stored in the session
$encrypted_id = md5($user['userid']);
$encrypted_name = md5($user['username']);
// Store the data in the session
$_SESSION['userid'] = $userid;
$_SESSION['username'] = $username;
$_SESSION['encrypted_id'] = $encrypted_id;
$_SESSION['encrypted_name'] = $encrypted_name;
if ($numrows == 1)
{
return 'Correct';
}
else
{
return false;
}
}
function user_logout()
{
// End the session and unset all vars
session_unset ();
session_destroy ();
}
function is_authed()
{
// Check if the encrypted username is the same
// as the unencrypted one, if it is, it hasn't been changed
if (isset($_SESSION['username']) && (md5($_SESSION['username']) == $_SESSION['encrypted_name']))
{
return true;
}
else
{
return false;
}
}
?>
register.php
<?php
// Include init file
include 'init.php';
if (!isset($_POST['submit']))
{
// Show the form
include 'register_form.inc.php';
exit;
}
else
{
// Check if any of the fields are missing
if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['confirmpass']) || empty($_POST['firstname']) || empty($_POST['lastname']) || empty($_POST['address']) || empty($_POST['city']) || empty($_POST['state']) || empty($_POST['country']))
{
// Reshow the form with an error
$reg_error = 'One or more fields missing';
include 'register_form.inc.php';
exit;
}
// Check if the passwords match
if ($_POST['password'] != $_POST['confirmpass'])
{
// Reshow the form with an error
$reg_error = 'Your passwords do not match';
include 'register_form.inc.php';
exit;
}
// Everything is ok, register
user_register ($_POST['username'], $_POST['password'], $_POST['firstname'], $_POST['lastname'], $_POST['address'], $_POST['city'], $_POST['state'], $_POST['country']);
echo 'Thank you for registering on our site, <a href="index.php">click here</a> to go back.';
}
?>
I have 3-4 more pages of coding, but those pages are mostly login and stuff.
Any help is always appreciated. THANKS!