Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.