homepage Welcome to WebmasterWorld Guest from 23.22.29.137
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
accessing the $_POST array returns 0 variables
...even though the form is submitted correctly
dmmh




msg:1311155
 9:17 am on May 15, 2006 (gmt 0)

I have a form on one page which lets a user choose a action to perform on some items, the user selects the items to be edited and is taken to another page via a javascript onchange="this.form.submit()"

The data from the form is sent to the second page via the POST method.
If I try to access the $_POST array contents, it's completely empty (var_dump($_POST) returns array(0) { } ).
If I change the method to GET on the first page, change var_dump($_POST) to var_dump($_GET) on the second page, the form is submitted correctly
My HTML is 100% validated by W3C validator and ini_set('error_reporting', E_ALL) returns 0 errors, none whatsoever

These 2 pages should just work together, but somehow the data is not submitted or whatever

HOW IS THIS POSSIBLE?
I really am baffled :(

 

eelixduppy




msg:1311156
 11:14 am on May 15, 2006 (gmt 0)

It seems that you have the method set to 'get' instead of 'post' on your form. I'm not sure if this is true or not but if it is, it wouldn't give you any errors. Check this first to see if it is set correctly.

eelix

dmmh




msg:1311157
 11:49 am on May 15, 2006 (gmt 0)

like I already said, the method is set to POST and I am accessing the $_POST array, which remains empty.
If I change both the method and the second page to $_GET, it does work

whoisgregg




msg:1311158
 1:34 pm on May 15, 2006 (gmt 0)

Do you have any included scripts that loop through and process the $_POST array? Perhaps there is a flaw in that code that is emptying the array?

dmmh




msg:1311159
 1:53 pm on May 15, 2006 (gmt 0)

nope, none whatsoever :(
It works for other similar pages, which is the odd thing :/

dreamcatcher




msg:1311160
 3:17 pm on May 15, 2006 (gmt 0)

Can you post some code?

If you set your error_reporting level to E_ALL, does that throw up any errors?

dc

dmmh




msg:1311161
 3:23 pm on May 15, 2006 (gmt 0)

If you set your error_reporting level to E_ALL, does that throw up any errors?

My HTML is 100% validated by W3C validator and ini_set('error_reporting', E_ALL) returns 0 errors, none whatsoever

;)

I'll post some code later on :)

dreamcatcher




msg:1311162
 3:48 pm on May 15, 2006 (gmt 0)

My HTML is 100% validated by W3C validator and ini_set('error_reporting', E_ALL) returns 0 errors, none whatsoever

Oops. I just ordered a new pair of glasses. :)

coopster




msg:1311163
 5:06 pm on May 15, 2006 (gmt 0)

Have you checked the variables_order [php.net]?

dmmh




msg:1311164
 7:03 pm on May 15, 2006 (gmt 0)

am I wrong when I say that shouldnt really matter at all?
$_POST as well as $_GET is available througout my site, $_GET is available on on the failing page, but apparently $_POST isnt.....
I havent set anything to cause this page to stick out from the rest

eelixduppy




msg:1311165
 7:25 pm on May 15, 2006 (gmt 0)

What version of PHP do you have and what OS are you running it on?

eelix

dmmh




msg:1311166
 7:29 pm on May 15, 2006 (gmt 0)

its an apache/ linux/ 4.3.11 configuration

coopster




msg:1311167
 8:16 pm on May 15, 2006 (gmt 0)


am I wrong when I say that shouldnt really matter at all?

Yes. That directive [php.net] is of type PHP_INI_ALL in PHP <= 5.0.5. After that it is of type PHP_INI_PERDIR. It could very well be overridden in either version installation. The easiest way to find out is to dump the directive value to see if it is set that way in your form processing script. Seems as though as it would be unlikely, but never assume. ini_get() [php.net] will let you know either way.

sonjay




msg:1311168
 8:55 pm on May 15, 2006 (gmt 0)

If you pull out the javascript and just POST it the regular way, do the POST variables come through? Testing that would help narrow down whether it's a problem with POSTing or a problem with your javascript.

eelixduppy




msg:1311169
 9:29 pm on May 15, 2006 (gmt 0)

Are you posting over a secure connection (ie SSL,HTTPS, etc) because I read some articles of people who are experiencing similar problems with this?

eelix

dmmh




msg:1311170
 10:16 pm on May 15, 2006 (gmt 0)

no SSL, HTTPS, tried non-javascript, and variables_order() returns EGPCS, the default

completely baffled :(

eelixduppy




msg:1311171
 10:25 pm on May 15, 2006 (gmt 0)


I'll post some code later on :)

Maybe later one is now? I'm not seeing any logic to this. The only thing, I think, that may be causing it is something that you aren't seeing in your script. I'll keep searching for other possible problems though.

eelix

dmmh




msg:1311172
 9:11 am on May 16, 2006 (gmt 0)

ok, but this is one huge page :)

the code of the first page, domain obscured, db and session variable names obscured but rest is 1 on 1 the same

<?
ini_set("session.cookie_domain"," .site.com");
session_start();

if (!empty($_SESSION['username'])){ //if user is logged in.....
@mysql_select_db('db'); //...check what their details are so we can echo it to the browser
$nr_dvd_sell_query = 'SELECT COUNT(*) AS count FROM selllist'." WHERE uid='".$_SESSION['uid']."'";
$nr_dvd_sell_result = mysql_query($nr_dvd_sell_query) or die ("Error in query: $nr_dvd_sell_query " . mysql_error());
$nr_dvds_sell = mysql_fetch_array($nr_dvd_sell_result);
$nr_sell = $nr_dvds_sell['count'];?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>site.com - Your DVD sell list</title>
<? include ('meta_overall.php');?>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">
function un_check(){
for (var i = 0; i < document.sell_list.elements.length; i++) {
var e = document.sell_list.elements[i];
if ((e.name!= 'check_all') && (e.type == 'checkbox')) {
e.checked = document.sell_list.check_all.checked;
}
}
}
</SCRIPT>
<link href="http://www.site.com/main.css';}?>" rel="stylesheet" type="text/css">
</head>
<body>
<div align="center">
<? include ('header.php');?>
<? include ('menu.php');?>
<table width="90%" class="backgroundtable">
<tr>
<td width="18%" valign="top">
<? include ('leftcolumn.php');?>
</td>
<td width="82%" colspan="4" valign="top">
<div align="center">
<form name="sell_list" method="post" action="http://profile.site.com/edit/sell">
<table width="100%" border="0" class="innertableright" id="right">
<tr>
<td valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" class="indexheadinfo"><div align="left"><strong>DVD's you want to sell</strong> (<? echo $nr_dvds_sell['count'];?>)</div></td>
</tr>
<tr>
<td valign="top" class="col2">
<? if ($nr_sell == 0){?>
<div align="center">No entries exist in this list yet</div>
<? exit;
}else{
$max_rows = 50; //set the maximum amount of rows
$current_row= ($count + 1); //set current row to '1' or $from would be negative on the next line ((0 * 5) - 5)
$from = (($current_row * $max_rows) - $max_rows); //calculate which results to query based on the row being displayed and the max results per row
$query= 'SELECT * FROM user_selllist'." WHERE uid='".$_SESSION['uid']."' ORDER BY mid ASC LIMIT $from, $max_rows";
$result = mysql_query($query) or die ("Error in query: $query " . mysql_error());
$nr_dvds_this_row = mysql_num_rows($result); //count the number of results for each row because if it doesnt fill the row we need to draw empty cells
$nr_empty_tds =($max_results_per_row - $nr_dvds_this_row); //calculate the actual number of empty cells?>
<!-- BEGIN DYNAMIC CONTENT -->
<div align="center">
<table width="100%" border="0" class="backgroundtable">
<tr>
<td class="col2">&nbsp;</td>
<td class="col2">&nbsp;</td>
<td class="col2">&nbsp;</td>
<td class="col2">&nbsp;</td>
<td colspan="6" class="dvd_have_list_cell"><div align="center">Shipping &amp; handling </div></td>
<td class="col2">&nbsp;</td>
<td class="col2">&nbsp;</td>
</tr>
<tr>
<td colspan="13" class="rowdivide"><img src="http://www.site.com/spacer.gif" width="1" height="1" ALT="spacer_img"></td>
</tr>
<tr>
<td width="3%" class="col2"><div align="center"><input name="check_all" type="checkbox" value="" title="select/ deselect all" onClick="un_check();"></div></td>
<td width="7%" class="col2">&nbsp;</td>
<td width="10%" class="col2"><div align="center"><strong>Price</strong></div></td>
<td width="15%" class="col2"><div align="center"><strong>sell type</strong></div></td>
<td width="10%" class="col2"><div align="center"><strong>R1</strong></div></td>
<td width="10%" class="col2"><div align="center"><strong>R2</strong></div></td>
<td width="10%" class="col2"><div align="center"><strong>R3</strong></div></td>
<td width="10%" class="col2"><div align="center"><strong>R4</strong></div></td>
<td width="10%" class="col2"><div align="center"><strong>R5</strong></div></td>
<td width="10%" class="col2"><div align="center"><strong>R6</strong></div></td>
<td width="10%" class="col2"><div align="center"><strong>Quantity</strong></div></td>
<td width="5%" class="col2"><div align="center"><strong>Currency</strong></div></td>
</tr>
<? for ($count=0; $row = mysql_fetch_array($result); $count++){//draw the cells with dvd cover art via a function?>
<tr>
<td valign="middle" class="col2"><div align="center">
<input name="selected_dvd[]" type="checkbox" value="<? echo $row['id'];?>" class="checkbox"></div></td>
<td valign="middle" class="col2"><div align="center"><? func_makethumb_dvdcover_list_zoom($row['mid'], $row['sid']);?></div></td>
<td class="col2"><div align="center"><? echo $row['price'];?>&nbsp;<? echo $row['currency'];?></div></td>
<td class="col2"><div align="center"><? echo $row['sell_type'];?></div></td>
<td class="col2"><div align="center"><? echo $row['sh_r1'];?></div></td>
<td class="col2"><div align="center"><? echo $row['sh_r2'];?></div></td>
<td class="col2"><div align="center"><? echo $row['sh_r3'];?></div></td>
<td class="col2"><div align="center"><? echo $row['sh_r4'];?></div></td>
<td class="col2"><div align="center"><? echo $row['sh_r5'];?></div></td>
<td class="col2"><div align="center"><? echo $row['sh_r6'];?></div></td>
<td class="col2"><div align="center"><? echo $row['quantity'];?></div></td>
<td class="col2"><div align="center"><? echo $row['currency'];?></div></td>
</tr>
<? }?>
<tr>
<td colspan="12" valign="middle" class="indexheadinfo"><div align="left">&nbsp;&nbsp;<img src="http://www.site.com/images/icons/html_checkbox2.gif" alt="icon" width="16" height="22" class="img_bottom">&nbsp;
<select name="mode" class="menu" onChange="this.form.submit();">
<option value="" selected>select</option>
<option value="sell_to_sell">move to selllist</option>
<option value="sell_to_have">copy to have list</option>
<option value="sell_edit">edit</option>
<option value="sell_delete">delete</option>
</select>
&nbsp;
<noscript><input type="submit" name="submit" value="go" class="postbuttons_bold"></noscript></div></td>
</tr>
</table>
</div>
<? }?>
<!-- END DYNAMIC CONTENT -->
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</div>
</td>
</tr>
</table>
<br/>
<? include ('copy.php');?>
</div>
</body>
</html>
<? }

dmmh




msg:1311173
 9:16 am on May 16, 2006 (gmt 0)

the processing script:

<?
ini_set("session.cookie_domain"," .site.com");
ini_set('error_reporting', E_ALL);
session_start();

var_dump($_POST);
echo ini_get('variables_order');

if (!empty($_SESSION['username']) && (!empty($_POST['mode']) && $_POST['mode'] === 'sell_edit')){ //if user is logged in.....?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Site.com - Set prices for the DVDs</title>
<? include ('meta_overall.php');?>
<link href="http://www.site.com/main.css" rel="stylesheet" type="text/css">
</head>
<body>
<div align="center">
<? include ('header.php');?>
<? include ('menu.php');?>
<br/>
<form name="edit_selllist" method="POST" action="">
<table width="90%" border="0" class="innertableright" id="right">
<tr>
<td valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top" class="col2">
<div align="center">
<table width="100%" border="0" class="backgroundtable" cellpadding="0" cellspacing="0">
<tr>
<td width="30%" class="indexheadinfo"><div align="left"></div></td>
<td width="10%" class="indexheadinfo"><div align="center">sell type</div></td>
<td width="5%" class="indexheadinfo"><div align="center">price</div></td>
<td width="6%" class="indexheadinfo"><div align="center">region 1</div></td>
<td width="6%" class="indexheadinfo"><div align="center">region 2</div></td>
<td width="6%" class="indexheadinfo"><div align="center">region 3</div></td>
<td width="6%" class="indexheadinfo"><div align="center">region 4</div></td>
<td width="6%" class="indexheadinfo"><div align="center">region 5</div></td>
<td width="6%" class="indexheadinfo"><div align="center">region 6</div></td>
<td width="5%" class="indexheadinfo"><div align="center">quantity</div></td>
<td width="15%" class="indexheadinfo"><div align="center">currency</div></td>
</tr>
<?
$nr_dvds = count($_POST['selected_dvd']);
for ($count=0; $count<$nr_dvds; $count++){
$sid = mysql_real_escape_string($_POST['selected_dvd'][$count]);
$query = 'SELECT * FROM selllist'.
" INNER JOIN movies ON movies.mid=selllist.mid".
" INNER JOIN dvds on dvds.sid=selllist.sid".
" WHERE selllist.sid='$sid'";
$result = mysql_query($query) or die ("Error in query: $query ");
$row = mysql_fetch_array($result);?>
<tr>
<td class="colsmalltxt"><div align="left"><a href="http://db.cinemasiafreaks.com/view/?mid=<? echo $mid;?>&amp;sid=<? echo $sid;?>">R<? echo $row['region'];?> - <? echo $row['colorsystem'];?> - <? echo $row['discs'];?> Disc - <? echo ucwords($row['country_edition']);?> version</a><input name="sid[]" type="hidden" value="<? echo $sid;?>"></div></td>
<td>
<div align="center">
<? func_sell_type_selector($mid, $sid, $_SESSION['uid']);?>
</div>
</td>
<td class="col2"><div align="center"><input name="price[]" type="text" size="3" maxlength="6" class="txtfield" value="<? echo $row['price'];?>"></div></td>
<td class="col2"><div align="center"><input name="sh_r1[]" type="text" size="3" maxlength="6" class="txtfield" value="<? echo $row['sh_r1'];?>"></div></td>
<td class="col2"><div align="center"><input name="sh_r2[]" type="text" size="3" maxlength="6" class="txtfield" value="<? echo $row['sh_r2'];?>"></div></td>
<td class="col2"><div align="center"><input name="sh_r3[]" type="text" size="3" maxlength="6" class="txtfield" value="<? echo $row['sh_r3'];?>"></div></td>
<td class="col2"><div align="center"><input name="sh_r4[]" type="text" size="3" maxlength="6" class="txtfield" value="<? echo $row['sh_r4'];?>"></div></td>
<td class="col2"><div align="center"><input name="sh_r5[]" type="text" size="3" maxlength="6" class="txtfield" value="<? echo $row['sh_r5'];?>"></div></td>
<td class="col2"><div align="center"><input name="sh_r6[]" type="text" size="3" maxlength="6" class="txtfield" value="<? echo $row['sh_r6'];?>"></div></td>
<td class="col2"><div align="center"><input name="quantity[]" type="text" size="3" maxlength="3" class="txtfield" value="<? echo $row['quantity'];?>"></div>
</td>
<td>
<div align="center">
<? func_currency_selector($row['currency']);?>
</div>
</td>
</tr>
<? }?>
<tr>
<td colspan="11" valign="middle" class="indexheadinfo">
<div align="center"><? if ($result){?><div align="center"><strong>Because one ore more of the selected items where already on your sell list, you can only edit those items, you can not add them seperately....</strong></div><? }?>
<input name="mid" type="hidden" value="<? echo $mid;?>">
<input name="dvd_mode" type="hidden" value="addselllist">
<input type="submit" name="submit" value="submit" class="postbuttons_bold">
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<br/>
<br/>
<? include ('copy.php');?>
</div>
</body>
</html>
<? }

defireman




msg:1311174
 9:51 am on May 16, 2006 (gmt 0)

By any chance, are you submitting the POSTDATA via Javascript? You will probably need to add an enctype field, like

<form action="upload.asp" method="POST" enctype="multipart/form-data">

also, try accessing the $http_raw_post_data var to see if you get anything. If you do, it's probably an enctype problem, but you can get and parse the data yourself from there.

dmmh




msg:1311175
 10:22 am on May 16, 2006 (gmt 0)

just because I have a javascript onchange attached to a menu does not mean I would have to attach that (a lot of my pages use javascript and all but one work), but hey, I tried it, and as expected, to no avail.

Thanks for the input though :)

Also, the $http_raw_post_data var....is this a pre-defined PHP variable? Cant find much about it, but it appears to be something from ZEND or summat...

defireman




msg:1311176
 11:45 am on May 16, 2006 (gmt 0)

It's poorly documented, but it should yield some data if the POSTDATA is indeed sent. Otherwise, I don't really know how to help you.

dmmh




msg:1311177
 12:16 pm on May 16, 2006 (gmt 0)

tried to access it as $GLOBALS["HTTP_RAW_POST_DATA"] and $HTTP_RAW_POST_DATA but I get Notice: Undefined variable: HTTP_RAW_POST_DATA for those. Even though the form encoding is set to different from the default, default beeing application/x-www.form-urlencoded

:S

whoisgregg




msg:1311178
 1:41 pm on May 16, 2006 (gmt 0)

Here's my shots in the dark to identify the source of the problem...

First, try to use relative path to the actual filename:
<form name="sell_list" method="POST" action="/edit/sell.php">

I venture a guess that the method of resolving "http://profile.site.com/edit/sell" to the actual processing script involves some kind of redirect or rewrite that is dumping the postdata.

Next, remove everything (*Of course, back up everything, this is just for debugging.*) from the processing script, add this line and retest:
print_r(get_defined_vars());

I can't imagine what in your processing script could cause postdata to disappear, but best to reduce the test case down to as little script as possible that reproduces the error.

[edited by: whoisgregg - Tue, 16 May 2006 13:42:28 GMT]

dmmh




msg:1311179
 6:02 am on May 17, 2006 (gmt 0)

Yeah I had it set as relative path, I normally always do, that didnt work either :(

dreamcatcher




msg:1311180
 7:02 am on May 17, 2006 (gmt 0)

Have you tried posting on Google Groups? I keyed in 'no post data' and got some interesting threads.

Google Groups [groups.google.com]

Worth a shot.

dc

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved