SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question “Build Your Own Database Driven Web Site Using PHP & MySQL" Chapter 3

    Hello,

    I am currently working on Chapter 3 in the book “Build Your Own Database Driven Web Site Using PHP & MySQL”. I am on the section that discusses Templates, One Controller and I am unable to get the examples in the book to work properly.

    When I view the 'welcome' examples in my browsers (chrome and safari) the first name: and last name: inputfields appear however after filling out the form and hit the 'go' button nothing happens.

    Here is the code:

    index.php:

    Code:
    <?php
    if (!isset($_REQUEST['first name']))
    {
    include 'form.html.php';
    }
    else
    {
    $firstname = $_REQUEST['firstname'];
    $lastname = $_REQUEST['lastname'];
    if ($firstname == 'Kevin' and $lastname == 'Yank')
    {
    $output = 'Welcome, oh glorious leader!';
    }
    else
    {
    $output = 'Welcome to our web site, ' .
    htmlspecialchars($firstname, ENT_QUOTES, 'UTF-8') . ' ' .
    htmlspecialchars($lastname, ENT_QUOTES, 'UTF-8') . '!';
    }
    include 'welcome.html.php';
    }
    ?>

    form.html.php

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>Form Example</title>
    <meta http-equiv="content-type"
    content="text/html; charset=utf-8"/>
    </head>
    <body>
    <form action="" method="post">
    <div><label for="first name">First name:
    <input type="text" name="first name" id="first name"/></label>
    </div>
    <div><label for="lastname">Last name:
    <input type="text" name="lastname" id="lastname"/></label>
    </div>
    <div><input type="submit" value="GO"/></div>
    </form>
    </body>
    </html>
    welcome.html.php

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <title>Form Example</title>
    <meta http-equiv="content-type"
    content="text/html; charset=utf-8"/>
    </head>
    <body>
    <p>
    <?php echo $output; ?>
    </p>
    </body>
    </html>

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,117
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Hi jrealist. Welcome to SitePoint.

    This is not really my area, but I'll just make this point:

    Have a look at this code:

    Code:
    <input type="text" name="first name" id="first name"/>
    You can't have a gap in an id name (and probably name attribute also), so firstly try removing all those gaps and see if the form works any better. If not, it might be worth moving this thread to the PHP forum. Let us know how you go.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  3. #3
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ralph.m that fixed the problem! Thank you!

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,117
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    Great! Glad to hear it.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •