Jump to content

judeur

New Members
  • Posts

    3
  • Joined

  • Last visited

Posts posted by judeur

  1. Looks like the issue is with this line:

     

    echo "<div style='padding:4px; border:1px solid red; color:red" . $error . "</div>";

    You're missing a "'>" after "red" to close the div before you show the error message.

     

    It should be like this:

     

    echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error . "</div>";

     

    Of course, I should have seen that myself.

     

    Thanks so much!

  2. if ($firstname == '' || $lastname == '')

     

    try changing this to:

     

    if ((!isset($firstname)) || (!isset($lastname)))
    {

     

     

    Thanks for suggestion; didn't work, though -no error, just empty page....

  3. I've been following the video's to the letter, literally :) , but still don't get the error message when not all fields in the form are filled in.

    Here is my code (but, if it's easier for you, send me yours and I'll be able to figure it out by myself).

    Thanks,

    judith

     

    records.php

     

    <?php

     

    function renderForm($first = '', $last = '' , $error = '', $id = '')

     

    { ?>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

    <html>

    <head>

    <title>

    <?php

    if ($id !='')

    {

    echo "Edit Record";

    }

    else

    {

    echo "New Record";

    }

    ?>

    </title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    </head>

    <body>

    <h1>

    <?php

    if ($id !='')

    {

    echo "Edit Record";

    }

    else

    {

    echo "New Record";

    }

    ?>

    </h1>

    <?php

    if ($error !='')

    {

    echo "<div style='padding:4px; border:1px solid red; color:red" . $error . "</div>";

    }

    ?>

    <form action="" method="post">

    <div>

    <?php

    if ($id != ''){ ?>

    <input type="hidden" name="id" value="<?php echo $id;?>" />

    <p>ID: <?php echo $id; ?></p>

    <?php }

    ?>

    <strong> First name: *</strong> <input type="text" name="firstname"

    value="<?php echo $first; ?>" /> <br />

    <strong> Last name: *</strong> <input type="text" name="lastname"

    value="<?php echo $last; ?>" />

    <p>* required </p>

    <input type="submit" name="submit" value="submit" />

    </div>

    </form>

    </body>

    </html>

    <?php }

     

    if (isset($_GET['id']))

    {

    //echo "id is set"; //TEST

    //editing existing record

    renderForm(NULL, NULL, NULL, $_GET['id']);

    }

    else

    {

    //echo "id is not set"; //TEST

    //creating new record

    if (isset($_POST['submit']))

    {

     

    $firstname = htmlentities($_POST['firstname'], ENT_QUOTES);

    $lastname = htmlentities($_POST['lastname'], ENT_QUOTES);

     

    if ($firstname == '' || $lastname == '')

    {

    $error = 'ERROR: please fill in all required fields';

    renderForm($firstname, $lastname, $error); //if the user entered one of the fields, he doesn't lose that

    }

    }

    else

    {

    renderForm();

    }

     

    }

     

    ?>

×
×
  • Create New...