Page 1 of 1

PHP is not parsing values through a form.

Posted: Sun Jun 13, 2004 4:16 am
by funkymeerkat
Can somebody please help.

I use to develop webpages with php about 3 years back and at a reasonable level - however i never actually dealt with the setup of php and mysql etc - just coded.

Now the problem i've got is that when i create a page with a form on it and then try to parse the info through to the next page and insert into my table....there is no info appearing in the table.

It IS creating a row but with empty fields.

I have checked my html tags etc and is no problem with the actual basic code.

When i do a form to just display the values on the next page - nothing appears too.

I have been looking through the forums and notice that in the latest versions of php the php.ini file has the register_globals set to off - i have turned this on as it said it would help. No joy!

please see below my basic form code - can u see anything wrong here.....?

Add User Page

Code: Select all

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>

<FORM ACTION="add.php" METHOD="post" name="form"> 

Real Name: 
  <INPUT type="text" name="real_name" SIZE=20 MAXLENGTH=70>
<Br> 

Username: <INPUT type="text" name="username" SIZE=20 MAXLENGTH=70>
<Br> 

Password: <Input type="text" name="password" Size=10 Maxlength=70>
<Br> 

E-mail address: <Input type="text" name="email" Size=20 Maxlength=70>
<Br> 

<INPUT TYPE=submit VALUE="Add">  

<INPUT type=reset VALUE="Reset Form">

</form> 

</body>
</html>
Added User Page

Code: Select all

<?php
mysql_connect("localhost","username","password");
mysql_select_db (test);
$query = ("INSERT INTO users (id, real_name, username, password, email) 
                VALUES ('$ID', '$real_name', '$username', '$password', '$email') "); 
$result = mysql_query($query);
echo '$real_name Entered.';
?>
PLEASE HELP :)

Posted: Sun Jun 13, 2004 4:20 am
by markl999
register_globals is Off by default since PHP 4.2.0 (which is a good thing) but your code requires register_globals to be On (which is not so good ;))
Instead of using $real_name (which won't be set) use $_POST['real_name']
E.g.

Code: Select all

//not sure where you set $ID but it doesn't appear to be part of the form
$query = "INSERT INTO users (id, real_name, username, password, email)
                VALUES ('$ID', '{$_POST['real_name']}', '{$_POST['username']}', '{$_POST['password']}', '{$_POST['email']}') ";
For more info on register_globals see http://php.net/variables.predefined

Posted: Sun Jun 13, 2004 4:26 am
by funkymeerkat
Nice one mate - i appreciate that.

So has php changed that much....coz i never had to do it like that before...the way i had it always used to work.

Posted: Sun Jun 13, 2004 4:29 am
by markl999
It's just the change in the default setting of register_globals, before 4.2.0 it was On, now it's Off :0
You can just edit your php.ini and set it to On and it will work as before, but it's not recommended.