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

help with posting conditional if statement

Art
Can anyone help. I've tried scaling down a script to the bare minimum and
it still is not working correctly. What I think should happen is that when
the field app_fname is blank, that $hold_chk will get set to 1 and the 1st
if statement will be executed. What actually happens is that when I hit
submit, the form stays where it is, for example if the form where the submit
button is located is on the form other.php, then when I hit submit this is
where it stays. If I then hit the submit button a 2nd time, it post to the
some.php form. I've tried this script without the conditional if(isset()
and it works. I need to have the isset() otherwise the form displays all
empty fields as soon as it loads, before the submit button is hit. Any help
would be appreciated. After working on this for 2 weeks it seems like i'm
stuck.

Thanks
Art

<?php

$holdchk = 0;

if (isset($_POST['B1'])) {

echo "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk == 1 ){
echo "<form method=\"POST\" action=\"some.php\">";

}

if ($holdchk == 0 ){
echo "<form method=\"POST\" action=\"other.php\">";

}
}
?>

<html>

<head>
</head>

<form method="POST" action="">

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

May 4 '07 #1
16 1732
Message-ID: <ry*******************@bignews7.bellsouth.netfro m Art
contained the following:
>After working on this for 2 weeks it seems like i'm
stuck.
Don't multipost. And haven't we seen this before?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
May 4 '07 #2
Art
Sort of, but this is a scaled down version of the code, which was requested.
I'm still stuck and still trying to understand why it's not working.

Thanks
Art
"Geoff Berrow" <bl******@ckdog.co.ukwrote in message
news:8c********************************@4ax.com...
Message-ID: <ry*******************@bignews7.bellsouth.netfro m Art
contained the following:
>>After working on this for 2 weeks it seems like i'm
stuck.

Don't multipost. And haven't we seen this before?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

May 4 '07 #3
Art

Try something like this.

$holdchk= (strlen ($_POST['B1'])>0 and strlen($_POST['app_fname'])==0);
$action= ($holdchk)? "some.php": "other.php";
echo "<form method='POST' action='$action'>";

avoid isset and empty

S

"Art" <c_***@bellsouth.netwrote in message
news:ry*******************@bignews7.bellsouth.net. ..
Can anyone help. I've tried scaling down a script to the bare minimum and
it still is not working correctly. What I think should happen is that
when
the field app_fname is blank, that $hold_chk will get set to 1 and the 1st
if statement will be executed. What actually happens is that when I hit
submit, the form stays where it is, for example if the form where the
submit
button is located is on the form other.php, then when I hit submit this is
where it stays. If I then hit the submit button a 2nd time, it post to
the
some.php form. I've tried this script without the conditional if(isset()
and it works. I need to have the isset() otherwise the form displays all
empty fields as soon as it loads, before the submit button is hit. Any
help
would be appreciated. After working on this for 2 weeks it seems like i'm
stuck.

Thanks
Art

<?php

$holdchk = 0;

if (isset($_POST['B1'])) {

echo "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk == 1 ){
echo "<form method=\"POST\" action=\"some.php\">";

}

if ($holdchk == 0 ){
echo "<form method=\"POST\" action=\"other.php\">";

}
}
?>

<html>

<head>
</head>

<form method="POST" action="">

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

May 4 '07 #4

"Simon Stewart" <ad*****@www.simonstewart.iewrote in message
news:5a*************@mid.individual.net...
Art

Try something like this.

$holdchk= (strlen ($_POST['B1'])>0 and strlen($_POST['app_fname'])==0);
$action= ($holdchk)? "some.php": "other.php";
echo "<form method='POST' action='$action'>";

avoid isset and empty
And why is that?
May 4 '07 #5
Message-ID: <na*******************@bignews7.bellsouth.netfro m Art
contained the following:
>Sort of, but this is a scaled down version of the code, which was requested.
I'm still stuck and still trying to understand why it's not working.
And you took no notice of my post on the subject before. You are still
echoing html /before/ the<htmltag!

I think you need something like this:

<?php

$holdchk = 0;
if (isset($_POST['B1'])) {
$form= "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk === 1 ){
$form.= "<form method=\"POST\" action=\"some.php\">";
}

if ($holdchk === 0 ){
$form.= "<form method=\"POST\" action=\"other.php\">";

}
}
?>

<html>

<head>
</head>

<?php echo $form;?>

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
May 4 '07 #6
Simon Stewart wrote:
Art

Try something like this.

$holdchk= (strlen ($_POST['B1'])>0 and strlen($_POST['app_fname'])==0);
$action= ($holdchk)? "some.php": "other.php";
echo "<form method='POST' action='$action'>";

avoid isset and empty
Why avoid isset?
I use that function in every script that receives clientinformation...
Couldn't life without it.

Personally I think your posted code is a bad example on how to solve it...
You need to read it twice and rethink it. Clear code is better and happens
to use isset().
Just my 2 cent of course...

Regards,
Erwin Moller
May 4 '07 #7
Erwin Moller kirjoitti:
Simon Stewart wrote:
>Art

Try something like this.

$holdchk= (strlen ($_POST['B1'])>0 and strlen($_POST['app_fname'])==0);
$action= ($holdchk)? "some.php": "other.php";
echo "<form method='POST' action='$action'>";

avoid isset and empty

Why avoid isset?
I don't think he knows what he's talking about. isset is essential.
I use that function in every script that receives clientinformation...
Couldn't live without it.
Same here. And it's really handy when using forms with multiple submit
buttons, to see which was pressed. (print, edit, delete, for example.)
Personally I think your posted code is a bad example on how to solve it...
You need to read it twice and rethink it. Clear code is better and happens
to use isset().
Yeah, the example is indeed a bit messy. And concidering the level of
the OP, it's no help at all, it only confuses more. The OP requires the
"php for dummies" answer.

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
May 4 '07 #8
Art
Geoff, I tried modifying the code with your suggestions. It had the effect
of disabling the submit button. It seems like there has to be <form
method="POST" action=""in the html, to enable the submit button.
Variables aren't being recognized by the html as defining the form.

Thanks
Art
"Geoff Berrow" <bl******@ckdog.co.ukwrote in message
news:lo********************************@4ax.com...
Message-ID: <na*******************@bignews7.bellsouth.netfro m Art
contained the following:
>>Sort of, but this is a scaled down version of the code, which was
requested.
I'm still stuck and still trying to understand why it's not working.

And you took no notice of my post on the subject before. You are still
echoing html /before/ the<htmltag!

I think you need something like this:

<?php

$holdchk = 0;
if (isset($_POST['B1'])) {
$form= "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk === 1 ){
$form.= "<form method=\"POST\" action=\"some.php\">";
}

if ($holdchk === 0 ){
$form.= "<form method=\"POST\" action=\"other.php\">";

}
}
?>

<html>

<head>
</head>

<?php echo $form;?>

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

May 4 '07 #9
Message-ID: <DX*******************@bignews8.bellsouth.netfro m Art
contained the following:
>Geoff, I tried modifying the code with your suggestions. It had the effect
of disabling the submit button. It seems like there has to be <form
method="POST" action=""in the html, to enable the submit button.
Variables aren't being recognized by the html as defining the form.
I was in a hurry last night because I was going out and not really
paying attention. Your code /is/ still seriously screwed but that
wasn't the solution.

Can you please describe what you /expect/ it to do? I'm sure the answer
is very simple.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
May 5 '07 #10
Geoff Berrow kirjoitti:
Message-ID: <DX*******************@bignews8.bellsouth.netfro m Art
contained the following:
>Geoff, I tried modifying the code with your suggestions. It had the effect
of disabling the submit button. It seems like there has to be <form
method="POST" action=""in the html, to enable the submit button.
Variables aren't being recognized by the html as defining the form.

I was in a hurry last night because I was going out and not really
paying attention. Your code /is/ still seriously screwed but that
wasn't the solution.

Can you please describe what you /expect/ it to do? I'm sure the answer
is very simple.
Your sample was missing the default form. It only worked in the case
when something was posted, but in the case the page is opened the first
time, there is no form tag at all...

So, once again, from the top...

<?php

$holdchk = 0;
if (isset($_POST['B1'])) { // if the form was submitted
$form= "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk === 1 ){
$form.= "<form method='POST' action='some.php'>";
}

if ($holdchk === 0 ){
$form.= "<form method='POST' action='other.php'>";

}
} else { // no form was submitted
$form = "<form method='POST' action='{$_SERVER['PHP_SELF']}'>";
}
?>

<html>

<head>
</head>

<?php echo $form;?>

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

I think this is what Geoff meant, he just forgot the default case. :)

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
May 5 '07 #11
Message-ID: <f1**********@nyytiset.pp.htv.fifrom Rami Elomaa contained
the following:
>I think this is what Geoff meant, he just forgot the default case. :)
LOL thanks Rami for seeing where I was going. :-)

But as I said, I'm sure we can find a far better way of accomplishing
what the OP wants to do.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
May 5 '07 #12
Art
Geoff, I'm just trying to have validation in my form. I check to see if
certain fields have values, if all the required fields have values, i want
to sent the data to another php form, that processes the request and sends
the data to a sql database and generates an email that a request has come
in.

The problem i'm having is that no matter what i do, the form will not submit
on the first click, even though all conditions are met. I've tested this by
echoing variables that let me know where i am in the code.

What's strange is that when i hit the submit button the 2nd time, it submits
ok.

I've tried your suggestions but the abscense of the form tag in the html
deactivated the submit button. I'm going to try the other suggestion.

You're also right in that it can no doubt be done better. I'm new to php
programming. I'm currently enrolled in a cis programming degreed course but
haven't gotten into my core curricula yet.

Thanks for your patience
Art
"Rami Elomaa" <ra*********@gmail.comwrote in message
news:f1**********@nyytiset.pp.htv.fi...
Geoff Berrow kirjoitti:
>Message-ID: <DX*******************@bignews8.bellsouth.netfro m Art
contained the following:
>>Geoff, I tried modifying the code with your suggestions. It had the
effect of disabling the submit button. It seems like there has to be
<form method="POST" action=""in the html, to enable the submit button.
Variables aren't being recognized by the html as defining the form.

I was in a hurry last night because I was going out and not really
paying attention. Your code /is/ still seriously screwed but that
wasn't the solution.

Can you please describe what you /expect/ it to do? I'm sure the answer
is very simple.

Your sample was missing the default form. It only worked in the case when
something was posted, but in the case the page is opened the first time,
there is no form tag at all...

So, once again, from the top...

<?php

$holdchk = 0;
if (isset($_POST['B1'])) { // if the form was submitted
$form= "<br><br><br>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

if ($holdchk === 1 ){
$form.= "<form method='POST' action='some.php'>";
}

if ($holdchk === 0 ){
$form.= "<form method='POST' action='other.php'>";

}
} else { // no form was submitted
$form = "<form method='POST' action='{$_SERVER['PHP_SELF']}'>";
}
?>

<html>

<head>
</head>

<?php echo $form;?>

When
hit the submit button</font></b<input
type="submit" value="Submit" name="B1"></p>
</form>
</body>

</html>

I think this is what Geoff meant, he just forgot the default case. :)

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

May 5 '07 #13
>Geoff, I'm just trying to have validation in my form. I check to see if
>certain fields have values, if all the required fields have values, i want
to sent the data to another php form,
You do realize that if it's important to check certain fields for valid
values, that it is just as important to check those fields for the SECOND
form ALSO, I hope?
>that processes the request and sends
the data to a sql database and generates an email that a request has come
in.
May 6 '07 #14
Art kirjoitti:
Geoff, I'm just trying to have validation in my form. I check to see if
certain fields have values, if all the required fields have values, i want
to sent the data to another php form, that processes the request and sends
the data to a sql database and generates an email that a request has come
in.
So you'll be requesting the user to submit it twice? That's complicating
things unnecessarily. Once you have validated, just insert them into the
database right away. You can do that by including the processing page if
the fields check okay.

Like this:

if($_POST['submit']){

if(!empty($_POST['field'])){

// Here you include the processing script
include('some.php');
exit();

}

}

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
May 6 '07 #15
Art
Thanks Geoff, that worked.

Art
"Rami Elomaa" <ra*********@gmail.comwrote in message
news:f1**********@nyytiset.pp.htv.fi...
Art kirjoitti:
>Geoff, I'm just trying to have validation in my form. I check to see if
certain fields have values, if all the required fields have values, i
want to sent the data to another php form, that processes the request and
sends the data to a sql database and generates an email that a request
has come in.

So you'll be requesting the user to submit it twice? That's complicating
things unnecessarily. Once you have validated, just insert them into the
database right away. You can do that by including the processing page if
the fields check okay.

Like this:

if($_POST['submit']){

if(!empty($_POST['field'])){

// Here you include the processing script
include('some.php');
exit();

}

}

--
Ra*********@gmail.com

"Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

May 8 '07 #16
"Art" <c_***@bellsouth.netwrote in message
news:cCZ%h.24665$vD4.23811@bigfe9...
Thanks Geoff, that worked.

Art

No problem Fred. :)

--
Ra*********@gmail.com

"Good tea. Nice house." -- Worf
May 8 '07 #17

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

Similar topics

4
by: mux | last post by:
Hi I found out that the following piece of code throws an error. 1 #include "stdio.h" 2 3 int main() 4 { 5 int a,b; 6 a= 10;
2
by: estafford | last post by:
I am having trouble writing a conditional block using ASP.NET and C#. I am trying to do something like this: 1. if page is PostBack - transfer to another page 2. if not postback - connect...
9
by: Marty | last post by:
Hi, Does using the the conditional operator (?:) instead of the common "if" statement will give a performance gain in a C# .NET 2003 application (even in C# .NET 2005?). What is the advantage...
5
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
43
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. ...
0
by: RCapps | last post by:
When running the below SQL Query I keep getting the following error: Server: Msg 4924, Level 16, State 1, Line 1 ALTER TABLE DROP COLUMN failed because column 'ContractDef' does not exist in table...
10
by: strife | last post by:
Hi, This is a homework question. I will try to keep it minimal so not to have anyone do it for me. I am really just stuck on one small spot. I have to figure out the highest number from a users...
13
by: Neal Becker | last post by:
In hindsight, I am disappointed with the choice of conditional syntax. I know it's too late to change. The problem is y = some thing or other if x else something_else When scanning this my...
7
by: tiptap | last post by:
Hey Guys, I have a huge statement loads of if statements in... and its getting bigger. On closer inspection there is only 3 difference in the select statement. so I thought I could cut the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.