PHP / html coding problem

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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>
 
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.
 

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
 
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.
 

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!
 
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.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Members online

Top