Jump to content

[SOLVED] trying to greet the user


cluce

Recommended Posts

I have three pages a user_logon.html, userlogin.php, and a logon(if successful). I am trying to greet the user but my php is not on the same page as logon.php.  Is their any way I can greet the user this way?? If so I can't get it to work.                                          here is the userlogon.html code........

 <form method="post" action="userlogin.php">
<p> </p>
<p><strong>Username:</strong>
  <input name="username" type="text" size="25"/>
</p>
<p><strong>Password:</strong>
  <input name="password" type="password" size="25"/>
</p>
<blockquote>
  <blockquote>
    <p align="right">
      <input name="submit" type="submit" onclick="MM_validateForm('username','','R','password','','R');return document.MM_returnValue" value=" Login "/>
      <input name="Reset" type="reset" id="Reset" value="Cancel" />
    

 

here is the userlogin.php code........

<?php

//check for required fields from the form
if ((!isset($_POST["username"])) || (!isset($_POST["password"]))) {
header("Location: user_logon.html");
exit;
}

//connect to server and select database
$mysqli = mysqli_connect("localhost", "root", "", "test");

//create and issue the query
$sql = "SELECT f_name, l_name FROM auth_users WHERE username = '".$_POST["username"]."' AND password = PASSWORD('".$_POST["password"]."')";

$result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));

//get the number of rows in the result set; should be 1 if a match
if (mysqli_num_rows($result) == 1) {

//if authorized, get the values of f_name l_name
while ($info = mysqli_fetch_array($result)) {
	$f_name = stripslashes($info['f_name']);
	$l_name = stripslashes($info['l_name']);
}

//set authorization cookie
setcookie("auth", "1", 0, "/", "yourdomain.com", 0);

//directs authorized user
header("Location: logon.php");

} else {
//redirect back to login form if not authorized
header("Location: registration.html");
exit;
}

?>

 

here is the logon.php page code......

        <p>
<?php  echo("<p>Welcome <b>".$_POST['f_name']."</b>!</p>") ?>	
 </p>

 

 

Can someone suggest how I can get this accomplished??

 

Link to comment
Share on other sites

You have to use cookies or sessions. IE:

 

<?php
session_start();
//check for required fields from the form
if ((!isset($_POST["username"])) || (!isset($_POST["password"]))) {
header("Location: user_logon.html");
exit;
}

//connect to server and select database
$mysqli = mysqli_connect("localhost", "root", "", "test");

//create and issue the query
$sql = "SELECT f_name, l_name FROM auth_users WHERE username = '".$_POST["username"]."' AND password = PASSWORD('".$_POST["password"]."')";

$result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));

//get the number of rows in the result set; should be 1 if a match
if (mysqli_num_rows($result) == 1) {

//if authorized, get the values of f_name l_name
while ($info = mysqli_fetch_array($result)) {
	$f_name = stripslashes($info['f_name']);
	$l_name = stripslashes($info['l_name']);
}

//set authorization cookie
setcookie("auth", "1", 0, "/", "yourdomain.com", 0);

            $_SESSION['usersname'] = $f_name . " " . $l_name;

//directs authorized user
header("Location: logon.php");

} else {
//redirect back to login form if not authorized
header("Location: registration.html");
exit;
}

?>

 

<?php
session_start();
print $_SESSION['usersname'];
?>

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.