Jump to content

My code is a world issue


Spiew

Recommended Posts

Hello,

 

 

Just to mention, I started with PHP in february I think.

 

Now I've come across a problem that none of my friends can help me solve, so I thought of posting it here in hope of saving my life.

 

I'm making a registrationscript.

 

This is my code:

login.php - http://pastebin.com/RDhHFX3t

functions.php - http://pastebin.com/mMRxxwqC

 

The problem I have, is that it never gets through. It always shows the else message in the login.php file which is "Populate all the fucking fields."

 

Please, save my life by helping me solve this problem. If I ever get the opportunity to meet you who solved this, I'll hug you.

 

Peace!

 

 

 

Link to comment
Share on other sites

In the future, please post just the relevant code here, in code tags.

You also need to better describe your problem. What "never gets through"? What part of your code is the problem?

 

Try some debugging by doing a print_r($_POST) before your if(isset()) part, and see just what part isn't set.

Also use && not and.

Link to comment
Share on other sites

you need to troubleshoot WHY your code is not doing what you expect. you know, actually examine the values that are being tested that cause it to take the execution branch that it is.

 

i'll give you a hint, you have far too much logic. you need just the right amount of logic, not too little or too much (edit: because typing or copy/pasting excess amounts of code often leads to mistakes and you have one in a post variable name.)

 

text/textarea from fields that have been submitted will be set. once you test that your form has been submitted, with if (isset($_POST['register'])) {, you don't need to test if each field is set and if your fields are all required, you should individually test if each one contains expected content and output a specific error message for each one that doesn't.

Edited by mac_gyver
Link to comment
Share on other sites

In the future, please post just the relevant code here, in code tags.

You also need to better describe your problem. What "never gets through"? What part of your code is the problem?

 

Try some debugging by doing a print_r($_POST) before your if(isset()) part, and see just what part isn't set.

Also use && not and.

Uhmkay, Changed to &&.

 

And I've already done print_r($_POST) and it shows 

Array ( [first_name] => first [last_name] => last => test@gadaw.com [password] => hej [password_repeat] => hej [country] => Barbados [city] => city [zip_code] => 23232 [billing_address] => hemma [mobile_number] => 2323232 [register] => Register )

 

 

 

you need to troubleshoot WHY your code is not doing what you expect. you know, actually examine the values that are being tested that cause it to take the execution branch that it is.

 

i'll give you a hint, you have far too much logic. you need just the right amount of logic, not too little or too much (edit: because typing or copy/pasting excess amounts of code often leads to mistakes and you have one in a post variable name.)

 

text/textarea from fields that have been submitted will be set. once you test that your form has been submitted, with if (isset($_POST['register'])) {, you don't need to test if each field is set and if your fields are all required, you should individually test if each one contains expected content and output a specific error message for each one that doesn't.

 

So you mean I should remove all the 

if (isset($_POST['first_name'], $_POST['last_name'].....................

because it's not needed?

 

Don't I have to change my function also then? Or shall I keep it as it is?

register_user($_POST['first_name'], $_POST['last_name']................

 

 

Thanks for the answers so far

Link to comment
Share on other sites

What is meant is, if 1 variable from the form is set, then all the variables will be set. You need to make sure the form is sending the variables though, but that is where sanitation and validation comes into play.

Link to comment
Share on other sites

I often find that when seeking help from people who volunteer their time that it is often best to be pleasant and listen to what they say. Sometimes they do know more than you do (surprisingly!). 

 

On the basis of your last post, I would refuse to help you anymore.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.