 |
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

December 31st, 2009, 01:25 AM
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
trying to pass the array of $_POST form variables through a function
hi,
i'm trying to get the variable $attribs to contain the array of attribute descriptions and values from the database, but i keep getting the following error passed through ajax.
Warning: Invalid argument supplied for foreach() in C:\XAMPP\htdocs\fab\scripts\request_handler.php on line 32
the post string sent to the request_handler.php page is the following:
Code:
"menu_services=1&text_consumerfullname=Piet%20Pompies&text_consumeremail=pierre%40greywacke.co.za&attribute=1&attribute=2&menu_regions=8&text_leadsubject=test%20subject&text_leadmessage=test%20message"
the function that is defined there is the following, followed by the call:
PHP Code:
function getattribs($arr) { $arr2 = array(); foreach ($arr as $key => $val) { $sql = "SELECT bigint_AttributeID, text_AttributeDescription, text_AttributeValue FROM 3_serviceattributes WHERE bigint_AttributeID = ".$val.";\n"; $GLOBALS["sql"] .= $sql; $result = mysql_query($sql); $err = mysql_error(); $GLOBALS["sql"] .= strtoupper($err)."\n"; while ($row = mysql_fetch_array($result)) { array_push($GLOBALS["attribids"],$arr2,$row["text_AttributeID"]); array_push($arr2,$row["text_AttributeDescription"]." = ". $row["text_AttributeValue"]); } } return join("<BR>\n",$arr2); } $attribs = getattribs($_POST["attribute"]);
i've tried passing the array as attribute[] too, but that did not work too well. how should i use the for loop in this case? i'm not sure it's being passed correctly?
__________________
Sincerely,
Pierre "Greywacke" du Toit
pierre@greywacke.co.za
don't worry about my 0 thankyou's either way, i would say thank you should you help, and i will gladly help others when this work rush is over.
Last edited by Greywacke; December 31st, 2009 at 08:32 AM..
|

December 31st, 2009, 02:30 AM
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i've added the array() method around the $_POST["attribute"] request to ensure it's an array. that solved the error, but now it doesn't step through the first $key = attribute $val = 1... only the second which is 2... i see this because the processed queries added to $GLOBALS["sql"], only includes the query for value 2 - there should be one for value 1 as well, here is the processed queries (if an error occurred, the following line contains it):
Code:
SELECT bigint_AttributeID, text_AttributeDescription, text_AttributeValue
FROM 3_serviceattributes WHERE bigint_AttributeID = 2;
not sure i'm doing that correctly, how can i process this that ALL attributes passed are stepped through, wether one or more?
__________________
Sincerely,
Pierre "Greywacke" du Toit
pierre@greywacke.co.za
don't worry about my 0 thankyou's either way, i would say thank you should you help, and i will gladly help others when this work rush is over.
Last edited by Greywacke; December 31st, 2009 at 08:30 AM..
|

December 31st, 2009, 03:00 AM
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
also noticed the extra parameter in the first array_push() method.
__________________
Sincerely,
Pierre "Greywacke" du Toit
pierre@greywacke.co.za
don't worry about my 0 thankyou's either way, i would say thank you should you help, and i will gladly help others when this work rush is over.
|

December 31st, 2009, 04:26 AM
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
> this post can be closed, resolved this issue.
apparently not yet. how can i get the joined array to be by a <br /> tag followed a new line? for some reason it's not parsing the string as regexp.
PHP Code:
return join("<br />\n",$arr2);
__________________
Sincerely,
Pierre "Greywacke" du Toit
pierre@greywacke.co.za
don't worry about my 0 thankyou's either way, i would say thank you should you help, and i will gladly help others when this work rush is over.
Last edited by Greywacke; December 31st, 2009 at 06:31 AM..
|

December 31st, 2009, 06:53 AM
|
Authorized User
|
|
Join Date: Sep 2003
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
okay, i guess this issue is resolved now, not putting the attributes on their own lines. the \n was removed. it would still be helpful to know how to insert a new line as a seperator with join functions in php though... i guess one could always do it by character code.
__________________
Sincerely,
Pierre "Greywacke" du Toit
pierre@greywacke.co.za
don't worry about my 0 thankyou's either way, i would say thank you should you help, and i will gladly help others when this work rush is over.
|

February 6th, 2013, 11:15 AM
|
Registered User
|
|
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
error in passing parameter with POST
Hi, I am new to php. I am using a Macintosh OSX 10.7.5 and XAMPP. I have been following a series of tutorials on youtube and in one of them method = 'POST' this is used in a html document. The corresponding php document uses :
$number = $_POST['number'];
then $number is used in a conditional as follows:
if($number < 50) {...
it doesn't matter if the number submitted on the html document side is greater than or less than 50 the conditional evaluates to true in both cases. If I substitute on the html side method = 'GET' and use on the php side $number = $_GET['number']; the conditional evaluates correctly
echo "<?php phpinfo(); ?>" >> blah.php informed me that php 5.3.1 was operatijng
I had also MAMP and I tested operation under that framework to find the system operated identically.
does any1 have a clue as to why this is operating so?
|
|
 |