Here I continue covering Web Design and Programming using all of the most used languages being HTML, CSS, JavaScript, PHP, MySQL, etc. If you missed my first video, you should watch that first Web Design and Programming part 1.
In this specific tutorial I’ll cover the following:
The code used follows the video. Use it in anyway that you like. If you have any questions or comments leave them below.
[adsense]
The Code from the Video
<html>
<head>
<title><?php echo “I have the Info”;?></title>
</head>
<body>
<?php
echo “I know everything about you “, $_POST[‘name’], “<br />”;
echo “You live here ” . $_POST[‘address’] . ” ” .$_POST[‘city’]. ” “. $_POST[‘state’] . “<br />”;
# Playing with if conditionals
echo “Did you guess my favorite number? “;
$numGuessed = (int) $_POST[‘number’];
# Compare multiple conditions with AND OR XOR (NOT PROVIDES THE OPPOSITE)
if (( $numGuessed == 5 ) AND ( $numGuessed < 11))
{
echo “You guessed it<br />”;
}
elseif ( $numGuessed > 5 )
{
echo “Too High<br />”;
}
else
{
echo “Too Low<br />”;
}
$trueCond = true;
$falseCond = false;
$condAnswer = (int) ($trueCond XOR $falseCond);
echo $condAnswer . “<br />”;
echo (int) !$condAnswer . “<br />”;
# Playing with the switch statement
$favPet = $_POST[‘pet’];
switch($favPet) {
case “Dogs” :
echo “Woof woof”;
break;
case “Cats” :
echo “Meow”;
break;
case “Fish” :
echo “Bubble”;
break;
default:
echo “Grrrr”;
}
?>
</body>
</html>
<html>
<head>
<title><?php echo “Send me your Info”;?></title>
</head>
<body>
<form action=”http://localhost/php/phptest1.php” method=”post”>
<p>Name:
<input type=”text” name=”name” size=”30″ value=”” />
</p>
<p>Address:
<input type=”text” name=”address” size=”30″ value=”” />
</p>
<p>City:
<input type=”text” name=”city” size=”25″ value=”” />
</p>
<p>State:
<input type=”text” name=”state” size=”25″ value=”” />
</p>
<p>Guess a number from 1 to 10:
<input type=”text” name=”number” size=”25″ value=”” />
</p>
<p>Cats, Dogs, or Fish?:
<input type=”text” name=”pet” size=”25″ value=”” />
</p>
<p>
<input type=”submit” name=”submit” value=”Send” />
</p>
</form>
</body>
</html>
Please, go on these tutorials, I need your web design tutorials. You are really good teacher.
I’ll continue with the tutorial today. I didn’t have an internet connection over the Thanksgiving holiday. I’m glad to be helping you 🙂
When I paste this code above into Coda as a .php file, I get this error:
unexpected T_STRING, expecting ‘,’ or ‘;’ in – on line 3
…
line 2 is:
Line 3 is the title. Not sure what the problem is because I’m sure you would have escaped any double quotes that needed escaping.
Figured it out: your quotation marks are smart quotes or something. I did a find-replace of all ” and ‘ using TextEdit and that worked.
Sorry I couldn’t get to you quicker. Yes my old posts use backquotes for security reasons. I’ve corrected that issue in my more recent work over the last few months.
I’m grateful beyond belief for what you’re doing. I learned so much playing with this code for hours. Believe it or not, this helped me figure out bits of CODA, even.
The little bit you put in there about XOR confused me at first, but I did some Googling and experimenting and now I understand XOR very well and I also learned along the way that if you echo a boolean false value, it returns an empty string unless you convert it to an integer. 🙂
I feel like working through these lessons, this stuff is really going to stick in my brain this time! Thank you!
You’re very welcome. I’m glad it is working for you. Sometimes a bit of code slips in that I forget about in the video. Very Rarely. I’m trying to figure out ways to touch on different features of the language. My stuff often becomes multi-layered because I’m not 100% sure what I’ll do in any video.
I never know how a video is going to turn out because I improvise a lot. I don’t know if that comes through or not? Some times I improvise my way through 90% of a video. That’s what makes it fun for me 🙂
Great tutorials! I’m learning so much. One thing, though… I’m not able to see the file names on screen (I’m on an oldish laptop) and had a bit of trouble making out that I needed an .html and a .php in order to get the data. I tried a number of different combinations until I finally landed on the correct solution. I now realize that the info was in the description, but failed to comprehend it at the time.
Sorry about that. I’m glad you like the tutorials. Thanks for taking the time to show your appreciation 🙂
thanks, your php tutorial is very easy to learn!! I bought the book about php programming. It was not easy to understand……your tutorial is great!
Thank you 🙂 I’m very happy to help. I’m going to improve on the PHP tutorial very soon by covering the zend framework