shamuraq Posted April 7, 2011 Share Posted April 7, 2011 Hi guys, I have a form using radio buttons. For the radio button, lets just say i have the id name as 'rim' + number eg; rim0, rim1, rim2.... When i post the data to another file to execute the data collected, naturally i would use the: $rim0=$_POST['rim0']; $rim1=$_POST['rim1']; .... $rim10=$_POST['rim10']; i tried to shorten this process using this method: //$q is part of the post variable. for($x = 0; $x < count($q); $x++){ $rim[]=$_POST['"rim"."$x"']; } But i get this error Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Notice: Undefined index: "rim"."$x" in D:\Apache Software Foundation\Apache2.2\htdocs\.....\#####.php on line 20 Is there something wrong with my POST syntax? Link to comment https://forums.phpfreaks.com/topic/232991-php-_post/ Share on other sites More sharing options...
Maq Posted April 7, 2011 Share Posted April 7, 2011 The parser thinks that the double quotes are part of the key string, try: $rim[]=$_POST['rim'.$x]; Link to comment https://forums.phpfreaks.com/topic/232991-php-_post/#findComment-1198282 Share on other sites More sharing options...
mattal999 Posted April 7, 2011 Share Posted April 7, 2011 Don't undefined index notices mean that you didn't check if the variable has a value before using it? if(isset($_POST['rim'.$x])) { $rim[] = $_POST['rim'.$x]; } Link to comment https://forums.phpfreaks.com/topic/232991-php-_post/#findComment-1198283 Share on other sites More sharing options...
PFMaBiSmAd Posted April 7, 2011 Share Posted April 7, 2011 If you use a HTML array name for the form elements, you can eliminate almost all of your code and simply iterate over the values using one simple foreach() loop - http://us3.php.net/manual/en/faq.html.php#faq.html.arrays Link to comment https://forums.phpfreaks.com/topic/232991-php-_post/#findComment-1198285 Share on other sites More sharing options...
shamuraq Posted April 7, 2011 Author Share Posted April 7, 2011 The parser thinks that the double quotes are part of the key string, try: $rim[]=$_POST['rim'.$x]; TT's it! Thanx Mag Link to comment https://forums.phpfreaks.com/topic/232991-php-_post/#findComment-1198286 Share on other sites More sharing options...
Maq Posted April 7, 2011 Share Posted April 7, 2011 Also, since you are using a single quote as your master string the '$x' and '.' don't get interpolated, even though it looks like you're concatenating it. Link to comment https://forums.phpfreaks.com/topic/232991-php-_post/#findComment-1198287 Share on other sites More sharing options...
Maq Posted April 7, 2011 Share Posted April 7, 2011 TT's it! Thanx Mag Maq*, and you're welcome. Link to comment https://forums.phpfreaks.com/topic/232991-php-_post/#findComment-1198288 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.