[ back to toc ]

php code in cgi

Date: 2002/04/17 09:20

Q:
Hi Peter,

I am fairly comfortable programming in php, but I have very limited
experience in cgi. What I would like to know is if there is a way to
write the follow php code to display in cgi.

<html>
<body>

<select name="toursite">
<?
$var = '5';

for ($i=1; $i <= $var; $i++) {
?>
<option><?php echo $i; ?>
<?php
}
?>

</select>
</body>
</html>

You can see the actual output by going to:

www.profitmatic.com/pulldown.php

What I want to do is pull $var (which is a number from 1 - 30 that has
been previously set by the user) from a database and then create the
pulldown menu on the fly, displaying the same number of options as the
user has set. In the example above the user has set $var = 5, so therefor
5 options are displaying in the pulldown menu.

The way I'm displaying html within cgi right now is:

print "Content-type: text/html\n";
print "\n";

print qq~

<html>
<body>

</body>
</html>

~;
return;

Any help you can provide would be greatly appreciated.

Thanks in advance :-)

*NAME-DELETED*
A:
*NAME-DELETED*,

there are errors in the HTML generated by the php code. The select/option
is not within a FORM, and therefore it only appears in the browser, but
the user can not send it. To allow the client to send a page the HTML page
generated by the php code should contain a

<FORM METHOD="method" ACTION="url">

where the 'method' is either POST or GET (if missing the default is GET)
and the 'url' is the URL where the data will be sent by the browser when
the user presses the submit button.

The option tag does not have any value and this is another error. The
numbers are displayed for the user, but the value assigned to the variable
'tourist' is the value specified in the value tag. For example

<SELECT NAME="tourist">
<option value="a">1
<option value="b">2
<option value="c">3
</SELECT>

will return in the CGI variable 'tourist' "b" if the user selects 2.

The CGI variable 'tourist' will be placed in the PHP variable $tourist.

I see no reason why you would want to program in Perl and PHP mixed.

I hope this helps.

regards,
Peter

[ back to toc ]