Someone tell me I'm not going mad...
#1
..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
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
#2
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
so it would be echo $HTTP_GET_VARS["name"];
Hanven't got my book with me but would assume it $HTTP_POST_VARS[] ?
Deano
#3
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!
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!
#5
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...
#6
$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];
just use this instead: $_POST[varnamehere]
e.g.
echo $_POST[name];
Trending Topics
Thread
Thread Starter
Forum
Replies
Last Post