1) How do I write a simple code that says something to the effect that if form field $old is empty (i.e. no entered values) than values from form field $new in the same form should be sent to the database instead.
And, 2) I would put this code in the page that processes the form and not the in the form page itself, correct? Is there any special place it need to go on that page?
Many thanks
if (empty)....do - can't figure this code out
Moderator: General Moderators
-
Jim_Madrid
- Forum Newbie
- Posts: 1
- Joined: Sat Feb 01, 2003 10:11 am
Code: Select all
<?php
if(empty($_POST[old_field_name]))
{
$new_var = $_POST[new_field_name];
//rest of the code goes in here
}
?>Code: Select all
<?php
if(isset($_POST[field_name]))
{
//..code here
}
?>Thanks alot...being very new to php I still don't understand this completely and have a few questions. Let's say I have the following:
text box form field name = "phylum"
select box form field name = "new_phylum"
database field name = "phylum"
According to the script you sent:
1. does old_field_name refer to the database field "phylum" or the text box form field of the same name?
2. does $new_var refer to my select box "new_phylum"
3. what does new_field_name refer to?
4. I am also not sure what remaining code is to be placed in //rest of the code goes in here.
<?php
if(empty($_POST[old_field_name]))
{
$new_var = $_POST[new_field_name];
//rest of the code goes in here
}
?>
I am also pretty much at a loss to understand what fields correspond to the hidden form field.
<?php
if(isset($_POST[field_name]))
{
//..code here
}
1. Does field name refer to the database field "phylum" in this case?
2. what code goes in the //....code here? the previous code from above?
As you can see I am very new....your patience and assistance is greatly appreciated, believe me
Thanks
Jim
text box form field name = "phylum"
select box form field name = "new_phylum"
database field name = "phylum"
According to the script you sent:
1. does old_field_name refer to the database field "phylum" or the text box form field of the same name?
2. does $new_var refer to my select box "new_phylum"
3. what does new_field_name refer to?
4. I am also not sure what remaining code is to be placed in //rest of the code goes in here.
<?php
if(empty($_POST[old_field_name]))
{
$new_var = $_POST[new_field_name];
//rest of the code goes in here
}
?>
I am also pretty much at a loss to understand what fields correspond to the hidden form field.
<?php
if(isset($_POST[field_name]))
{
//..code here
}
1. Does field name refer to the database field "phylum" in this case?
2. what code goes in the //....code here? the previous code from above?
As you can see I am very new....your patience and assistance is greatly appreciated, believe me
Thanks
Jim
This is a modification of my previous message. I believe my questions may be clearer here.
In essence this is what I have created. I have a text box in which researchers enter new phylum names into a database. Once those names are entered they appear in the new_phylum select box once the form is refreshed. What I would like to do is make it possible for the researchers to either select a name from the select box or type in a new name...one of the two will then be sent to the database.
text box form field name = "phylum"
select box form field name = "new_phylum"
database field name = "filo"
database table name= museum
According to the script you sent have I filled in the statement correctly with the names I am using?
<?php
$sql="";
if(empty($_POST['phylum']))
{
$new_phylum= $_POST['new_phylum'];
$sql="INSERT INTO museum (filo) values ('$new_phylum');
}
?>
Is this the correct place to put the INSERT INTO statement or should that go in the hidden field as a form variable for example
Regarding the hidden field:
1. What should the field_name be for my above example? Does it need to match one of my other field names?
2. Is this where I should put the INSERT INTO statement?
<?php
if(isset($_POST[field_name]))
{
//..code here
}
Again, your patience and assistance is greatly appreciated, believe me
Thanks
Jim
In essence this is what I have created. I have a text box in which researchers enter new phylum names into a database. Once those names are entered they appear in the new_phylum select box once the form is refreshed. What I would like to do is make it possible for the researchers to either select a name from the select box or type in a new name...one of the two will then be sent to the database.
text box form field name = "phylum"
select box form field name = "new_phylum"
database field name = "filo"
database table name= museum
According to the script you sent have I filled in the statement correctly with the names I am using?
<?php
$sql="";
if(empty($_POST['phylum']))
{
$new_phylum= $_POST['new_phylum'];
$sql="INSERT INTO museum (filo) values ('$new_phylum');
}
?>
Is this the correct place to put the INSERT INTO statement or should that go in the hidden field as a form variable for example
Regarding the hidden field:
1. What should the field_name be for my above example? Does it need to match one of my other field names?
2. Is this where I should put the INSERT INTO statement?
<?php
if(isset($_POST[field_name]))
{
//..code here
}
Again, your patience and assistance is greatly appreciated, believe me
Thanks
Jim