Connecting Tech Pros Worldwide Forums | Help | Site Map

Passing parameters from HTML to PHP

Dave Kelly
Guest
 
Posts: n/a
#1: Sep 26 '06
I'm posting on this again. Sorry I am so thick heading but I do not
understand why this failure.

I have put in some 'printf' statements for debugging and some comments.
And some questions.

From the menu.html page

<html>
<a href="guestbook.php?var1=list-PINSS.txt"><h3>Padre Island National
Sea Shore</h3></a><br>
<a href="guestbook.php?var1=list-LHL.txt"><h3>Light House
Lakes</h3></a><br>
<a href="guestbook.php?var1=list-7LD.txt"><h3>7 Lakes Damon</h3></a><br>
<a href="guestbook.php?var1=list-GR.txt"><h3>Guadalupe River</h3></a><br>
</html>

To the PHP file
<?php

include $_GET['var1']; //prints to screen the correct information
$file=$_GET['var1'];

printf("-----%s", $var1); // prints nothing.
printf("+++++%s", $file); // prints to the screen the correct information.

error_reporting(1);
$mode=$_GET['mode'];
if($mode!='view' && $mode!='sign') $mode=$_POST['mode'];
if($mode!='view' && $mode!='sign') $mode='sign';
$name=$_POST['name'];
$site=$_POST['site'];
$phone=$_POST['phone'];
$date=date('l, F dS, Y (g:i A T)');
$self=$_SERVER['PHP_SELF'];
printf(;// prints to the screen the correct information.
($handle=fopen($file,'a+') or die("Could not open file: $file"));// FAILS
....................
....................
?>

This is the way it appears on the screen....
Sunday, September 24th, 2006 (4:10 PM CDT) Dafydd Cealleigh
daveecealleig@ireland.nat lets go fishing Sunday, September 24th, 2006
(4:30 PM CDT) Dave Kelly daveecealleig@ireland.nat Sunday, September
24th, 2006 (4:53 PM CDT) Jim Kloss daveecealleig@ireland.nat Sunday,
September 24th, 2006 (5:01 PM CDT) Wilson Harmon will@harmon.cum 936 894
1710 Sunday, September 24th, 2006 (5:11 PM CDT) Alfred E Newman
49wist@vista.fiv 1234483298374

Notice: Undefined variable: var1 in
/var/www/vhosts/texasflyfishers.org/httpdocs/guestbook.php on line 22

-----+++++list-PINSS.txt_____list-PINSS.txt_____

Why does $file contain 'list-PINSS.txt' in printf ("_____%s_____",
$file) and 'var1' in ($handle=fopen($file,'a+')?

Jerry Stuckle
Guest
 
Posts: n/a
#2: Sep 26 '06

re: Passing parameters from HTML to PHP


Dave Kelly wrote:
Quote:
I'm posting on this again. Sorry I am so thick heading but I do not
understand why this failure.
>
I have put in some 'printf' statements for debugging and some comments.
And some questions.
>
From the menu.html page
>
<html>
<a href="guestbook.php?var1=list-PINSS.txt"><h3>Padre Island National
Sea Shore</h3></a><br>
<a href="guestbook.php?var1=list-LHL.txt"><h3>Light House
Lakes</h3></a><br>
<a href="guestbook.php?var1=list-7LD.txt"><h3>7 Lakes Damon</h3></a><br>
<a href="guestbook.php?var1=list-GR.txt"><h3>Guadalupe River</h3></a><br>
</html>
>
To the PHP file
<?php
>
include $_GET['var1']; //prints to screen the correct information
What are you printing? Does the included file do it?
Quote:
$file=$_GET['var1'];
>
printf("-----%s", $var1); // prints nothing.
That's because $var1 isn't defined. Perhaps you're using an old text or
code that ran with register_globals enabled. That's a security hole,
and the default now is to have it turned off (as it should be).

Use

printf("-----%s", $_GET['var1']);

instead, as you had it in the include statement.
Or,

$var1 = $_GET['var1'];

and your current printf will work.

Quote:
printf("+++++%s", $file); // prints to the screen the correct information.
>
error_reporting(1);
$mode=$_GET['mode'];
if($mode!='view' && $mode!='sign') $mode=$_POST['mode'];
Which method is your form using - GET or POST? One or the other.
Quote:
if($mode!='view' && $mode!='sign') $mode='sign';
$name=$_POST['name'];
$site=$_POST['site'];
$phone=$_POST['phone'];
$date=date('l, F dS, Y (g:i A T)');
$self=$_SERVER['PHP_SELF'];
printf(;// prints to the screen the correct information.
($handle=fopen($file,'a+') or die("Could not open file: $file"));// FAILS
...................
...................
?>
>
This is the way it appears on the screen....
Sunday, September 24th, 2006 (4:10 PM CDT) Dafydd Cealleigh
daveecealleig@ireland.nat lets go fishing Sunday, September 24th, 2006
(4:30 PM CDT) Dave Kelly daveecealleig@ireland.nat Sunday, September
24th, 2006 (4:53 PM CDT) Jim Kloss daveecealleig@ireland.nat Sunday,
September 24th, 2006 (5:01 PM CDT) Wilson Harmon will@harmon.cum 936 894
1710 Sunday, September 24th, 2006 (5:11 PM CDT) Alfred E Newman
49wist@vista.fiv 1234483298374
>
Notice: Undefined variable: var1 in
/var/www/vhosts/texasflyfishers.org/httpdocs/guestbook.php on line 22
>
-----+++++list-PINSS.txt_____list-PINSS.txt_____
>
Why does $file contain 'list-PINSS.txt' in printf ("_____%s_____",
$file) and 'var1' in ($handle=fopen($file,'a+')?
It doesn't. That's an error message due to the uninitialized variable.

Looks like your logic is just a little messed up here.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Closed Thread