Hi, I’ve recently started to seriously try and learn PHP and MySQL
I’ve bought janet valades book “php and mysql for dummies” and have been setting up her example catalogue and member login scripts to practise.
I’ve managed to get the catalog script working but have run into a problem with the membership script that I just can’t seem to figure out.
my problem is to do with checking to see whether the necessary fields have been filled in on the membership form.
janet’s script has this:
(all fields must be filled in except fax)
[php]
case “new”:
foreach($_POST as $key => $value)
{
if ($key != “fax”)
{
if ($value == “”)
{
unset($do);
$message_new = “Required information is missing.
Please try again.”;
include(“login_form.inc”);
exit();
}
}
/…more code…/[/php]
which doesn’t seem to work as i must still fill in ALL fields to join including “fax”.
I tried modifying the script to this:
[php]case “new”:
foreach($_POST as $key => $value)
{
if (($key == “newname”) or ($key == “password”) or ($key == “firstname”) or ($key == “lastname”) or ($key == “email”))
{
if ($value == “”)
{
unset($do);
$message_new = “Required information is missing.
Please try again.”;
include(“login_form.inc”);
exit();
}
}
/…more code…/[/php]
as i thought stating the fields i didn’t want empty might work.
I’m not even sure I have the syntax(?) right but it seemed to work. except now i can leave any field blank and join. I’m almost positive i’m not using ‘or’ correctly, but my brain is now scrambled with the trial and errors i’ve been making and this seemed to actually get halfway near where I wanted to go.
I’ve searched php.net on all the terms i could think of but now I’m a bit lost. I’m the kind of learner who likes to see how things work ‘in action’ this is making me really confused and I’m finding I’m running around in circles.
Can anyone see something basic there that I’m just not getting? Or can explain the foreach and if statements janet has in simple terms?
Thanks in advance,
NightOwl