I'm very new to web developing and PHP. I'm creating a website with a member area and would like to display a Welcome "username" message. In my actual code there is a Welcome message displaying the Full Name of user. Can someone help me here? Below I'm pasting the code I'm using for my login.php and login-home.php (member's area). Thank you
login.php
<?PHP
require_once("./include/membersite_config.php");
if(isset($_POST['submitted']))
{
if($fgmembersite->Login())
{
$fgmembersite->RedirectToURL("login-home.php");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Login</title>
<link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css" />
<script type='text/javascript' src='scripts/gen_validatorv31.js'></script>
</head>
<body>
<!-- Form Code Start -->
<div class="logo_container"></div>
<div class='splash-container'>
<div id='fg_membersite'>
<form id='login' action='<?php echo $fgmembersite->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
<fieldset >
<legend>Orcaly</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<div><span class='error'><?php echo $fgmembersite->GetErrorMessage(); ?></span></div>
<div class='container'>
<label for='username' ></label><br/>
<input type='text' placeholder="UserName"name='username' id='username' value='<?php echo $fgmembersite->SafeDisplay('username') ?>' maxlength="50" /><br/>
<span id='login_username_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='password' ></label><br/>
<input type='password' placeholder="Password" name='password' id='password' maxlength="50" /><br/>
<span id='login_password_errorloc' class='error'></span>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
<div class='short_explanation'><a href='reset-pwd-req.php'>Forgot Password?</a></div>
<div class='register'><a href='register.php'>Register</a></div>
</fieldset>
</form>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->
<script type='text/javascript'>
// <![CDATA[
var frmvalidator = new Validator("login");
frmvalidator.EnableOnPageErrorDisplay();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("username","req","Please provide your username");
frmvalidator.addValidation("password","req","Please provide the password");
// ]]>
</script>
</div>
</div>
<!--
Form Code End (see html-form-guide.com for more info.)
-->
</body>
</html>
login-home.php
<?PHP
require_once("./include/membersite_config.php");
if(!$fgmembersite->CheckLogin())
{
$fgmembersite->RedirectToURL("login.php");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Home page</title>
<link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css">
</head>
<body>
<div class="logo_container"></div>
<div class='splash-container'>
<div id='fg_membersite'>
<fieldset>
<legend>Home Page</legend>
<div class='confirmation'>Welcome back <?= $fgmembersite->UserFullName(); ?>!</div>
<div class='confirmation'><a href='change-pwd.php'>Change password</a></div>
<div class='register'><a href='access-controlled.php'>A sample 'members-only' page</a></div>
<br>
<div class='register'><a href='logout.php'>Logout</a></div>
</fieldset>
</div>
</div>
</body>
</html>
The simple answer is you need to change this line of code:
<div class='confirmation'>Welcome back <?= $fgmembersite->UserFullName(); ?>!</div>
So that $fgmembersite->UserFullName(); becomes a variable that holds your username or a function that returns your username. Right now it is a function that returns the user's full name.
This might be a little bit beyond your current skills at programming. One thing that is very simple and feasible is to store the username as a session variable when the user logs in. Then you can replace $fgmembersite->UserFullName(); with $_SESSION["username"] or whatever you descide to call it.
Alternatively you can define your own function to return the username, or if the username isn't available for some reason, some other value (which is slightly better design).
Related
what is the problem in this code...??? it is not redirecting to the other page but stay on the login.php page (Blank Page)... Database are all correct...
can someone help me on this code...
your help is much appreciated...
<?
require_once('include/config.php');
require_once('include/functions.php');
session_start();
session_destroy();
$message="";
$Login=$_POST['Login'];
if($Login){ // If clicked on Login button.
$username=$_POST['username'];
$md5_password=md5($_POST['password']); // Encrypt password with md5() function.
mysql_select_db("$db", $con);
$result=mysql_query("select * from staff where stf_username='$username' and stf_password='$md5_password'");
$sql =mysql_query("select stf_level from staff where stf_username='$username'");
if(mysql_num_rows($result)!='0'){ // If match.
session_register("username");
while($row = mysql_fetch_array($sql))
{
//echo $row['level'] . " ";
if($row['stf_level'] == 1){
header("location:admin/index.php");
}
elseif($row['stf_level'] == 2){
header("location:cashier/index.php");
}
elseif($row['stf_level'] == 3){
header("location:waiter/index.php");
}
elseif($row['stf_level'] == 4){
header("location:kitchen/index.php");
}
}
//header("location:main.php"); // Re-direct to main.php
exit;
}else{ // If not match.
$message="--- Incorrect Username or Password ---";
}
} // End Login authorize check.
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta name="description" content="Description" />
<meta name="keywords" content="Keywords" />
<meta name="author" content="Aafrin" />
<title>iCafe Login</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="css/keyboard.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="js/keyboard.js"></script>
</head>
<body>
<div id="wrapper">
<div id="loginPanel">
<img class="image" alt="" src="images/logo.png" width="220" height="120" />
<div id="error"><? echo $message; ?></div>
<form id="form" name="form" method="post" action="<? echo $PHP_SELF; ?>">
<label>Username :</label>
<input type="text" name="username" class="keyboardInput" />
<label>Password :</label>
<input type="password" name="password" class="keyboardInput" />
<input name="Login" type="submit" id="Login" value="Login" class="submit" />
<!--
<input type="submit" value="Submit" name="submit" class="submit" />
-->
</form>
<div id="footer">
XYZ © 2012 - All Rights Reserver | Powered By Kesavan
</div>
</div>
<!--
<div id="details">
<p>Login Details</p>
Admin : admin
<br />
Waiter : waiter
<br />
Kitchen : kitchen
<br />
Cashier : cash
</div>
-->
</body>
</html>
try #header("") may be you have an error. Why dont you save all the location in a variable and pass the variable to the header function?
if($x=1){$loc="admin/index.php"}
if($x=2){$loc="staff/index.php"}
if($x=3){$loc="manager/index.php"}
#header('location:$loc')
i think you should put space after the :
it will be like
header("location: cashier/index.php");
I have dynamically loaded a page. In that page I have two div with the required values or the data displayed in one div or iframe and the values passed using POST to another file that should reflect in another div or iframe as a result.
Please help me to solve this....
Thank you.
Following is my Sample code
main.html
<html>
<head>
</head>
<body>
<div id="leftbar" style="background-color:#eeeeee;width:400px;height:1000px;float:left;position:absolute;">
<iframe src="form1.html" width="1050px" height="1500px" seamless></iframe>
</div>
<div id="container" style="background-color:#FFD700;height:1000px;width:990px;float:right;">
<iframe src="process.php" name="content" width="1050px" height="1500px" seamless></iframe>
</div>
</body>
</html>
form1.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello!</title>
</head>
<body>
<form name="myform" action="process.php" method="POST" >
<input type="hidden" name="check_submit" value="1" />
Choose the colors: <br>
<input type="checkbox" name="Colors[]" value="green" checked="checked" onclick="document.forms.myform.submit();"/> Green<br>
<input type="checkbox" name="Colors[]" value="yellow" onclick="document.forms.myform.submit();" /> Yellow <br>
<input type="checkbox" name="Colors[]" value="red" onclick="document.forms.myform.submit();"/> Red <br>
<input type="checkbox" name="Colors[]" value="gray" onclick="document.forms.myform.submit();" /> Gray <br>
<br /><br />
</form>
</body>
</html>
process.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Hello!</title>
</head>
<body>
<?php
if (array_key_exists('check_submit', $_POST)) {
if (isset($_POST['Colors']) ) {
$_POST['Colors'] = implode(', ', $_POST['Colors']);
}
echo "Colors you chose: {$_POST['Colors']}";
}
?>
</body>
</html>
Change your main.html to main.php and for form name instead of process.php just use main.php
<html >
<head>
</head>
<body>
<div id="leftbar" style="background-color:#eeeeee;width:400px;height:1000px;float:left;position:absolute;">
<iframe src="form1.html" width="1050px" height="1500px" seamless></iframe>
</div>
<?php
if (isset($_POST['Colors'])) {
if (array_key_exists('check_submit', $_POST)) {
$_POST['Colors'] = implode(', ', $_POST['Colors']);
}
echo "Colors you chose: {$_POST['Colors']}";
<div id="container" style="background-color:#FFD700;height:1000px;width:990px;float:right;">
<iframe src="process.php" name="content" width="1050px" height="1500px" seamless> </iframe>
</div>
<?PHP
}
?>
</body>
</html>
Ok my first time asking question here. This as been very helpful in the past but now i'm lost.
I'm trying to understand how php work with the help of a book. So i did the exercise as it was shown in the book and the result if not what it should be.
Here's the code:
<div id="content">
<p>Here's a record of everything in the REQUEST array:</p>
<?php
foreach($_REQUEST as $value) {
echo "<p>" . $value . "</p>";
}
?>
</div>
<div id="footer"></div>
</body>
And here's the result:
Here's a record of everything in the REQUEST array:
" . $value . "
"; } ?>
Why is not showing the info it is suppose to? Thanks.
Ok here's all the code:
showRequestInfo.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html
> xmlns="http://www.w3.org/1999/xhtml"> <head> <meta
> http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link
> href="/wamp/www/livrephp/css/phpMM.css" type="text/css"
> rel="stylesheet" />
>
> <title>Untitled Document</title> </head>
>
> <body> <div id="header"><h1>PHP & MySQL: The Missing
> manual</h1></div>
> <div id="example">Example 3-2</div>
>
> <div id="content">
> <p>Here's a record of everything in the REQUEST array:</p>
> <?php foreach($_REQUEST as $value) { echo "<p>" . $value . "</p>"; } ?>
>
>
> </div>
> <div id="footer"></div> </body> </html>
And this goes with this file called "socialEntryForm.php"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="/wamp/www/livrephp/css/phpMM.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="header"><h1>PHP & MySQL: The misiing manual</h1></div>
<div id="example">Example -1</div>
<div id="content">
<h1>Join the missing manual (Digital) Social Club</h1>
<p>Please enter your online connections below:</p>
<form action="../showRequestInfo.php" method="post">
<fieldset>
<label for="first_name">First Name:</label>
<input type="text" name="first_name" size="20" /><br />
<label for="last_name">Last Name:</label>
<input type="text" name="last_name" size="20" /><br />
<label for="email">Email Address:</label>
<input type="text" name="email" size="50" /><br />
<label for="facebook_url">Facebook URL:</label>
<input type="text" name="facebook_url" size="50" /><br />
<label for="twitter_handle">Twitter Handle:</label>
<input type="text" name="twitter_handle" size="50" /><br />
</fieldset>
<br />
<fieldset class="center">
<input type="submit" value="Join The Club" />
<input type="reset" value="Clear and Restart" />
</fieldset>
</form>
</div>
<div id="footer"></div>
</body>
</html>
Are you sure your file is a PHP file and it's being run on a PHP enabled server? The browser seems to be receiving the code unparsed, thinking that there's a tag starting at <?php and ending at the first <p> tag. If you look at the source, you'll probably see your PHP code, untouched by the server.
In other words: Your code is correct and the problem is your file type or server configuration. If you are indeed using a server on your machine, make sure you're running the file right, e.g. if it's in the root, open http://localhost/your_file.php, and not C:\xampp\htdocs\your_file.php.
EDIT: Just for the heck of it, I replicated your issue with a fiddle. I got the exact same output as you, meaning it's not getting parsed by the server. Who said JSFiddle was only good for JavaScript?
$_REQUEST Contains data which is gathered from cookies, $_POST and $_GET .. Are you sure that your data is properly assigned?
Take this example.
print_r($_REQUEST); just doing that without no <form method="get/post"> will produce a blank array, that might be why you are getting nothing
Your snippet is correct.. you are lacking a html form to go with that..
Example:
<form method="POST">
<input type="submit" name="test" value="ThisIsCorrect">
</form>
With your code you have shown your question.. your $_REQUEST array will return the value of the button. In this case "ThisIsCorrect"
Moral Of this?
Ensure that you are using using post/get/cookies before calling the $_REQUEST, and for future reference, just using $_POST & $_GET is cleaner to use.. But that is down to my personal preference.
How is the $_REQUEST Array constructed?
Consider this:
the array will contain the name as the array key and the value as the value..
So taking this into account:
<form method="POST">
<input type="text" name="username">
<input type="submit" name="test" value="ThisIsCorrect">
</form>
For your text box & Submit button the array will be:
array ("username" => "UserInputData",
"test" => "ThisIsCorrect");
I am writing a rather large PHP application and I've come to a point where I would like some debugging output. I've successfully installed FireBug and FirePHP and I've managed to output one line of text to the console.
Here is the problem now. I have a php file called Register.php which contains basically code only to display the view and submit the form. This file calls a function in the SiteViewModel.php class to do the actually background work in registering the user. The SiteViewModel.php also calls other php files to connect to the DB and perform checks/inserts.
If I put the debugging line in the SiteViewModel.php file constructor I get an output to the Firebug console. If I put any other lines anywhere else I get nothing logged.
Some code
Register.php:
<?php
require_once("/xampp/htdocs/SiteConfig.php");
if(isset($_POST['submitted']))
{
if($rlrpgSite->RegisterUser())
{
$rlrpgSite->RedirectToURL("registrationthanks.php");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Register</title>
<link rel="STYLESHEET" type="text/css" href="../style/fg_membersite.css" />
<script type='text/javascript' src='../scripts/gen_validatorv31.js'></script>
<link rel="STYLESHEET" type="text/css" href="../style/pwdwidget.css" />
<script src="../scripts/pwdwidget.js" type="text/javascript"></script>
</head>
<body>
<!-- Form Code Start -->
<div id='fg_membersite'>
<form id='register' action='<?php echo $rlrpgSite->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
<fieldset >
<legend>Register</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<div class='short_explanation'>* required fields</div>
<input type='text' class='spmhidip' name='<?php echo $rlrpgSite->GetSpamTrapInputName(); ?>' />
<div><span class='error'><?php echo $rlrpgSite->GetErrorMessage(); ?></span></div>
<div class='container'>
<label for='firstname' >First Name*: </label><br/>
<input type='text' name='FirstName' id='FirstName' value='<?php echo $rlrpgSite->SafeDisplay('FirstName') ?>' maxlength="100" /><br/>
<span id='register_firstname_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='lastname' >Last Name*: </label><br/>
<input type='text' name='LastName' id='LastName' value='<?php echo $rlrpgSite->SafeDisplay('LastName') ?>' maxlength="100" /><br/>
<span id='register_lastname_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='email' >Email Address*:</label><br/>
<input type='text' name='EmailAddress' id='EmailAddress' value='<?php echo $rlrpgSite->SafeDisplay('EmailAddress') ?>' maxlength="512" /><br/>
<span id='register_email_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='username' >UserName*:</label><br/>
<input type='text' name='UserName' id='UserName' value='<?php echo $rlrpgSite->SafeDisplay('UserName') ?>' maxlength="255" /><br/>
<span id='register_username_errorloc' class='error'></span>
</div>
<div class='container' style='height:80px;'>
<label for='Password' >Password*:</label><br/>
<div class='pwdwidgetdiv' id='thepwddiv' ></div>
<noscript>
<input type='password' name='Password' id='Password' maxlength="50" />
</noscript>
<div id='register_password_errorloc' class='error' style='clear:both'></div>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form>
<!-- client-side Form Validations:
Uses the excellent form validation script from JavaScript-coder.com-->
<script type='text/javascript'>
// <![CDATA[
var pwdwidget = new PasswordWidget('thepwddiv','Password');
pwdwidget.MakePWDWidget();
var frmvalidator = new Validator("register");
frmvalidator.EnableOnPageErrorDisplay();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("firstname","req","Please provide your name");
frmvalidator.addValidation("lastname","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email address");
frmvalidator.addValidation("email","email","Please provide a valid email address");
frmvalidator.addValidation("username","req","Please provide a username");
frmvalidator.addValidation("Password","req","Please provide a password");
// ]]>
</script>
<!--
Form Code End (see html-form-guide.com for more info.)
-->
</body>
</html>
SiteConfig.php:
<?php
require_once('SiteViewModel.php');
$rlrpgSite = new siteviewmodel();
$rlrpgSite->SetWebsiteName('localhost.com');
$rlrpgSite->SetAdminEmail('rlrpg#localhost.com');
$rlrpgSite->SetRandomKey('Hng2XxIdNfp8EwO');
?>
SiteViewModel.php:
<?php
class siteviewmodel
{
...
function siteviewmodel()
{
ob_start();
fb("Instantiating");
//This works
}
RegistUser()
{
ob_start();
fb("Registering");
//doesn't work
}
}
?>
When the form is submit my jquery accordion stops working my file name is add.php here is its code
<?php require_once('database.php');?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<link rel="stylesheet" href="css/accordionTheme.css">
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.ui.core.js" type="text/javascript"></script>
<script src="js/jquery.ui.widget.js" type="text/javascript"></script>
<script src="js/jquery.ui.accordion.js" type="text/javascript"></script>
<script>
$(function() {
$("#myAccordion").accordion();
});
</script>
<head>
<body>
<div id="myAccordion"><!-- Start Accordion --->
<h2>
Add Student
</h2>
<div>
<form action="add.php" id="form1" method="get" >//here my form start
<p>Please add Student Data</p>
<label for="stname">Enter Student Name:</label>
<input name="stname" type="text" id="stname" size="37" />
<br /><br />
<label for="stclass">Enter Student Class :</label>
<select name="stclass">
<option>MPhil</option>
<option>M.Sc.</option>
</select>
<br />
<input name="Add" type="submit" id="Add" value="Add" />
</form>
<?php
//lets start submit data to database
if(isset($_GET['stname'])&& isset($_GET['stclass']))
{
$stname=$_GET['stname'];
$stclass=$_GET['stclass'];
if(mysql_query("insert into student(teacher_id,student_name,student_class) values ('1','$stname','$stclass')"));
{
print "<p>record added</p";
}
}
?>
</div>
<h2>
Add course
</h2>
<div></div>
<h2>
Add publication
</h2>
<div></div>
</body>
</html>
I am printing php inside body you can see recordadded when form is submitted.
The p tag you print using PHP is not closed, which is what makes JavaScript go crazy. Close it and it should work OK.