Hi guys.
I am at a stage in my learning where I am feeling confident enough to experiment and set myself little tasks while coding.
I am trying to do something which, in theory, should work perfectly fine but it doesn't.
Below is document 1:
<html>
<head>
</head>
<body>
<form action="practice1.php" method="post">
<br><label for="fname">First name:</label>
<input type="text" name="fname" value=""><br><br>
<input type="submit" value="send"><br><br>
</form>
</body>
</html>
..... this is just a simple form.
and below is document 2:
<html>
<head>
<title>Practice PHP</title>
</head>
<body>
<p>Firstname:</p>
<?php
if(isset($_POST["fname"])) {
if(is_int($_POST["fname"])) {
echo "you must enter a sentence. Please try again";
} else {
echo $_POST["fname"];
}
}
?>
</body>
</html>
When the 'text field' in 'doc 1' has been filled in, and the info has been transfered to 'doc 2', I use a couple of if statements. The outer if statement works just fine, but the inner if statement will not function as I imagined.
Inside the inner 'if statement', I clearly check to see if the data type contained in the $_POST superglobal is an interger (by using the is_int() function).
But when I try to type an integer in the field and press send, I do not get the expected: "you must enter a sentence. Please try again" comment.
Instead, it just displays whatever I typed in, in the text field from 'doc 1'.
Can someone tell me where I am going wrong?
Paul.