adv Posted December 20, 2011 Share Posted December 20, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/253543-_post-problem/ Share on other sites More sharing options...
trq Posted December 20, 2011 Share Posted December 20, 2011 $_POst is an array. As the name suggests parse_str expects a string. This is no different between php4 - 5, it is likely that your php4 install is misconfigured to hide errors form you the developer. Quote Link to comment https://forums.phpfreaks.com/topic/253543-_post-problem/#findComment-1299690 Share on other sites More sharing options...
SergeiSS Posted December 20, 2011 Share Posted December 20, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/253543-_post-problem/#findComment-1299691 Share on other sites More sharing options...
adv Posted December 20, 2011 Author Share Posted December 20, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/253543-_post-problem/#findComment-1299696 Share on other sites More sharing options...
trq Posted December 20, 2011 Share Posted December 20, 2011 i have a php 4.3 server and it worked like that No, your php4.3 server was configured to hide errors from you. Bad code is bad code, it doesn't matter what version it is written in. Quote Link to comment https://forums.phpfreaks.com/topic/253543-_post-problem/#findComment-1299698 Share on other sites More sharing options...
adv Posted December 20, 2011 Author Share Posted December 20, 2011 yea thanks alot i got it now:D Quote Link to comment https://forums.phpfreaks.com/topic/253543-_post-problem/#findComment-1299699 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.