[PHP] Trouble with an If Statement

Soldato
Joined
12 Jun 2005
Posts
5,361
Hi there,

I am having a little trouble with an IF statement and PHP, I can't show you want I am doing as its being done locally but I will post the code.

The problem is, that whenever I run the IF statement, under both conditions (yes and no) it runs whats in the If Statement if the condition is yes.

Here is the posting page (I know its not valid because i quick coded it but im sure that isnt the problem)

index.html said:
<html>
<head>
<title>Title</title>
</head>
<body>
<div>
<h1>Header</h1>
<form method="POST" action="proc.php">
<p>S1*: <input type="text" name="s1" size="40" maxlength="40"></p>
<p>S2: <input type="text" name="s2" size="40" maxlength="40"></p>
<p>S3: <input type="text" name="s3" size="40" maxlength="40"></p>
<p>S4: <input type="text" name="s4" size="40" maxlength="40"></p>
<p>S5: <input type="text" name="s5" size="40" maxlength="40"></p>
<p><input type="submit" value="Submit" name="sumbitted" /></p>
</form>
<p>Fields marked (*) are required</p>
<p><a href="../index.php">Back to Navigation</a></p>
</div>
</body>
</html>

Here is the processing PHP page

proc.php said:
<?php

if($s1=='')
{
echo "Nothing Typed In!";
exit;
} else {
echo "Do Stuff";
}

?>

What's the problem as it is not obvious to me?

Thanks...
 
You are depending upon register_globals. Stop.

Use the $_POST superglobal, ala:
Code:
<?php

if (!isset($_POST['s1']) || empty($_POST['s1'])) {
  //field was either not submitted (no value) or was submitted blank
}

?>
 
Beansprout said:
if($s1=='') >>> if($s1 == "")

Lol, well thats a first.....didn't work :D



Dj_Jestar said:
You are depending upon register_globals. Stop.

Use the $_POST superglobal, ala:
Code:
<?php

if (!isset($_POST['s1']) || empty($_POST['s1'])) {
  //field was either not submitted (no value) or was submitted blank
}

?>

However, this did work, thanks :)
 
The reason it didn't work was because it seems you have register_globals disabled, but you coded it that way so I assumed you did, hence I just corrected syntax :)

In other words, I didn't want to give you the whole answer, rather prod you...I'm a meanie :D
 
Back
Top Bottom