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