HELP! i got stuck showing a variable value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
iAnoir
Forum Newbie
Posts: 4
Joined: Tue Apr 16, 2013 7:34 am

HELP! i got stuck showing a variable value

Post by iAnoir »

Hello all php coders,

Can you just take a few seconds to see what problem i am having in this code, i spent more than 5 hours to get the solution but without success :(

* Well let me first explain a little bit the goal of this little code,
---> First page Test.html
we have this code :

Code: Select all

 <html>
<body>

<form action="welcome.php" method="post">
Name: <input type="text" name="name">
<input type="submit">
</form>

</body>
</html>
---> Second page welcome.php // where the posted data will be submited!
we have this code:

Code: Select all

 <?php

	$an= file_get_contents('./anoir.php'); 
	$f = $_POST['name'];


	if($f == anoir){
		print $an;
} else { ''; } 
	 ?>
-----> last page where i want exactly my name be shown :) it doesn't display here that's what am asking about :/
anoir.php

some code here
variable must be display here

Code: Select all

<? echo .$_POST['name'].''; ?>
---------------------------------------------------------------------------
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: HELP! i got stuck showing a variable value

Post by Christopher »

iAnoir wrote:

Code: Select all

<? echo .$_POST['name'].''; ?>
This code has an error. Try:

Code: Select all

<? echo $_POST['name'].''; ?>
PS - the code .'' does not really do anything. It concatenates nothing to the end of the string.
(#10850)
iAnoir
Forum Newbie
Posts: 4
Joined: Tue Apr 16, 2013 7:34 am

Re: HELP! i got stuck showing a variable value

Post by iAnoir »

I do really understand what you're saying but the problem is that the value of the variable doesn't display on the page :)

/* when i am writing "anoir" in the field and submitted the form it goes to welcome.php then the if statement verify if the input field is true then it calls the function file_get_contents .. which is anoir.php ---> so here i want the variable to be displayed :) i guess this will help you to understand my goal

Please take a moment and test it yourself to better understand me, i would be glad to hear from you soon
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: HELP! i got stuck showing a variable value

Post by McInfo »

PHP Manual: include
iAnoir
Forum Newbie
Posts: 4
Joined: Tue Apr 16, 2013 7:34 am

Re: HELP! i got stuck showing a variable value

Post by iAnoir »

I still need help :(
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: HELP! i got stuck showing a variable value

Post by Christopher »

Thanks McInfo. I am embarrassed that I missed that! Try:

Code: Select all

$f = $_POST['name'];
if($f == 'anoir'){
	include('./anoir.php');
}
(#10850)
iAnoir
Forum Newbie
Posts: 4
Joined: Tue Apr 16, 2013 7:34 am

Re: HELP! i got stuck showing a variable value

Post by iAnoir »

I tried this method, it works, but there is a problem of the statement,
example,
if --> it include the first file
and
else if --> it include the second file and the first file stil on the same page :S Please help :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: HELP! i got stuck showing a variable value

Post by Christopher »

I don't understand the question. You might want to explain what you are trying to do. Your code does not make much sense.
(#10850)
Post Reply