Simple talk script

By jackster35-1 on May 10, 2010

Hi, this is a simple PHP script witch will say what you put in the text boxes! Just open notepad and put this code in, make sure you save it as "talk.php" or it wont work. Once done, upload to your FTP server. And it should work! Have fun!!

<html>  
<body>      
<!-- Form -->
<form action="talk.php" method="POST">      
Text1:<input type="text" name="text1"><br>          
Text2:<input type="text" name="text2"><br>          
<input type="submit" name="submit" value="Say!">        
</form>     
</body>
</html>
<?php
//Text generator code 
if ($_POST['submit'])
{
$text1 = $_POST['text1'];
$text2 = $_POST['text2'];
if ($text1&&$text2)
{   
echo "Text1: " . $text1 . "<br>";
echo "Text2: " . $text2 . "<br>";
}
else    
die("Please fill in all boxes!");
}
?>

Comments

Sign in to comment.
shaneny   -  Jul 10, 2010

This script is cool, and helps you learn the basic's of PHP, but again, the script is pretty much pointless

 Respond  
sean   -  Jun 06, 2010

just as a reference, check out http://php.net/manual/en/function.extract.php
through rather redundant in this snippet, it'll save you from renaming your vars if using the array index as a name scheme.

I'd personally use single quotes instead of doubles in your echo statements as you're not using any line returns etc. and there's no reason to use die() considering it's at the very end of this snippet, an echo would suffice

otherwise nice starter. look forward to seeing more php :)
i voted 4/10 for mediocre ( we really need a better voting system )

 Respond  
Jonesy44   -  May 11, 2010

'gratz. it's a good start :) like Hawkee said not much practical use but a good example of how POST is used :)

 Respond  
jackster35-1   -  May 11, 2010

I know, its for people new to php they can figure the code out and it will teach them the basic of $_POST

 Respond  
Hawkee   -  May 10, 2010

Works as an example for collecting form inputs, but it doesn't quite have any practical use.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.