473,414 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Forms in Php

Is it possible to use the GET method with checkboxes in php?? I have a
form that does a get but I get the following error.

Warning: Invalid argument supplied for foreach() in
If I change the method to a POST it works fine..

Thanks

Oct 17 '05 #1
5 1413
What snippet of code are you using for the foreach?
foreach($_GET as $key=>$value){} should work.

Is there a particular reason you are using GET and not POST for the form?

onefastmustang wrote:
Is it possible to use the GET method with checkboxes in php?? I have a
form that does a get but I get the following error.

Warning: Invalid argument supplied for foreach() in
If I change the method to a POST it works fine..

Thanks


--
Scott Johnson
http://www.seaforthsailingclub.com
Oct 17 '05 #2
I am using that exact syntax.. I misspoke before.. POST does not work
either.. The reason I was using GET is that the client wants to be
able to use the back button on the browser without getting the PAGE
EXPIRED page..

my form looks like this..
<input type="checkbox" value= "1" name="roles[]" >
<input type="checkbox" value= "2" name="roles[]" >

The reciveing code looks like this..
$roles = $_GET[roles]. $_POST[roles];
if ($roles) {
$sqls = $sqls. " and profiles.role IN (";
foreach ($roles as $key => $value){
$sqls = $sqls. "$value,";
}
$sqls = substr("$sqls", 0 , -1);
$sqls .= ")";
}

Oct 17 '05 #3
onefastmustang said the following on 17/10/2005 18:22:
I am using that exact syntax.. I misspoke before.. POST does not work
either.. The reason I was using GET is that the client wants to be
able to use the back button on the browser without getting the PAGE
EXPIRED page..

my form looks like this..
<input type="checkbox" value= "1" name="roles[]" >
<input type="checkbox" value= "2" name="roles[]" >

The reciveing code looks like this..
$roles = $_GET[roles]. $_POST[roles]; ^ ^
^ ^
Missing quotes here?
Also, you can't concatenate arrays like this. Try array_merge() instead.


if ($roles) {
$sqls = $sqls. " and profiles.role IN (";
foreach ($roles as $key => $value){
$sqls = $sqls. "$value,";
}
$sqls = substr("$sqls", 0 , -1);
$sqls .= ")";
}

--
Oli
Oct 17 '05 #4
onefastmustang wrote:
I am using that exact syntax.. I misspoke before.. POST does not work
either.. The reason I was using GET is that the client wants to be
able to use the back button on the browser without getting the PAGE
EXPIRED page..

my form looks like this..
<input type="checkbox" value= "1" name="roles[]" >
<input type="checkbox" value= "2" name="roles[]" >

The reciveing code looks like this..
$roles = $_GET[roles]. $_POST[roles];
Do you use both get and post at the same time? If you want to use a
method that doesn't care wether the post or get method is used try request..

$roles = $_REQUEST['roles'];



if ($roles) {
$sqls = $sqls. " and profiles.role IN (";
foreach ($roles as $key => $value){
$sqls = $sqls. "$value,";
}
$sqls = substr("$sqls", 0 , -1);
$sqls .= ")";
}


Your error message is for the loop that goes through the query to the
database. I can't see why you try to loop the way you do. Could you try
to explain what you're trying to retreive in that query?
Oct 18 '05 #5
onefastmustang wrote:
I am using that exact syntax.. I misspoke before.. POST does not work
either.. The reason I was using GET is that the client wants to be
able to use the back button on the browser without getting the PAGE
EXPIRED page..

my form looks like this..
<input type="checkbox" value= "1" name="roles[]" >
<input type="checkbox" value= "2" name="roles[]" >

The reciveing code looks like this..
$roles = $_GET[roles]. $_POST[roles];
if ($roles) {
$sqls = $sqls. " and profiles.role IN (";
foreach ($roles as $key => $value){
$sqls = $sqls. "$value,";
}
$sqls = substr("$sqls", 0 , -1);
$sqls .= ")";
}


Well, $roles won't be an array at this time - you did a string
concatenation on it.

If you're using GET method, use $_GET. If you're using $_POST, use
$_POST. You can also use $_REQUEST to handle either - but personally I
don't like that as well. But that's just my personal preference.

Also, if neither checkbox is checked, $roles will be empty.

A couple of changes:

$roles = isset($_GET['roles']) ? $_GET($roles) : null; // Note quotes!

if (isset($roles) { // Has one been set?
if (isarray($roles) { // Ensure it's an array
$sqls = $sqls. " and profiles.role IN (";
foreach ($roles as $key => $value){
$sqls = $sqls. "$value,";
}
$sqls = substr("$sqls", 0 , -1);
$sqls .= ")";
}
else { // Set but not an array
$sqls = $sqls . " and profiles.role = " . $roles . ")"
}
}

(note - not checked for syntax)
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
3
by: Joshua Russell | last post by:
Hi, Both the methods below open up a windows form called MasterForm. However, one works better than the other. Method 1 opens the form correctly but I don't have any reference to the instance of...
7
by: Mike Bulava | last post by:
I have created a base form that I plan to use throughout my application let call the form form1. I have Built the project then add another form that inherits from form1, I add a few panel controls...
13
by: MD | last post by:
I have been converting a program from VB6 to VB.Net and enhancing it as well. All has been progressing OK although its been hard work. Now, all of a sudden, when I try to execute a ShowDialog()...
15
by: Joshua Kendall | last post by:
I have a script in which it keeps opening the same form instead of only one instance. I also need help with a form that has a password. Where do I put the actual password? can I use a database for...
3
by: Lloyd Sheen | last post by:
I have the following situation: Need a user resizable user control. After much trying with user control I came across the idea of hosting the controls in a form marked as not TopLevel = false. ...
8
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a...
3
by: Geraldine Hobley | last post by:
Hello, In my project I am inheriting several forms. However when I inherit from a form and add additional subroutines and methods to my inherited form I get all sorts of problems. e.g. I sometimes...
6
by: dbuchanan | last post by:
I have a Windows Forms application that accesses SQL Server 2k from a small local network. The application has been used for weeks on other systmes but a new install on a new machine retruns...
21
by: Dan Tallent | last post by:
In my application I have a form (Customer) that I want to be able to open multiple copies at once. Within this form I have other forms that can be opened. Example: ZipCode. When the user enters...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.