Passing form values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ylime243
Forum Newbie
Posts: 4
Joined: Fri Nov 15, 2002 12:19 pm

Passing form values

Post by ylime243 »

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
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Notice: Undefined variable: text_fname in c:\inetpub\wwwroot\php_fun\form1_action.php on line 23
Notice (pun intended) that the message says notice. 8O Your script will probably work just fine once inspite of it.

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
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

I agree. It would be helpful to see your code. At least several lines before and after it.
ylime243
Forum Newbie
Posts: 4
Joined: Fri Nov 15, 2002 12:19 pm

Here's the code

Post by ylime243 »

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">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">&nbsp;</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">&nbsp;</td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">First Name</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_fname">
</td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">Last Name</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_lname">
</td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">Address</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_address">
</td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">City </td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_city">
</td>
</tr>
<tr>
<td width="10" height="21">&nbsp;</td>
<td width="100" align="left" valign="top" class="body" height="21">State</td>
<td width="10" height="21">&nbsp;</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">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">Zip</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">
<input type="text" name="text_zip">
</td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">&nbsp;</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">&nbsp;</td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">&nbsp;</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">
<input type="submit" name="Submit" value="Submit">
</td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">&nbsp;</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">&nbsp;</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">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">&nbsp;</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">&nbsp;</td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">First Name</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">
<?php

print "Your First Name is $text_fname";


?></td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">Last Name</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">&nbsp;</td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">Address</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">&nbsp; </td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">City </td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">&nbsp; </td>
</tr>
<tr>
<td width="10" height="21">&nbsp;</td>
<td width="100" align="left" valign="top" class="body" height="21">State</td>
<td width="10" height="21">&nbsp;</td>
<td width="180" align="left" valign="top" class="body" height="21">&nbsp; </td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">Zip</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">&nbsp; </td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">&nbsp;</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">&nbsp;</td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">&nbsp;</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">&nbsp; </td>
</tr>
<tr>
<td width="10">&nbsp;</td>
<td width="100" align="left" valign="top" class="body">&nbsp;</td>
<td width="10">&nbsp;</td>
<td width="180" align="left" valign="top" class="body">&nbsp;</td>
</tr>
</table>
</body>
</html>
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

You are right in that it works on unix. I did notice you useing GET instead of POST. Any reason for that. I personally dont like all the fields getting put in the URL.

Sorry I am not any help for you. I run 2k but dont have it setup for any local web testing.
ylime243
Forum Newbie
Posts: 4
Joined: Fri Nov 15, 2002 12:19 pm

Reason for using Get

Post by ylime243 »

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.
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

That makees more sence then what I do. I usualy echo it out while setting up stuff to enter a DB. then remove it once i see it is working.
ylime243
Forum Newbie
Posts: 4
Joined: Fri Nov 15, 2002 12:19 pm

I found the answer

Post by ylime243 »

You have to go into your php.ini file and change the register_global variable to on.


Phew!! Hope this helps someone out.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

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
Post Reply