Web Hosting Talk







View Full Version : Php help; Sending data through forms!


1jetsam
04-22-2004, 12:22 AM
ok, I have done stuff like this dozens of times, but right now, its pretending that the variables don't even egsist!

$DMG1 = "{$_POST['DMG1']}";
$DMG2 = "{$_POST['DMG2']}";
$DMG3 = "{$_POST['DMG3']}";

even though on the previous page:

<input name="DMG1" type="hidden" value="<? rand (1,6); ?>">
<input name="DMG2" type="hidden" value="<? rand (1,8); ?>">
<input name="DMG3" type="hidden" value="<? rand (1,8); ?>">

The script sences nothing wrong, but the output, should actually have an output instead of a blank.
Thanks very much!

mshowman
04-22-2004, 01:01 AM
You need to add "echo" to the input values to get php to actually spit the results into the "value" tag.


<input name="DMG1" type="hidden" value="<? echo rand(1,6); ?>">
<input name="DMG2" type="hidden" value="<? echo rand(1,8); ?>">
<input name="DMG3" type="hidden" value="<? echo rand(1,8); ?>">

1jetsam
04-22-2004, 01:29 AM
Thanks alot...I would of never thought of that. Great annalise!

Burhan
04-22-2004, 03:00 AM
Or, you can just use <?= which echoes output.

<?= $foo; ?>

is the same as

<? echo $foo; ?>

trukfixer
04-22-2004, 12:21 PM
Originally posted by 1jetsam
ok, I have done stuff like this dozens of times, but right now, its pretending that the variables don't even egsist!

$DMG1 = "{$_POST['DMG1']}";
$DMG2 = "{$_POST['DMG2']}";
$DMG3 = "{$_POST['DMG3']}";

even though on the previous page:

<input name="DMG1" type="hidden" value="<? rand (1,6); ?>">
<input name="DMG2" type="hidden" value="<? rand (1,8); ?>">
<input name="DMG3" type="hidden" value="<? rand (1,8); ?>">

The script sences nothing wrong, but the output, should actually have an output instead of a blank.
Thanks very much!

and lose the curly braces and quotes.. not really needed..

do:


$DMG1=$_POST['DMG1'];
echo "$DMG1"; //should print out the value of DMG1


is just as simple easy to do.. you're simply assigning the post array element of DMG1 to the variable $DMG1...