...

View Full Version : trying to do != in an HTML form



cuz
10-31-2003, 01:11 PM
Hello. I'm trying to create a form that outputs to a PHP page. The form has 2 fields in it: one called "fname" and the other called "lname."I need the PHP page to say that "if the fname field was left blank, print the info in the lname field. Otherwise, print the fname field." My present PHP code looks like this:


if ($fname != $fname) {
print ($lname);
} else {
print ($fname);
}

I've tried other variations such as "$fname = !$fname,"($fname == $fname," "$fname <> $fname," and "$fname = 0," but I can't get things to work my way. Can anyone tell me where I went wring?

Thanx in advance...
cuz

Nightfire
10-31-2003, 01:26 PM
<?php
$fname = $_POST['fname'];
$lname = $_POST['lname'];

if(!isset($fname)){
echo $lname;
}else{
echo $fname;
}

?>


<edit>Just improved it a bit</edit>

Something like that?

cuz
10-31-2003, 01:50 PM
Hey Nightfire. Thanks for the help!

I changed the PHP code to what you posted before and after you edited it. Unfortunatly, it's stll a no-go. Could it be something on my end? If you would like to see the HTML form, it's posted here (http://www.passionatemusic.net/join/). The field at the top is "fname" and the one below it is "lname."

Thanx again!
-cuz

pb&j
10-31-2003, 03:37 PM
$fname = $_REQUEST['fname'];
$lname = $_REQUEST['lname'];
if (!$fname) {
print ($lname);
} else {
print ($fname);
}

or


$fname = $_REQUEST['fname'];
$lname = $_REQUEST['lname'];
if ($fname=="") {
print ($lname);
} else {
print ($fname);
}

cuz
10-31-2003, 04:33 PM
Hey pbj! Thanx for the help!

Unfortunatly I still can't get it to work properly. I've checked the HTML form and the fields are definetly named right. I've checked the PHP settings on my webhost and anyplace that "REQUEST" is listed, it's given a value of "GET." I've changed the form's method from "POST" to "GET" a few times and still no go.

Am I screwed beyond belief?

Nightfire
10-31-2003, 04:52 PM
just try this, for curiosty really



print_r($_POST);


See if that shows anything

cuz
10-31-2003, 05:01 PM
Hey Nightfire. When my PHP code is this:


print_r($_POST);

And I enter the name "cuz" in the "fname" field, I get an output of this:

Array ( [fname] => cuz [lname] => [ad1] => [ad2] => [city] => [state] => Select A State [zip] => [Submit] => Submit )

Thanx again!
cuz

nicklim
11-06-2003, 10:15 AM
hmm
no problem with fname...

you are not passing your lname...
try filling in lname also
if it is still not passing it, this could mean an error within your form tags....

btw i usually do this
(but i use it for check boxes..)

$fname = (isset($_POST['fname'])? $_POST['fname'] : "" );
$lname = (isset($_POST['lname'])? $_POST['lname'] : "" );

if ( $fname == "" ) {
echo $lname;
} else {
echo $fname;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum