473,785 Members | 3,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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><b r>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

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

}

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
16 1762
Geoff Berrow kirjoitti:
Message-ID: <DX************ *******@bignews 8.bellsouth.net from 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><b r>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

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

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

}
} else { // no form was submitted
$form = "<form method='POST' action='{$_SERV ER['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*********@gma il.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**********@n yytiset.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*********@gm ail.comwrote in message
news:f1******** **@nyytiset.pp. htv.fi...
Geoff Berrow kirjoitti:
>Message-ID: <DX************ *******@bignews 8.bellsouth.net from 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><b r>";
if (empty($_POST['app_fname'])) {
$holdchk = 1;
}

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

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

}
} else { // no form was submitted
$form = "<form method='POST' action='{$_SERV ER['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*********@gma il.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($_POS T['field'])){

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

}

}

--
Ra*********@gma il.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*********@gm ail.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($_POS T['field'])){

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

}

}

--
Ra*********@gma il.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_***@bellsout h.netwrote in message
news:cCZ%h.2466 5$vD4.23811@big fe9...
Thanks Geoff, that worked.

Art

No problem Fred. :)

--
Ra*********@gma il.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
4690
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
1619
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 to database and get information using a querystring id and create a DataReader (as DR). - generate a Form to display using values from the database query.
9
4783
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 of using it in C# other than typing shorter if ? Thanks, Marty
5
2905
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
7587
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. How is it possible? Please help me. Thanks in advance.
0
4130
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 'zContractDefault'. For some reason it is only returning the first 11 chars of the column name? Any help would be greatly appreciated... This query searches a DB and determines which columns are 'Invalid' if the column name is >30 and...
10
4376
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 input. I give them a menu to choose from, and I am stuck on only one of the choices. When this choice is picked I must allow the user to enter how many numbers he/she wants to enter; then I must figure out which number is the highest. I have...
13
1559
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 eye tends to see the first phrase and only later notice that it's conditioned on x (or maybe not notice at all!). Particularly if 'some thing or other' is long or complicated.
7
4315
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 whole thing down to just 1 select statement if I have a conditional Having. I've simplified the IF statement down a bit to give you an idea of what im trying to achieve IF @month <> 0 & @diffFuture = 0 & @showDate <> 0
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.