Printing HTML in perl which use if, else statments

Printing HTML in perl which use if, else statments

Page 1 of 1

2 Replies - 2230 Views - Last Post: 03 April 2007 - 11:03 PM

#1 bigredmike24   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 31-March 07

Printing HTML in perl which use if, else statments

Posted 31 March 2007 - 04:32 PM

The below .cgi script works perfectly with the HTML form post just beneath it. :trockon:

#Script beginning#
#!/usr/bin/perl -wT

use strict;

use CGI ':standard';

my $item_name;
my $amount;
my $business;
my $item_number;
my $notify_url;
my $return;
my $cancel_return;
my $shipping;
my $cbt;
my $src;

$item_name = param('item_name');
$amount = param('amount');
$business = param('business');
$item_number = param('item_number');
$notify_url = param('notify_url');
$return = param('return');
$cancel_return = param('cancel_return');
$shipping = param('shipping');
$cbt = param('cbt');
$src = param('src');

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

<td width="60%" valign="top">
&lt;form action=&quot;;&gt;<BR>
&lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_xclick&quot;&gt;<BR>
&lt;input type=&quot;hidden&quot; name=&quot;item_name&quot; value=&quot;$item_name&quot;&gt;<BR>
&lt;input type=&quot;hidden&quot; name=&quot;item_number&quot; value=&quot;$item_number&quot;&gt;<BR>
&lt;input type=&quot;hidden&quot; name=&quot;amount&quot; value=&quot;$amount&quot;&gt;<BR>
&lt;input type=&quot;hidden&quot; name=&quot;business&quot; value=&quot;$business&quot;&gt;<BR>
&lt;input type=&quot;hidden&quot; name=&quot;notify_url&quot; value=&quot;$notify_url&quot;&gt;<BR>
&lt;input type=&quot;hidden&quot; name=&quot;return&quot; value=&quot;$return&quot;&gt;<BR>
&lt;input type=&quot;hidden&quot; name=&quot;cancel_return&quot; value=&quot;$cancel_return&quot;&gt;<BR>
&lt;input type=&quot;hidden&quot; name=&quot;shipping&quot; value=&quot;$shipping&quot;&gt;<BR>
&lt;input type=&quot;hidden&quot; name=&quot;cbt&quot; value=&quot;$cbt&quot;&gt;<BR>
&lt;input type=&quot;image&quot; src=&quot;$src&quot;&gt;<BR>


Below is the HTML form post:

<form action="" method="post">
<input type="hidden" name="item_name" value="product">
<input type="hidden" name="item_number" value="123r">
<input type="hidden" name="amount" value="10.00">
<input type="hidden" name="business" value="example">
<input type="hidden" name="notify_url" value="example">
<input type="hidden" name="return" value="example">
<input type="hidden" name="cancel_return" value="example">
<input type="hidden" name="shipping" value="example">
<input type="hidden" name="cbt" value="example">
<input type="image" src="example" height="90" width="90">

End HTMl form post

Again the above examples perform perfectly. Printing my <, and " HTML symbols to the screen. It is great in order to display the end result of what the HTML code would appear as. Now I wish to make it function, so that if no value is passed for one of the variables, the .cgi script will not print the line of code. Below is what I have attempted as far as an if else statement, and the script breaks throwing an Internal Server error. I have checked permissions, and the script will function perfectly once I remove the if, else statments.

print "Content-type: text/html\n\n";
<table border="1" width="100%" cellpadding="10">
<td width="40%" valign="top">
print &lt;form action=&quot;;&gt;<BR>
print &lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_xclick&quot;&gt;<BR>
if ($item_name eq 'NULL') {
print ;
} else {
print &lt;input type=&quot;hidden&quot; name=&quot;item_name&quot; value=&gt;


Now I do realize that if else statements work perfectly with perl only syntax involved. However, I am unable to find how I can print the symbols such as <, ", -. Which is essential for me to print, because I am hoping for someone to be able to copy and paste the end result of a form post creation process. Not every person will want an end result that contains each and every variable.

Please someone save me from this! It seems as if I am missing something rater fundamental.

Is This A Good Question/Topic? 0
  • +

Replies To: Printing HTML in perl which use if, else statments

#2 girasquid   User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Printing HTML in perl which use if, else statments

Posted 02 April 2007 - 11:18 AM

I think that you need to check out your print statements...try putting quotation marks or something around both of them. So that if there's no value in $item_name you print '';, and if there IS a value you put quotation marks around what you're printing out.
Was This Post Helpful? 0
  • +
  • -

#3 KevinADC   User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: Printing HTML in perl which use if, else statments

Posted 03 April 2007 - 11:03 PM

You can't have an if/else block in the middle of a heredoc, but even if you fix that, I don't understand what your basic question is.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1