cluce Posted May 7, 2007 Share Posted May 7, 2007 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 https://forums.phpfreaks.com/topic/50396-solved-trying-to-greet-the-user/ Share on other sites More sharing options...
sasa Posted May 7, 2007 Share Posted May 7, 2007 use session varible to pass value Link to comment https://forums.phpfreaks.com/topic/50396-solved-trying-to-greet-the-user/#findComment-247520 Share on other sites More sharing options...
per1os Posted May 7, 2007 Share Posted May 7, 2007 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 https://forums.phpfreaks.com/topic/50396-solved-trying-to-greet-the-user/#findComment-247524 Share on other sites More sharing options...
cluce Posted May 7, 2007 Author Share Posted May 7, 2007 thanks a millioin Link to comment https://forums.phpfreaks.com/topic/50396-solved-trying-to-greet-the-user/#findComment-247572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.