Passing form values
Moderator: General Moderators
Passing form values
I'm new to all this PHP stuff....
I'm having trouble passing form values when I run my scripts on localhost. When I run my scripts on localhost I get this error
Notice: Undefined variable: text_fname in c:\inetpub\wwwroot\php_fun\form1_action.php on line 23
Even though I've tested to make sure the values are being passed using the GET method.
Also when I upload the pages to the server the scripts work fine.
Any help would be great.
Thanks!
Emily
I'm having trouble passing form values when I run my scripts on localhost. When I run my scripts on localhost I get this error
Notice: Undefined variable: text_fname in c:\inetpub\wwwroot\php_fun\form1_action.php on line 23
Even though I've tested to make sure the values are being passed using the GET method.
Also when I upload the pages to the server the scripts work fine.
Any help would be great.
Thanks!
Emily
Notice (pun intended) that the message says notice.Notice: Undefined variable: text_fname in c:\inetpub\wwwroot\php_fun\form1_action.php on line 23
What it's saying is that the script is trying to do something with a var that doesn't exist. I can understand that it probably will exist later in the script, but at line 23, it doesn't. The easy thing to do is somewhere like line 1 say error_reporting(0) for when the script has been uploaded to the production server.
Let's see the code. It's probably something simple to sort out.
Cheers,
BDKR
Here's the code
Like I said before it works fine on the server and the code is quite simple. It just won't work using IIS on my local machine.
thanks for you help
Here's the code:
form1.php
<html>
<head>
<title>FORM 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="includes/styles.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form method=GET action="form1_action.php">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">First Name</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_fname">
</td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">Last Name</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_lname">
</td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">Address</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_address">
</td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">City </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_city">
</td>
</tr>
<tr>
<td width="10" height="21"> </td>
<td width="100" align="left" valign="top" class="body" height="21">State</td>
<td width="10" height="21"> </td>
<td width="180" align="left" valign="top" class="body" height="21">
<select name="select_state">
<option value="PA">PA</option>
<option value="CO">CO</option>
</select>
</td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">Zip</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_zip">
</td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<input type="submit" name="Submit" value="Submit">
</td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
</table>
</form>
</body>
</html>
form1_action.php
<html>
<head>
<title>FORM 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="includes/styles.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">First Name</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<?php
print "Your First Name is $text_fname";
?></td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">Last Name</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">Address</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">City </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10" height="21"> </td>
<td width="100" align="left" valign="top" class="body" height="21">State</td>
<td width="10" height="21"> </td>
<td width="180" align="left" valign="top" class="body" height="21"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">Zip</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
</table>
</body>
</html>
thanks for you help
Here's the code:
form1.php
<html>
<head>
<title>FORM 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="includes/styles.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form method=GET action="form1_action.php">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">First Name</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_fname">
</td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">Last Name</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_lname">
</td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">Address</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_address">
</td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">City </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_city">
</td>
</tr>
<tr>
<td width="10" height="21"> </td>
<td width="100" align="left" valign="top" class="body" height="21">State</td>
<td width="10" height="21"> </td>
<td width="180" align="left" valign="top" class="body" height="21">
<select name="select_state">
<option value="PA">PA</option>
<option value="CO">CO</option>
</select>
</td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">Zip</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_zip">
</td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<input type="submit" name="Submit" value="Submit">
</td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
</table>
</form>
</body>
</html>
form1_action.php
<html>
<head>
<title>FORM 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="includes/styles.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">First Name</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body">
<?php
print "Your First Name is $text_fname";
?></td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">Last Name</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">Address</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">City </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10" height="21"> </td>
<td width="100" align="left" valign="top" class="body" height="21">State</td>
<td width="10" height="21"> </td>
<td width="180" align="left" valign="top" class="body" height="21"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body">Zip</td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
<tr>
<td width="10"> </td>
<td width="100" align="left" valign="top" class="body"> </td>
<td width="10"> </td>
<td width="180" align="left" valign="top" class="body"> </td>
</tr>
</table>
</body>
</html>
Reason for using Get
I only put get in there to test to make sure the values were being passed....I would normally use POST....
Let me know if you think of anything else....
Thanks for your time.
Let me know if you think of anything else....
Thanks for your time.
I found the answer
You have to go into your php.ini file and change the register_global variable to on.
Phew!! Hope this helps someone out.
Phew!! Hope this helps someone out.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
One reason for not putting register_globals on (and this is covered here: viewtopic.php?t=511) and for learning to cope with it off, is that it is now been deprecated so it is not going to be around for ever at some point you are going to have to rewrite all your scripts if they all rely on reg_globals on.
Mac
Mac