#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    15
    Rep Power
    0

    Form Validation using empty


    im validation a form using "empty() " ..but each time i try i am getting an error..

    Parse error: syntax error, unexpected '(' in C:\wamp\www\blog_blog\vv.php on line 4

    PHP Code:
    <?php

    $error
    =array(); 
    if(empty( (
    $_POST['name']), ($_POST['email']) ))
    {
    $error[]="All fields should be filled";
    }

    else
    {
    echo 
    "all set";
    }
    if(
    count($error)>0)
    {
    foreach( 
    $error as $err)
    {
    echo 
    $err;
    }
    }

    ?>
    how can i get rid of it?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,622
    Rep Power
    595
    The empty function accepts a single variable not a list.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2014
    Posts
    4
    Rep Power
    0
    Originally Posted by looner_flitz
    im validation a form using "empty() " ..but each time i try i am getting an error..

    Parse error: syntax error, unexpected '(' in C:\wamp\www\blog_blog\vv.php on line 4

    PHP Code:
    <?php

    $error
    =array(); 
    if(empty( (
    $_POST['name']), ($_POST['email']) ))
    {
    $error[]="All fields should be filled";
    }

    else
    {
    echo 
    "all set";
    }
    if(
    count($error)>0)
    {
    foreach( 
    $error as $err)
    {
    echo 
    $err;
    }
    }

    ?>
    how can i get rid of it?

    test
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2014
    Posts
    4
    Rep Power
    0
    <?php

    $error=array();
    if(empty( ($_POST['name']), ($_POST['email']) ))
    {
    $error[]="All fields should be filled";
    }

    else
    {
    echo "all set";
    }
    if(count($error)>0)
    {
    foreach( $error as $err)
    {
    echo $err;
    }
    }

    ?>
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2014
    Posts
    4
    Rep Power
    0

    dawdawd


    PHP Code:
    testdadjawdhadahwd[CPAN][/CPAN
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2014
    Posts
    4
    Rep Power
    0

    cide


    PHP Code:
    <?php

    $error
    =array(); 
    if(empty( (
    $_POST['name']), ($_POST['email']) ))
    {
    $error[]="All fields should be filled";
    }

    else
    {
    echo 
    "all set";
    }
    if(
    count($error)>0)
    {
    foreach( 
    $error as $err)
    {
    echo 
    $err;
    }
    }

    ?>

    Comments on this post

    • paulh1983 disagrees : please stop spamming.. use EDIT to edit your post
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,031
    Rep Power
    377
    stop spamming.. and your answer is still wrong..

    if ( empty($field) || empty($field2) ) {
    //all fields should be filled;
    }

    using spaces help you see where brackets start/end.. etc
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2014
    Posts
    19
    Rep Power
    0
    <!DOCTYPE HTML>
    <html>
    <head>
    <style>
    .error {color: #444444;}
    </style>
    </head>
    <body>

    <?php
    // define variables and set to empty values
    $nameErr = $emailErr = "";
    $name = $email = "";

    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (empty($_POST["name"])) {
    $nameErr = "Name is required";
    } else {
    $name = test_input($_POST["name"]);
    }

    if (empty($_POST["email"])) {
    $emailErr = "Email is required";
    } else {
    $email = test_input($_POST["email"]);
    }



    function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
    }
    ?>

    <h2>PHP Form Validation Example</h2>
    <p><span class="error">* required field.</span></p>
    <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
    Name: <input type="text" name="name">
    <span class="error">* <?php echo $nameErr;?></span>
    <br><br>
    E-mail: <input type="text" name="email">
    <span class="error">* <?php echo $emailErr;?></span>
    <br><br>

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

    </body>
    </html>
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,622
    Rep Power
    595
    F5buddy: Read the sticky at the top of this forum that says READ THIS BEFORE POSTING.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2014
    Posts
    1
    Rep Power
    0
    Please try this below code

    <?php

    $error=array();
    if(empty( ($_POST['name']), ($_POST['email']) ))
    {
    $error[]="All fields should be filled";
    }

    else
    {
    echo "all set";
    }
    if(count($error)>0)
    {
    foreach( $error as $err)
    {
    echo $err;
    }
    }

    ?>

    if anybody know mobile-application please find it

IMN logo majestic logo threadwatch logo seochat tools logo