Jump to content

$_POST problem


adv

Recommended Posts

hello i have a script and i keep getting an error

on php4 i dont get that error

only on php5

<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors',1);
function query_str($params) {
        $str = '';
                foreach ($params as $key => $value) {
                        $str .= (strlen($str) < 1) ? '' : '&';
                        $str .= $key . '=' . rawurlencode($value);
                }
                 return ($str);
}

if($_GET['id']=='1'){
                $query=parse_str($_POST);
                query_str($query);
                $username=rtrim($username);
                $password=rtrim($password);
                // .... continue
echo $username.':'.$password.chr(10);
}

 

Warning: parse_str() expects parameter 1 to be string, array given in /var/www/poo/do.php on line 15 
Warning: Invalid argument supplied for foreach() in /var/www/poo/do.php on line 7 
Notice: Undefined variable: username in /var/www/poo/do.php on line 17 
Notice: Undefined variable: password in /var/www/poo/do.php on line 18 

 

the html code is this

<form  name="Form_Auth" action="do.php?id=1" method="post" target="_top">
<input name="username" id="txt" value="Nome utente" class="nomeutente">
<input name="password" type="password" maxlength="32" id="pass" value="password" class="password lf">
<input name="bottone" type="submit" class="bottone rf" value="Invia" alt="accedi">
</form>

Link to comment
https://forums.phpfreaks.com/topic/253543-_post-problem/
Share on other sites

It's not a POST problem! It means that you can't read in English :)

What is written?

"parse_str() expects parameter 1 to be string, array given" - what is POST? It's an array. PHP is right, you give to the function parse_str() an array instead of string.

"Invalid argument supplied for foreach()" is also correct because you send $query to this function and suppose it's an array. But why are you sure that it's an array?

Link to comment
https://forums.phpfreaks.com/topic/253543-_post-problem/#findComment-1299691
Share on other sites

i have a php 4.3 server and it worked like that

but i figure it out anyway

 

 

  $str = '';
                foreach ($_POST as $key => $value) {
                        $str .= (strlen($str) < 1) ? '' : '&';
                        $str .= $key . '=' . rawurlencode($value);
			}
                parse_str($str);

Link to comment
https://forums.phpfreaks.com/topic/253543-_post-problem/#findComment-1299696
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.