Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Someone tell me I'm not going mad...

Thread Tools
 
Search this Thread
 
Old 06 August 2002, 03:05 PM
  #1  
Trotty
Scooby Regular
Thread Starter
 
Trotty's Avatar
 
Join Date: Feb 2002
Posts: 179
Likes: 0
Received 0 Likes on 0 Posts
Post

..because I'm got a daft problem with some php code.

This is a really simple bit. I've got a combo box on a form with some names listed like so:

<form action="newtest.php" method="post">
<select name="name">
<option selected>Choose your name...</option>
<option>Fred</option>
<option>Bob</option>
<option>Dave</option>
<option>Billy</option>
<option>Joe</option>
<option>Harry</option>
</select>
<input type="submit" value="Search">
</form>

When the form is submitted I'm right in saying that the result will be passed as a variable called 'name' into the newtest.php page yes?

So on the next page I say:

<?php
echo $name;
?>

for example.

I've done this before with no problems, but now I'm getting "Undefined variable" errors on the newtest.php page?

Any clues? I 'm only fiddling about at the moment. I've done this sort of thing previously and it was ok?

Ian
Old 06 August 2002, 03:15 PM
  #2  
dsmith
Scooby Regular
 
dsmith's Avatar
 
Join Date: Mar 1999
Posts: 4,518
Likes: 0
Received 0 Likes on 0 Posts
Post

for GET methods they're returned in an array called $HTTP_GET_VARS[]

so it would be echo $HTTP_GET_VARS["name"];

Hanven't got my book with me but would assume it $HTTP_POST_VARS[] ?

Deano
Old 06 August 2002, 03:21 PM
  #3  
Trotty
Scooby Regular
Thread Starter
 
Trotty's Avatar
 
Join Date: Feb 2002
Posts: 179
Likes: 0
Received 0 Likes on 0 Posts
Post

Ta for the reply. I don't think that's necessary with this though - this is just a very simple test.

Usually the select name for the form will be carried over as the variable name so...

<select name="poop">

on the form page can be used as

echo $poop

on the php page.

Can't work it out?? Tis a nice and simple test, nothing more. Could it be how php is set up on my web server? Had it running locally before with no problems, moved it to another machine on our LAN this morning with php & mySQL installed and it's now tit's up!

D'oh!
Old 06 August 2002, 03:32 PM
  #4  
AdrianFRST
Scooby Regular
 
AdrianFRST's Avatar
 
Join Date: Oct 2000
Posts: 368
Likes: 0
Received 0 Likes on 0 Posts
Post

Pretty sure this is something to do with the PHP config on the server.

My test server (Win2k) complains about undefined variables, but when uploaded live (RedHat) it works fine.
Old 06 August 2002, 03:38 PM
  #5  
Trotty
Scooby Regular
Thread Starter
 
Trotty's Avatar
 
Join Date: Feb 2002
Posts: 179
Likes: 0
Received 0 Likes on 0 Posts
Post

That's what I'm thinking... Odd thing is, before I was running it locally (Win2K, IIS5, mysql, php 4.2.1) and this other machine has got the same config? I'm just re-installing php, etc at the mo...
Old 06 August 2002, 03:51 PM
  #6  
legacyPete
Scooby Regular
 
legacyPete's Avatar
 
Join Date: Dec 2001
Posts: 202
Likes: 0
Received 0 Likes on 0 Posts
Post

$HTTP_POST_VARS is deprecated in newer versions of PHP. Also, if register_globals is turned off (it's off by default) you will not be able to access form variables by name - e.g $name

just use this instead: $_POST[varnamehere]

e.g.
echo $_POST[name];
Old 06 August 2002, 04:00 PM
  #7  
Trotty
Scooby Regular
Thread Starter
 
Trotty's Avatar
 
Join Date: Feb 2002
Posts: 179
Likes: 0
Received 0 Likes on 0 Posts
Post

Once again to the rescue Pete, thanks a lot

It's been a while since I installed PHP and had forgotton about the 'register_globals' bit.

Thanks,

Ian
Old 06 August 2002, 04:17 PM
  #8  
dsmith
Scooby Regular
 
dsmith's Avatar
 
Join Date: Mar 1999
Posts: 4,518
Likes: 0
Received 0 Likes on 0 Posts
Post

is HTTP_GET_VARS deprecated aswell ?
Old 06 August 2002, 04:27 PM
  #9  
legacyPete
Scooby Regular
 
legacyPete's Avatar
 
Join Date: Dec 2001
Posts: 202
Likes: 0
Received 0 Likes on 0 Posts
Post

Yep, you can still use them though. They should work if you call them globally e.g.

global $HTTP_POST_VARS;
echo $HTTP_POST_VARS[brains];

...but it's better to use the new ones for future compatibility etc. Also the new ones are already global, so less messin' about.

See here for more.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
willN
Lighting and Other Electrical
1
09 June 2012 08:47 PM
Alan Jeffery
Non Scooby Related
1
24 March 2012 08:48 AM
joz8968
Non Scooby Related
14
12 June 2011 10:29 AM
dervdriver
ScoobyNet General
11
26 March 2010 09:59 PM
Bullit 65
Wheels, Tyres & Brakes
5
15 September 2008 09:26 AM



Quick Reply: Someone tell me I'm not going mad...



All times are GMT +1. The time now is 08:19 AM.