Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    cuz
    cuz is offline
    New Coder
    Join Date
    Mar 2003
    Location
    New Chursey
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    trying to do != in an HTML form

    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:

    PHP Code:
    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
    -cUz

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    <?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?
    Last edited by Nightfire; 10-31-2003 at 01:34 PM.

  • #3
    cuz
    cuz is offline
    New Coder
    Join Date
    Mar 2003
    Location
    New Chursey
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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. The field at the top is "fname" and the one below it is "lname."

    Thanx again!
    -cuz
    -cUz

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Canada
    Posts
    253
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $fname $_REQUEST['fname'];
    $lname $_REQUEST['lname'];
    if (!
    $fname) {
    print (
    $lname);
    } else {
    print (
    $fname);

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


  • #5
    cuz
    cuz is offline
    New Coder
    Join Date
    Mar 2003
    Location
    New Chursey
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    -cUz

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    just try this, for curiosty really

    PHP Code:
    print_r($_POST); 
    See if that shows anything

  • #7
    cuz
    cuz is offline
    New Coder
    Join Date
    Mar 2003
    Location
    New Chursey
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey Nightfire. When my PHP code is this:

    PHP Code:
    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
    -cUz

  • #8
    New Coder
    Join Date
    Oct 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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;
    }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •