1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

PHP / html coding problem

Discussion in 'Software Development' started by Brooook, Oct 4, 2003.

Thread Status:
Not open for further replies.
Advertisement
  1. Brooook

    Brooook Thread Starter

    Joined:
    Oct 27, 2002
    Messages:
    164
    or is it a PHP config problem?

    I am teaching myself PHP / MySQL and getting to the coding stage and written some complex code that doesn't work. So figured it wasn't getting the input and went right back to the basics.

    Here is the coding for a simple HTML input to a simple PHP file. I put in the boolean functions so I could see if, infact, the data was getting input.

    No matter what I entered, or if I did not enter anything, the functions would return as NOT isset, and display 1 as IS empty. So I think the problem is I am not getting the data from HTML to the PHP file.

    Am I missing something simple in the code? Or have I not configured the php.ini correct?

    I have noone to ask and thought the code was correct (copied from learning text!). HELP

    //simplehtml.html

    <HTML>
    <HEAD>
    <TITLE><Simple HTML / PHP form> </TITLE>
    </HEAD>
    <BODY>
    <h1>Simple HTML / PHP form</h1>
    <form action="oknow.php" method="POST">
    Name: <input type="text" name="username"><br>
    Email: <input type="text" name="email"><br>
    <input type="submit" name="submit" value="Submit me!">
    </form>
    </BODY>
    </HTML>

    //---------------------------------------------------------------

    //oknow.php

    <HTML>
    <HEAD>
    <TITLE><OK Lets see what happens> </TITLE>
    </HEAD>
    <BODY>
    <h1>OK Lets see what happens</h1>
    <?php
    echo "<p> <br>";
    echo isset($username);
    echo "isset username <br>";
    echo isset($email);
    echo "isset email <br>";
    echo empty($username);
    echo "empty username <br>";
    echo empty($email);
    echo "empty email ";
    ?>
    </body>
    </html>
     
  2. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    First, $email should be
    $_POST['email']
    etc. You probably also want to use some IF statements...or the output is going to look strange.
     
  3. Brooook

    Brooook Thread Starter

    Joined:
    Oct 27, 2002
    Messages:
    164
    I have been pulling my hair out all day over this!!!

    Don't worry, it was just test code and I knew what it meant. After correcting the PHP file it came back TRUE for isset and FALSE for empty so I knew it was the answer. I then corrected the more complex code (searching for books, connecting to a database , etc) and WOW it works. I was so worried it wasn't connecting to MySQL and finally narrowed it down to it not inputing my search terms etc.

    THANK YOU. I did see $_POST in my PHP manual but it is not written in any of the test codes that I was learning (and typing out manually) so didn't quite know what to make of it. Now it will always be included.

    THANK YOU AGAIN
     
  4. deuce868

    deuce868

    Joined:
    Nov 2, 2000
    Messages:
    637
    it looks like you are using global variables set to on in your php.ini. This is a very insecure method of running the server. The reason the $_POST is in there is to specify you want the variables that was POSTED not one passed in the url and such.

    I would HIGHLY recommend that you spend some time looking into what global variables are and why they are bad.
     
  5. Brooook

    Brooook Thread Starter

    Joined:
    Oct 27, 2002
    Messages:
    164
    and had checked my php.ini file and the register_globals was set to Off. It has always been that way - is that why it DIDN'T work until I corrected the code to $_POST? I had thought of changing it to On to see if this corrected the problem but I didn't want to for the reasons in your post and the $_POST worked so I didn't touch it.

    The best thing I did was ask for TSG help before I changed things in php.ini. It took weeks (without help) to get the appropriate settings in the different config files for PHP, MySQL & Apache to communicate so I was loathe to change anything!
     
  6. brendandonhu

    brendandonhu

    Joined:
    Jul 8, 2002
    Messages:
    14,681
    Yes, changing register_globals to On would have fixed the problem, but things are better with no global variables.
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/169401

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice