Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-04-2013, 12:22 PM   PM User | #1
countrydj
Regular Coder

 
Join Date: Nov 2011
Location: Preston, UK
Posts: 130
Thanks: 36
Thanked 0 Times in 0 Posts
countrydj is an unknown quantity at this point
Change $_REQUEST to $_POST problem

On advice, I am changing all my $_REQUEST to $_POST.

My form is:
Code:
<form action="register-exec.php" target="new" method="POST">
My register-exec.php (receiving script) is:
Code:
<?php
	//Start session
	session_start();
	
	//Include database connection details
	require_once('config.php');

$from = $_REQUEST['email'];

$action = $_REQUEST['action'];
When I change it to:
Code:
<?php
	//Start session
	session_start();
	
	//Include database connection details
	require_once('config.php');

$from = $_POST['email'];

$action = $_POST['action'];
nothing gets through. I just get a blank screen.

If I set a trap:
Code:
echo $email; exit;
I get a blank screen.
Code:
echo "Hello World"; exit;
I get Hello World echoed.

Can anybody think of what I am doing wrong ???

I have checked other scripts that I have changed and can't find any difference.

Thanks
__________________
The MAN, The MYTH, The LEGEND:
John C
________________________________
Support your local Country Music Club
countrydj is offline   Reply With Quote
Old 02-04-2013, 03:44 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
$email isn't declared as anything, so that provides no surprise that it produces no output.
Enable your error reporting:
PHP Code:
ini_set('display_errors'1);
error_reporting(E_ALL); 
You can check the $_POST using var_dump($_POST); to see what's in it. If its empty, it's not receiving post, which indicates that it is receiving a $_GET instead. Did you modify the form action there as well, or was that always post?

Also, this hasn't a thing to do with Mysql. Moving to PHP forum.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-04-2013, 08:38 PM   PM User | #3
countrydj
Regular Coder

 
Join Date: Nov 2011
Location: Preston, UK
Posts: 130
Thanks: 36
Thanked 0 Times in 0 Posts
countrydj is an unknown quantity at this point
Hi Fou-Lu..

Many thanks, once again.
Firstly, let me apologise for posting in the wrong forum. I do get confused when the php objective is to populate the mysql database.

Secondly, sorry I misled you with $email. That was actually declared lower down the list (I only showed part of the list to save space.

However, I have obviously confused myself because this is not the problem.

The script is a double opt-in email catcher.
i.e. the subscriber fills in the form and the script sends out an email to the subscriber to verify the correct email address. The subscriber then clicks on a link in the email which then adds the data to the database.

The problem is NOT sending out the email, it is AFTER the subscriber clicks on the link. This is the link that is sent out to the subscriber:
PHP Code:
//////// SEND SUBSCRIBE VALIDATION EMAIL

    
$mail_body "Please DO NOT reply to this email. It is an unattended mailbox.\n\nTo validate your email address, please click the following link:\n\nhttp://countrymusic.org.uk/calendar/register-exec.php?email=$from&emailcount=$emailcount&act=$active&action=subscribe&fname=$fname&surname=$surname&country=$country&year=$year&m=$hashed";

    
mail($from"Validation Email"$mail_body"From: noreply@countrymusic.org.uk\n"); 
This is the email that the subscriber receives:
Quote:
Please DO NOT reply to this email. It is an unattended mailbox.

To validate your email address, please click the following link:

countrymusic.org.uk/calendar/register-exec.php?email=jc1@in-uk.co.uk&emailcount=1&act=1&action=subscribe&fname=John&surname=Craven&country=UK&year=2013&m=7d2263 650cde3c8a1f5744414de3a748
NB. I have removed the http\\ from the front of the link. I insisted on making it a link with it there.

I notice in here that there is no indication of method=POST.

This script worked perfectly well using $_REQUEST

Now that I have sorted my brain, can you help ???

Thanks
__________________
The MAN, The MYTH, The LEGEND:
John C
________________________________
Support your local Country Music Club
countrydj is offline   Reply With Quote
Old 02-04-2013, 09:08 PM   PM User | #4
TFlan
New Coder

 
Join Date: Dec 2012
Location: USA
Posts: 82
Thanks: 3
Thanked 17 Times in 17 Posts
TFlan is an unknown quantity at this point
Quote:
I notice in here that there is no indication of method=POST.

This script worked perfectly well using $_REQUEST
You have solved your own problem...

The $_REQUEST array includes $_GET, $_POST, and $_COOKIE

You are utilizing $_POST for the form submission and $_GET for the link.

To get the information held in the URL query string, you need to use $_GET, not $_POST

IE:
PHP Code:
// Link: http://countrymusic.org.uk/calendar/register-exec.php?email=jc1@in-uk.co.uk&emailcount=1&act=1&action=subscribe&fname=John&surname=Craven&country=UK&year=2013&m=7d2263 650cde3c8a1f5744414de3a748
$email $_GET['email']; // jc1@in-uk.co.uk 
TFlan is offline   Reply With Quote
Users who have thanked TFlan for this post:
countrydj (02-05-2013)
Old 02-04-2013, 10:03 PM   PM User | #5
countrydj
Regular Coder

 
Join Date: Nov 2011
Location: Preston, UK
Posts: 130
Thanks: 36
Thanked 0 Times in 0 Posts
countrydj is an unknown quantity at this point
Hi TFlan ...
Thank you so much for your help.

That worked fine.

I must admit, I don't really know when to use POST and when to use GET.
Is there a rule of thumb ???

How do you know that I am using GET for the string.
Is this always the case ???

Thanks again...
__________________
The MAN, The MYTH, The LEGEND:
John C
________________________________
Support your local Country Music Club
countrydj is offline   Reply With Quote
Old 02-05-2013, 01:24 AM   PM User | #6
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by countrydj View Post
I must admit, I don't really know when to use POST and when to use GET.
Is there a rule of thumb ???.
When the data is passed in a querystring (that is after a ? as part of a web address) then you read it using $_GET.

If the data is being passed from a form that has method="POST" then you read it using $_POST.

Note that in both cases you should validate the content received looks reasonable before moving it to another field for subsequent processing by your code - preferably validation but at least sanitize the data before moving it. That way you keep the tainted fields separated from the untainted ones.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
countrydj (02-05-2013)
Old 02-05-2013, 10:10 AM   PM User | #7
countrydj
Regular Coder

 
Join Date: Nov 2011
Location: Preston, UK
Posts: 130
Thanks: 36
Thanked 0 Times in 0 Posts
countrydj is an unknown quantity at this point
Hi felgall ...

Thanks very much for your explanation. This makes it a lot clearer.

I changed all my POSTs and GETs some years ago when I read that REQUEST was the best.
Recently I have read that REQUEST shouldn't be used so I am changing it all back. Slowly.

Thanks again.
__________________
The MAN, The MYTH, The LEGEND:
John C
________________________________
Support your local Country Music Club
countrydj is offline   Reply With Quote
Old 02-05-2013, 06:38 PM   PM User | #8
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by countrydj View Post
Recently I have read that REQUEST shouldn't be used so I am changing it all back.
One reason $_REQUEST shouldn't be used is that using it means that you have no control over whether the information is passed in $_POST, $_GET or $_COOKIE as it consolidates all three. In most cases you only want the info to come from one of those three places and so not looking for it in the other two places makes your code more secure.

I have never seen anywhere recommending using REQUEST - even 10 years ago all the references I saw were recommending against using it.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
countrydj (02-05-2013)
Old 02-05-2013, 06:46 PM   PM User | #9
countrydj
Regular Coder

 
Join Date: Nov 2011
Location: Preston, UK
Posts: 130
Thanks: 36
Thanked 0 Times in 0 Posts
countrydj is an unknown quantity at this point
Hi felgall ...

Thanks for your explanation.
Quote:
I have never seen anywhere recommending using REQUEST - even 10 years ago all the references I saw were recommending against using it.
Maybe I am wrong (it has been known) - QUITE OFTEN ACTUALLY !!!

I just seem to remember seeing it somewhere ????????

Can you tell me when to use POST and when to use GET PLEASE ???

Thank you very much.
__________________
The MAN, The MYTH, The LEGEND:
John C
________________________________
Support your local Country Music Club
countrydj is offline   Reply With Quote
Old 02-05-2013, 07:09 PM   PM User | #10
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
$_POST when your request is post, $_GET when you're request is get.
In HTML world, $_POST when your form has an action="post", $_GET when its passed through a querystring.

$_REQUEST is another one of those "brainchild" things that zend did, like register_globals and magic_quotes. Newer versions of PHP can control these variables (at perdir level) in PHP 5.3+. The ultimate fallback is still to variables_order which is by default EGPCS, or ENV, GET, POST, COOKIE, and finally SERVER. This is clearly a big problem as now you cannot tell which method provided what AND it's overridden in the order from left to right.
At the very minimum $_REQUEST should be manually overwritten as a merge of $_POST and $_GET, where $_POST overrides $_GET. My suggestion is to never use it.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
countrydj (02-05-2013)
Old 02-05-2013, 11:31 PM   PM User | #11
countrydj
Regular Coder

 
Join Date: Nov 2011
Location: Preston, UK
Posts: 130
Thanks: 36
Thanked 0 Times in 0 Posts
countrydj is an unknown quantity at this point
Many thanks Fou-Lu for your explanation.

Hopefully I will 'get there' eventually.

THANK YOU
__________________
The MAN, The MYTH, The LEGEND:
John C
________________________________
Support your local Country Music Club
countrydj is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:36 PM.


Advertisement
Log in to turn off these ads.