473,410 Members | 1,937 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,410 software developers and data experts.

What is wrong???

at test.php is...

<form action = "test1.php" method = "POST">
<p>
<b>Interests:</b>
<br>
<input type = "Checkbox" name = "interests[]" value =
"politics">Politics
<input type = "Checkbox" name = "interests[]" value =
"economy">Economy
<p>
<input type = "Submit" name = "submit" value = "Save">
</form>
</form>
at test1.php is...

<?
include("test2.php");

$fp = new FormProcessor();

$fp->valid(
"interests",
"array",
LETTERS,
'The interests are valid.',
'The interests are invalid!'
);
?>
at test2.php is...

<?
define('LETTERS', '/^[-+]?\\b[a-zA-Z]*\\.?[a-zA-Z]+\\b$/');

class FormProcessor
{
private function getValue($field)
{
$_REQUEST{$field};
}

public function valid($field, $type, $pattern, $warn, $alert)
{
$value = $this->getValue($field);

foreach ($value as $checkbox)
{
if(!preg_match($pattern, $checkbox))
{
$this->alerts[$field] = $alert;

return false;
}
}
}
}
Sep 13 '08 #1
8 1578
Raistlin Majere schreef:
at test.php is...
...
whats the difference between this, and your posting from 11 minutes ago
???? (besides the thow additional questionmarks in the subject)
--
Luuk
Sep 13 '08 #2
Raistlin Majere wrote:
at test.php is...

<form action = "test1.php" method = "POST">
<p>
<b>Interests:</b>
<br>
<input type = "Checkbox" name = "interests[]" value =
"politics">Politics
<input type = "Checkbox" name = "interests[]" value =
"economy">Economy
<p>
<input type = "Submit" name = "submit" value = "Save">
</form>
</form>
at test1.php is...

<?
include("test2.php");

$fp = new FormProcessor();

$fp->valid(
"interests",
"array",
LETTERS,
'The interests are valid.',
'The interests are invalid!'
);
?>
at test2.php is...

<?
define('LETTERS', '/^[-+]?\\b[a-zA-Z]*\\.?[a-zA-Z]+\\b$/');

class FormProcessor
{
private function getValue($field)
{
$_REQUEST{$field};
}

public function valid($field, $type, $pattern, $warn, $alert)
{
$value = $this->getValue($field);

foreach ($value as $checkbox)
{
if(!preg_match($pattern, $checkbox))
{
$this->alerts[$field] = $alert;

return false;
}
}
}
}

What happens/doesn't happen that leads you to say it is wrong? What is
it supposed to do? What DOES it do?

Why do expect people to go into your code while being mind readers as to
the objective/problem?
Sep 13 '08 #3
On 13 set, 15:37, Luuk <L...@invalid.lanwrote:
Raistlin Majere schreef:at test.php is...

..
whats the difference between this, and your posting from 11 minutes ago
???? (besides the thow additional questionmarks in the subject)
--
Luuk
test2.php is different
Sep 14 '08 #4
On 13 set, 15:51, sheldonlg <sheldonlgwrote:
Raistlin Majere wrote:
at test.php is...
<form action = "test1.php" method = "POST">
<p>
<b>Interests:</b>
<br>
<input type = "Checkbox" name = "interests[]" value =
"politics">Politics
<input type = "Checkbox" name = "interests[]" value =
"economy">Economy
<p>
<input type = "Submit" name = "submit" value = "Save">
</form>
</form>
at test1.php is...
<?
include("test2.php");
$fp = new FormProcessor();
$fp->valid(
* * "interests",
* * "array",
* * LETTERS,
* * 'The interests are valid.',
* * 'The interests are invalid!'
* * );
?>
at test2.php is...
<?
define('LETTERS', '/^[-+]?\\b[a-zA-Z]*\\.?[a-zA-Z]+\\b$/');
class FormProcessor
{
* * private function getValue($field)
* * {
* * * * $_REQUEST{$field};
* * }
* * public function valid($field, $type, $pattern, $warn, $alert)
* * {
* * * * $value = $this->getValue($field);
* * * * foreach ($value as $checkbox)
* * * * {
* * * * * * if(!preg_match($pattern, $checkbox))
* * * * * * {
* * * * * * * * $this->alerts[$field] = $alert;
* * * * * * * * return false;
* * * * * * }
* * * * }
* * }
}

What happens/doesn't happen that leads you to say it is wrong? *What is
it supposed to do? *What DOES it do?
If no box, any box or all boxes are checked, nothing should happen,
but I am getting a "Warning: Invalid argument supplied for foreach()
in C:\AppServ\www\intermediary\accounts\test2.php on line 15".
Why do expect people to go into your code while being mind readers as to
the objective/problem?
The objective is to check if there is any invalid value in the
interests array. The problem is that the value variable or the
interests array is an invalid argument to the foreach loop, but I do
not know why.

I thought people were going to run the code and see the error message,
but thinking about it again, why would people run the code? LOL!
Sep 14 '08 #5
Raistlin Majere wrote:
On 13 set, 15:51, sheldonlg <sheldonlgwrote:
>Raistlin Majere wrote:
>>at test.php is...
<form action = "test1.php" method = "POST">
<p>
<b>Interests:</b>
<br>
<input type = "Checkbox" name = "interests[]" value =
"politics">Politics
<input type = "Checkbox" name = "interests[]" value =
"economy">Economy
<p>
<input type = "Submit" name = "submit" value = "Save">
</form>
</form>
at test1.php is...
<?
include("test2.php");
$fp = new FormProcessor();
$fp->valid(
"interests",
"array",
LETTERS,
'The interests are valid.',
'The interests are invalid!'
);
?>
at test2.php is...
<?
define('LETTERS', '/^[-+]?\\b[a-zA-Z]*\\.?[a-zA-Z]+\\b$/');
class FormProcessor
{
private function getValue($field)
{
$_REQUEST{$field};
}
public function valid($field, $type, $pattern, $warn, $alert)
{
$value = $this->getValue($field);
foreach ($value as $checkbox)
{
if(!preg_match($pattern, $checkbox))
{
$this->alerts[$field] = $alert;
return false;
}
}
}
}
What happens/doesn't happen that leads you to say it is wrong? What is
it supposed to do? What DOES it do?

If no box, any box or all boxes are checked, nothing should happen,
but I am getting a "Warning: Invalid argument supplied for foreach()
in C:\AppServ\www\intermediary\accounts\test2.php on line 15".
That means that the array is empty.
>
>Why do expect people to go into your code while being mind readers as to
the objective/problem?

The objective is to check if there is any invalid value in the
interests array. The problem is that the value variable or the
interests array is an invalid argument to the foreach loop, but I do
not know why.
See above.
>
I thought people were going to run the code and see the error message,
but thinking about it again, why would people run the code? LOL!
Right.
Sep 14 '08 #6
sheldonlg wrote:
Raistlin Majere wrote:
>On 13 set, 15:51, sheldonlg <sheldonlgwrote:
>>Raistlin Majere wrote:
at test.php is...
<form action = "test1.php" method = "POST">
<p>
<b>Interests:</b>
<br>
<input type = "Checkbox" name = "interests[]" value =
"politics">Politics
<input type = "Checkbox" name = "interests[]" value =
"economy">Economy
<p>
<input type = "Submit" name = "submit" value = "Save">
</form>
</form>
at test1.php is...
<?
include("test2.php");
$fp = new FormProcessor();
$fp->valid(
"interests",
"array",
LETTERS,
'The interests are valid.',
'The interests are invalid!'
);
?>
at test2.php is...
<?
define('LETTERS', '/^[-+]?\\b[a-zA-Z]*\\.?[a-zA-Z]+\\b$/');
class FormProcessor
{
private function getValue($field)
{
$_REQUEST{$field};
}
public function valid($field, $type, $pattern, $warn, $alert)
{
$value = $this->getValue($field);
foreach ($value as $checkbox)
{
if(!preg_match($pattern, $checkbox))
{
$this->alerts[$field] = $alert;
return false;
}
}
}
}
What happens/doesn't happen that leads you to say it is wrong? What is
it supposed to do? What DOES it do?

If no box, any box or all boxes are checked, nothing should happen,
According to this line, you've specified all the possibilities and
nothing should ever happen. Under what conditions (nothing is left
here) SHOULD something happen?
>but I am getting a "Warning: Invalid argument supplied for foreach()
in C:\AppServ\www\intermediary\accounts\test2.php on line 15".

That means that the array is empty.
1 - Use $_POST, not $_REQUEST. You should know whether what came in was
via a post or via the URL. While $_REQUEST will get the result, it is
very sloppy coding. (If I saw this in an example of someone's work, it
would strongly influence me to not hire that person).

2 - The array $value in test2.php is empty. That means that it is not
getting the filled from the method getValue($field). A quick look at
that method reveals the problem. You need to change the one line (as
written) in it to:

return $_REQUEST($field);

(Use $_POST or $_GET instead). What you have written does not return
any value. That is why it remains empty.
Sep 14 '08 #7
I V
On Sat, 13 Sep 2008 21:27:12 -0400, sheldonlg wrote:
Raistlin Majere wrote:
>If no box, any box or all boxes are checked, nothing should happen, but
I am getting a "Warning: Invalid argument supplied for foreach() in
C:\AppServ\www\intermediary\accounts\test2.php on line 15".

That means that the array is empty.
That's not quite right - an empty array is a valid argument to foreach.
The problem is that the argument is not an array - it's probably null.
Sep 15 '08 #8
I V wrote:
On Sat, 13 Sep 2008 21:27:12 -0400, sheldonlg wrote:
>Raistlin Majere wrote:
>>If no box, any box or all boxes are checked, nothing should happen, but
I am getting a "Warning: Invalid argument supplied for foreach() in
C:\AppServ\www\intermediary\accounts\test2.php on line 15".
That means that the array is empty.

That's not quite right - an empty array is a valid argument to foreach.
The problem is that the argument is not an array - it's probably null.
Quite right. I was a little sloppy in my statement. That is why I
generally define it first with $variable = array() before trying to fill
the array which, itself, is before a foreach. Thanks for the correction.
Sep 15 '08 #9

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

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
5
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
28
by: Madhur | last post by:
Hello what about this nice way to open a file in single line rather than using if and else. #include<stdio.h> void main() { FILE *nd; clrscr();...
56
by: Cherrish Vaidiyan | last post by:
Frinds, Hope everyone is doing fine.i feel pointers to be the most toughest part in C. i have just completed learning pointers & arrays related portions. I need to attend technical interview on...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
9
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
3
by: Siong.Ong | last post by:
Dear all, my PHP aims to update a MySQL database by selecting record one by one and modify then save. Here are my PHP, but I found that it doesnt work as it supposed to be, for example, when...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.