Help with variable

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
mfbrowne
Forum Newbie
Posts: 16
Joined: Tue May 02, 2006 11:45 am

Help with variable

Post by mfbrowne »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Being a new user of PHP I am just playing around and testing some stuff, so I appologize if my problems seem trivial.

In the code below I am trying to assign a Variable called $Test and then have the contents of the variable be placed on the Submit Button. I have tried many different variations and can't seem to get it to work as I always get $Test as the text on the button. Could someone explain to me the proper way to accomplish having the contents of the variable show on the button. I would appreciate if someone could modify the code below to show me how it is done.

Thanks very much for any information.

Code: Select all

<?php
$Test = "Submit Info" ;

echo '


<form name="Form1" form method="POST" form action="test.php"  > 
<input type="text" name="lname" size="30">   <font face="Arial" size="4">Last Name</font> 
<input type="text" name="fName" size="30">   <font face="Arial" size="4">First Name</font> 
<<input type="submit" value= "$Test" > 

';

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Single quote strings do not parse variable references contained in them, only double quote strings do that.

http://php.net/language.types.string for more information and examples.
mfbrowne
Forum Newbie
Posts: 16
Joined: Tue May 02, 2006 11:45 am

Post by mfbrowne »

Oh, I see. Well it now works. Thanks for the quick information, I appreciate it.
mfbrowne
Forum Newbie
Posts: 16
Joined: Tue May 02, 2006 11:45 am

Post by mfbrowne »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am trying to just expand on my testing a bit and it seems I am lost again.

In the following if I don't fill anything in the form and click the submit button then the page refreshes but I don't see and error message.

Am I correct in thinking the first time through the form the isset should be false, then if I leave the form blank press the submit button and the form refreshes I should see a red error message on the display because the isset should be true.

I can see this is going to be a long education at this rate.

Thanks for any help.

Code: Select all

<?php
$Test = "Submit Info" ;

if(isset($submit_button)){
	$error_msg='';

	if(trim(form.lname)=='' ) {
		$error_msg.="Please enter your Last Name<br>";
	}
	if($error_msg==''){
		
		// other process here
	} else {
		echo "<font color=red>$error_msg</font>";
	}
}

echo "


<form name='Form1' form method='POST' form action='test.php'  > 
<div align='left' style='width: 424; height: 250'><p> 
<input type='text' name='lname' size='30'>   <font face='Arial' size='4'>Last Name</font> 
<input type='text' name='fName' size='30'>   <font face='Arial' size='4'>First Name</font> 
<div align='left'><p>
<input type='submit' value= \"$Test\" name='submit_button'> 

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the data will be in $_POST
mfbrowne
Forum Newbie
Posts: 16
Joined: Tue May 02, 2006 11:45 am

Post by mfbrowne »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Wel I am totally confused now. So I changed my little test php to relect the information being received from here. Now I have a problem that is really throwing me for a loop.

So in my first test I named the submit button as submit_button and I have changed it to a new value of just 'submit'. Ok, so I figure all should be good and things should start to work. I replaced the php file and tested again.

Well if I look at the source of what the browser is receiving it is still getting the submit_button name and not the submit name. If I hit the submit button showing on the screen without filling any data into the fields then the new version shows upin the browser. Then if I hit the submit button again the script works. 

So my confusion is why is the browser still getting the first version and how to I make sure the most current version is always used.

I appologize for these trivial questions and problems and I am sure once I get over this darn hump on basic understanding then I should be better, but for right now I am really confused.

Thanks

Code: Select all

<?php
$Test = "Submit Info" ;
if(isset($_POST['submit'])){
	$error_msg='';
	if(trim($_POST['lname'])=='' ) {
		$error_msg.="Please enter your Last Name<br>";
	}
	if($error_msg==''){
		
                     header(sprintf('Location:http://localhost/Test1.php')); 
		// other process here
	} else {
		echo "<font color=red>$error_msg</font>";
	}
}

echo "

<form name='Form1'  method='POST'  action=''  > 
<div align='left' style='width: 424; height: 250'><p> 
<input type='text' name='lname' size='30'>   <font face='Arial' size='4'>Last Name</font> 
<input type='text' name='fName' size='30'>   <font face='Arial' size='4'>First Name</font> 
<div align='left'><p>
<input type='submit' name='submit' value= \"$Test\" > 
</form>";

?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your browser is pulling an old cached version of the page. Clear your cache and you should be fine.

And seriously, start using the

Code: Select all

tags please. I'm getting tired of editing your posts to add them.
mfbrowne
Forum Newbie
Posts: 16
Joined: Tue May 02, 2006 11:45 am

Post by mfbrowne »

Thanks for the reply, I appreciate it.

Sorry about the tags I didn't realize I had to put them in. I have now read the information and will follow the proper format.

So is there any way to have a statement within the PHP to make sure the cache is cleared all the time.

Thanks

Mike
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

look on the header() page, there are references to no-cache. It's not guaranteed to have the cache clear, but most browsers will follow the directive.
Post Reply