Grow your CSS skills. Land your dream job.

Form validation!

  • # December 30, 2009 at 8:32 pm

    Hi, while this form doesnt return an error message, it wont validate the field ‘ video_ID ‘ which is required but even if you leave it blank nothing happens, it will send it to the database anyway. I want the error message to appear on the form submission page heres the code:

    html page

    Code:
    < ?php echo $error; ?>
    Details:

    Your initials:

    Video embeded code:



    php form process page (insert.php)

    Code:
    < ?php
    if ($video_ID="")
    { $error = "You must complete all required fields"; }

    $con = mysql_connect("*****","*******","**********");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("******", $con);

    $sql="INSERT INTO video (video_ID, video_url)
    VALUES
    ('$_POST[video_ID]','$_POST[video_url]')";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "1 record added";

    mysql_close($con)
    ?>

    Thanks in advance

    # December 31, 2009 at 11:10 am

    I’m guessing that since you use the POST array during your query, the reason it’s not validating is because you’re not using the array during your validation:

    Code:
    if ($POST['video_ID']=””)
    # January 1, 2010 at 6:47 pm

    ive implimented that as this:

    Code:
    < ?php
    // required fields in the line below
    if ($POST['video__ID]="")
    { $error = "You must complete all required fields"; }

    // Code to do something with the data here

    $con = mysql_connect("*********");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("*****", $con);

    $sql="INSERT INTO video (video_ID, video_url)
    VALUES
    ('$_POST[video_ID]','$_POST[video_url]')";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "1 record added";

    mysql_close($con)
    ?>

    but still returns the same :S

    # January 1, 2010 at 7:40 pm

    You are missing an ‘=’ and an ‘_’ in your code.

    Code:
    if ($_POST['video__ID]==””)
    { $error = “You must complete all required fields”; }
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".