$_post is empty!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
benjie500
Forum Newbie
Posts: 3
Joined: Mon Jul 28, 2008 5:46 am

$_post is empty!

Post by benjie500 »

Hi!
I am trying to create a user registration page. I have created the registration form called "register.html". This is where the user enter the information. When the user press submit it should put that information into the post array and direct the user to add_user.php. Currently this isn't finished and only checks if data has been entered into the form. But it always says that there is no data in the post array.

Here is the code for register.html

Code: Select all

<html>
<head>
<title>Registration</title>
</head>
<body>
<font size="3" face="Arial" color="red">
<h1>Registration page</h1>
Welcome to my site this is the registration page for access to exclusive news and features.<br>
    <form action="add_user.php" method=post>
    <label for="username">Username:</label>
    <input type="text" name="username" id="username"><br>
    <label for="password">password:</label>
    <input type="password" name="password" id="password"><br>
    <label for="confirm_password">Confirm password:</label>
    <input type="password" name="confirm_password" id="confirm_password"><br>
    <label for="full_name">Full name:</label>
    <input type="text" name="full_name" id="full_name"><br>
    <label for="email1">Email address:</label>
    <input type="text" name="email1" id="email1"><br>
    <lael for="email2">Confirm Email Address</label>
    <input type="text" name="email2" id="email2">
    <br>
    <input type="submit" value="submit">
    </form>
</html>
Here is the code for add_user.php

Code: Select all

<?
//connect to mysql and select database
    include 'C:\webserver\include\login\connect.php';
//checks if info has been put into each field if one field has no info echo and die
    if (($_post['username']==false)||($_post['password']==false)||
    ($_post['confirm_password']==false)||($_post['full_name']==false)||
    ($_post['email1']==false)||($_post['email2']==false))
        {echo "Please fill in all fields.";
        include 'register.php'
        ;die();}
    ?>
This always returns line 8,9 and 10. Please could someone help me!!


Thanks

Ben
User avatar
deejay
Forum Contributor
Posts: 201
Joined: Wed Jan 22, 2003 3:33 am
Location: Cornwall

Re: $_post is empty!

Post by deejay »

i'd have thought it'd be something to do with your form. To be honest I haven't the type of syntax your using . I'm pretty sure if you used something like

Code: Select all

 
  <tr>
     <td >Email Address:</td>
     <td><input type=text name="email" size="20" value=""></td>
    </tr>
        <tr>
     <td >Password:</td>
     <td><input type=password name="pwd" size="20"></td>
    </tr>
 

it'd send over with _POST, obviously you need to change the input names etc here.
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: $_post is empty!

Post by EverLearning »

In PHP variable names are case sesitive, so $_post is NOT the same as $_POST.
Change your code to check $_POST array values and it should work
benjie500
Forum Newbie
Posts: 3
Joined: Mon Jul 28, 2008 5:46 am

Re: $_post is empty!

Post by benjie500 »

Hi!
It still doesnt work! My code looks like:
register.html

Code: Select all

<html>
<head>
<title>Registration</title>
</head>
<body>
<font size="3" face="Arial" color="red">
<h1>Registration page</h1>
Welcome to my site this is the registration page for access to exclusive news and features.<br>
    <form action="add_user.php" method=post>
    Username:
    <input type="text" name="username" size="20" value=""><br>
    password:
    <input type="password" name="password" size="20" value=""><br>
    Confirm password:
    <input type="password" name="confirm_password" size="20" value=""><br>
    Full name:
    <input type="text" name="full_name" size="20" value=""><br>
    Email address:
    <input type="text" name="email1" size="20" value=""><br>
    Confirm Email Address
    <input type="text" name="email2" size="20" value="">
    <br>
    <input type="submit" value="submit">
    </form>
</html>
Add user has only been changed from any $_post to $_POSTand it still doesnt work!! :banghead:
mabwi
Forum Commoner
Posts: 27
Joined: Wed Aug 01, 2007 4:51 pm

Re: $_post is empty!

Post by mabwi »

Try doing a print_r($_POST); at the start of adduser.php

Also, instead of $_POST['password'] == false, try

Code: Select all

if (empty($_POST['password']))
and son on, with all the variables.
User avatar
EverLearning
Forum Contributor
Posts: 282
Joined: Sat Feb 23, 2008 3:49 am
Location: Niš, Serbia

Re: $_post is empty!

Post by EverLearning »

Your code (register.html and add_user.php with $_POST) works fine on my machine. When I enter all the values I dont get the 'Please fill in all fields' as you initially complained in your post.

Also, listen to mabwi's advice in previous post.
benjie500
Forum Newbie
Posts: 3
Joined: Mon Jul 28, 2008 5:46 am

Re: $_post is empty!

Post by benjie500 »

:D
I just went to change the add_user.php and i realised that i made a typo lol :oops: and infact I did need to change $_post to $_POST.

Thanks for all the great advice!

Ben
Post Reply