Web Design and Programming Pt 2 PHP & HTML

Help Web Design and ProgrammingHere 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:

  • How to access html form data with PHP
  • How to use if conditional statements in PHP
  • How to use the Switch statement in PHP
  • And more…

The code used follows the video. Use it in anyway that you like. If you have any questions or comments leave them below.


The Code from the Video

<title><?php echo “I have the Info”;?></title>
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 />”;
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”;
case “Cats” :
echo “Meow”;
case “Fish” :
echo “Bubble”;
echo “Grrrr”;

<title><?php echo “Send me your Info”;?></title>
<form action=”http://localhost/php/phptest1.php” method=”post”>

<input type=”text” name=”name” size=”30″ value=”” />

<input type=”text” name=”address” size=”30″ value=”” />

<input type=”text” name=”city” size=”25″ value=”” />

<input type=”text” name=”state” size=”25″ value=”” />

<p>Guess a number from 1 to 10:
<input type=”text” name=”number” size=”25″ value=”” />

<p>Cats, Dogs, or Fish?:
<input type=”text” name=”pet” size=”25″ value=”” />

<input type=”submit” name=”submit” value=”Send” />


12 Responses to “Web Design and Programming Pt 2 PHP & HTML”

  1. Please, go on these tutorials, I need your web design tutorials. You are really good teacher.

  2. nate says:

    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:

    • nate says:

      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.

  3. nate says:

    Figured it out: your quotation marks are smart quotes or something. I did a find-replace of all ” and ‘ using TextEdit and that worked.

    • admin says:

      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.

      • nate says:

        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!

        • admin says:

          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 🙂

  4. Steve Arthur says:

    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.

  5. dikien says:

    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!

Leave a Reply

Your email address will not be published.