Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 31st, 2009, 12:25 AM
Authorized User
 
Join Date: Sep 2003
Location: Wonderboom South, Pretoria, Gauteng, South Africa.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Greywacke Send a message via Skype™ to Greywacke
Unhappy 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 07:32 AM.
Reply With Quote
  #2 (permalink)  
Old December 31st, 2009, 01:30 AM
Authorized User
 
Join Date: Sep 2003
Location: Wonderboom South, Pretoria, Gauteng, South Africa.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Greywacke Send a message via Skype™ to Greywacke
Unhappy

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 07:30 AM.
Reply With Quote
  #3 (permalink)  
Old December 31st, 2009, 02:00 AM
Authorized User
 
Join Date: Sep 2003
Location: Wonderboom South, Pretoria, Gauteng, South Africa.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Greywacke Send a message via Skype™ to Greywacke
Red face

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.
Reply With Quote
  #4 (permalink)  
Old December 31st, 2009, 03:26 AM
Authorized User
 
Join Date: Sep 2003
Location: Wonderboom South, Pretoria, Gauteng, South Africa.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Greywacke Send a message via Skype™ to Greywacke
Question

> 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 05:31 AM.
Reply With Quote
  #5 (permalink)  
Old December 31st, 2009, 05:53 AM
Authorized User
 
Join Date: Sep 2003
Location: Wonderboom South, Pretoria, Gauteng, South Africa.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Greywacke Send a message via Skype™ to Greywacke
Talking

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.
Reply With Quote
  #6 (permalink)  
Old February 6th, 2013, 10:15 AM
dfy dfy is offline
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question 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?
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass variables from array inside a loop dustygn PHP How-To 2 May 3rd, 2006 05:35 PM
Is it better to pass variables to a function? stephen_c_ Beginning PHP 3 November 4th, 2005 04:07 AM
Can't pass variables to form for validation! gnilly PHP How-To 4 April 24th, 2005 06:33 AM
Convert all items in _POST to hidden form faqbch99 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 February 16th, 2005 06:18 PM



All times are GMT -4. The time now is 12:58 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.