username - Recall entered query from text form in php -
i learned code in php. want display 'hello, (logged in user)' in new page after user logged in using simple form , database can't find out how, can help? thank much.
for example:
login page simple form (login.php)
form action="hello.php"> name <input type="text" name="name"> <input name="button" type="submit"> </form>
php process login , new page, i'll assume database has been entered information (hello.php)
<?php $host="localhost"; $user="root"; $password=""; $database="test"; $connect=mysql_connect($host,$user,$password) or die("could not connect."); mysql_select_db($database,$connect) or die("could not select database."); $name=($_post['name']); $sql="select * users name='$name'" or die(mysql_error()); $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1) { header("location:hello2.php"); } else { echo "you not registered."; } ?>
welcome page (hello2.php), perhaps?
<html> <head> </head> <body> hello, <?php echo 'name' ?> </body> </html>
while logging in, save username in session variable,
$_session['username'] = 'guest';
then on home page,
echo 'hello'.$_session['username'];
Comments
Post a Comment