Jump to content

If statment doesn't work


phpagent

Recommended Posts

Hi all,

New at the forum but i am freak for php but i have this strage problem with code.. I'm sure that it should work but i can't see whats missing part in my if statement.

Can't be simpler that this, any idea?

 

<html>
<head>

<title><?php echo "Form Test";?></title>
<?PHP
$City = $_POST['City'];
if ($City = "New York") {
print ("Cool city!");
}
else {
print ("Write some other city");
}
?>
</head>
   <body>
	<FORM NAME ="City Searcher" METHOD ="pOST" ACTION = "">
<INPUT TYPE = "Enter city" VALUE ="City" NAME = "City">
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Search">
</FORM>	
    </body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/244691-if-statment-doesnt-work/
Share on other sites

I modified your code & now its working...

 

<?php
echo '<html>
<head>
<title>Form Test</title>';
if($_SERVER['REQUEST_METHOD']=='POST') {
$City = $_POST['City'];
if ($City == "New York") {
echo "Cool city!";
}
else {
echo "Write some other city";
}
}
echo '</head>
<body>
<FORM NAME ="City Searcher" METHOD ="POST" ACTION = "">
<INPUT TYPE = "TEXT" NAME = "City" VALUE = "City">
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Search">
</FORM>	
</body>
</html>';
?>

Just for fun:

<?php
$content = <<<'NOWDOC'
<html>
<head>
<title>Form Test</title>
NOWDOC;

if(isset($_POST['Submit1'])) {
$city = (!empty($_POST['City']) && strtolower($_POST['City']) == 'new york') ? 'Cool City!' : 'Try Another City';
}
$content = <<<HEREDOC
</head>
<body>
<FORM NAME ="City Searcher" METHOD ="POST" ACTION = "">
<INPUT TYPE = "TEXT" NAME = "City" VALUE = "City"> 
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Search">
</FORM>	
<br /><span style="color:red;font-size:200%">{$city}</span>
</body>
</html>
HEREDOC;

echo $content;
?>

 

Only works in >= PHP5.3.0

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.