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

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    Need help for basic php form


    I'm start learning php and i face problem in my form please any one help me
    my php file's cod
    <?php
    //retrive from data
    $username=$_POST['username'];
    $country=$_POST=['country'];
    $posts=$_POST=['posts'];
    $mood=$_POST=['mood'];
    //use it
    echo "User Name:<strong>$username</strong><br/>";
    echo "Flag:<strong>$country</strong><br/>";
    echo "No of Posts:<strong>$posts</strong><br/>";
    echo "Mood:<strong>$mood</strong><br/>";
    ?>
    ("message.php")
    and HTML file's code is

    <form action="message.php" method="post">
    Enter Your User Name:<input type="text" name="username" size="30"><br/>
    No Posts: <input type="text" name="posts" size="30"><br/>
    Flag: <input type="text" name="country" size="30"><br/>
    Mood: <input type="text" name"mood" size="30"><br/>
    <input type="submit" value="send">
    </form>

    when i triger it display this error

    User Name:Muhammad

    Notice: Array to string conversion in C:\xampp\htdocs\learn\message.php on line 13
    Flag:Array

    Notice: Array to string conversion in C:\xampp\htdocs\learn\message.php on line 14
    No of Posts:Array

    Notice: Array to string conversion in C:\xampp\htdocs\learn\message.php on line 15
    Mood:Array

    How i remove this error?
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,555
    Rep Power
    2338
    Why the = after $_POST here?

    Code:
    $country=$_POST=['country'];
    $posts=$_POST=['posts'];
    $mood=$_POST=['mood'];
    You got it right on the first one

    Code:
    $username=$_POST['username'];
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Burb of Detroit, Michigan
    Posts
    92
    Rep Power
    78
    PHP Code:
    <?php
    // Only process user input if form is submitted:
    // Also prevent unindentified index errors---->
    if (isset($_POST['action']) && $_POST['action'] == 'enter') {
        
    // Assign the attributes/variables from user input:
        
    $username=$_POST['username'];
        
    $country=$_POST['country'];
        
    $posts=$_POST['posts'];
        
    $mood $_POST['mood'];
        
        
    // Display the returned values:
        
    echo "User Name:<strong>$username</strong><br/>";
        echo 
    "Flag:<strong>$country</strong><br/>";
        echo 
    "No of Posts:<strong>$posts</strong><br/>";
        echo 
    "Mood:<strong>{$mood}</strong><br/>";
    }
    ?>
    <form action="user-form-01.php" method="post">
    <!--While the submit type is still needed this is more reliable-->
    <input type="hidden" name="action" value="enter">

    Enter Your User Name:<input type="text" name="username" size="30"><br/>
    No Posts: <input type="text" name="posts" size="30"><br/>
    Flag: <input type="text" name="country" size="30"><br/>
    Mood: <input type="text" name="mood" size="30"><br/>
    <input type="submit" value="send">
    </form>
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0
    Thank you sir
    you check my code deeply thanks
    please help for one more error display I can't understand what is?

    My code display
    [
    Notice: Undefined index: mymood in C:\xampp\htdocs\learn\message.php on line 10
    User Name:Muhammad
    Flag:Pakistan
    No of Posts:1023
    Mood:

    ]

    and my 10 line of code is
    $mood=$_POST['mood'];
  8. #5
  9. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    The error messages implies that you have something like this:
    PHP Code:
    $mood $_POST['mymood']; 
    Where $_POST['mymood'] has not been defined. The error message does not indicate that the array name is $_POST, so it could be something like $myarray['mymood'] instead. In any case, what the error message means is that you are attempting to access an array index called 'mymood' which has not been defined.

    You can check whether a particular array index has been set without causing an error using isset($_POST['mymood']) or empty($_POST['mymood']). Note that the first check whether the variable has been defined and is not null, while the second checks whether the variable is "empty".
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo