Solved

Merge solution code with exisitng code

Posted on 2007-12-05
10
273 Views
Last Modified: 2010-04-21
Yesterday someone helped me with some PHP code that will make a button disappear if a status is set to "sold" (see below), but I now need to merge the functionality of that code into an exisitng button code.
***************************************************************
<?
// Check for availability of the item.
if($db_item_info["status"] == 0){
        echo "<b>Status:</b> <span style=\"color:red;\">sold</span><br />\n";
        // Don't show the button if the item is sold.
} else {
    //    echo "<b>Status:</b> For Sale - {$db_item_info["status"]}<br />\n";
 
        // We still have stocks of the item - offer to sell.
        // The processbuy.php script should process the buy request.
        echo "<form action=\"processbuy.php\" method=\"POST\">";
       
 
        // This is required for processbuy.php to know what the visitor wants to buy.
        echo "<input type=\"hidden\" name=\"db_item\" value=\"{$db_item_info["no"]}\" />";
 
        echo "<input type=\"submit\" value=\"Buy Now!\" />";
        echo "</form>";
}
?>
********************************************************************************
My Code...
                      <form method="post" action="http://www.zoaphoria.co.uk/cgi-bin/cart/ppcal.cgi">
                        <input type="image" id="submit1" onMouseOver="document.getElementById('submit1').src = 'images/Shoppingcart2.bmp' " onMouseOut = "document.getElementById('submit1').src = 'images/Shoppingcart1.bmp' "
src="images/Shoppingcart1.bmp" border="0" name="submit1" alt="View Paypal Cart">
                        <input name="##ITEM" value="9003" type="hidden">
                        <input type=hidden name=user value="1">
                        <input name="item_quantity" value="1" type="hidden">
                      </form>
*******************************************************************************
I want to use my exisitng code as it has the correct parameters to link into a shopping cart i have running, plus has roll over images. But also want to use the solution code as it makes the form button disappear if the item is sold.  I have tried merging the code, but keep getting errors.
0
Comment
Question by:creativepresence
  • 5
  • 3
  • 2
10 Comments
 
LVL 18

Expert Comment

by:Mark Gilbert
ID: 20410863
HI, This should work for you.  I haven't been able to test as I'm not currently in the office, but hope it helps.
<?php
// Check for availability of the item.
if($db_item_info["status"] == 0){
        echo "<b>Status:</b> <span style=\"color:red;\">sold</span><br />\n";
        // Don't show the button if the item is sold.
} ?>
 
<?php else {
    //    echo "<b>Status:</b> For Sale - {$db_item_info["status"]}<br />\n";
 
        // We still have stocks of the item - offer to sell.
        // The processbuy.php script should process the buy request.
        echo "<form action=\"processbuy.php\" method=\"POST\">";
        
 
        // This is required for processbuy.php to know what the visitor wants to buy.
        echo "<input type=\"hidden\" name=\"db_item\" value=\"{$db_item_info["no"]}\" />";
 
        echo "<input type=\"submit\" value=\"Buy Now!\" />";
        echo "</form>";?>
<form method="post" action="http://www.zoaphoria.co.uk/cgi-bin/cart/ppcal.cgi">
                        <input type="image" id="submit1" onMouseOver="document.getElementById('submit1').src = 'images/Shoppingcart2.bmp' " onMouseOut = "document.getElementById('submit1').src = 'images/Shoppingcart1.bmp' "
src="images/Shoppingcart1.bmp" border="0" name="submit1" alt="View Paypal Cart">
                        <input name="##ITEM" value="9003" type="hidden">
                        <input type=hidden name=user value="1">
                        <input name="item_quantity" value="1" type="hidden">
                      </form>
 
 
 
<?php 
}
?>
 
                      

Open in new window

0
 
LVL 18

Assisted Solution

by:Mark Gilbert
Mark Gilbert earned 25 total points
ID: 20410871
Eek, just noticed...replace with this:
<?php
// Check for availability of the item.
if($db_item_info["status"] == 0){
        echo "<b>Status:</b> <span style=\"color:red;\">sold</span><br />\n";
        // Don't show the button if the item is sold.
} ?>
 
<?php else {
    //    echo "<b>Status:</b> For Sale - {$db_item_info["status"]}<br />\n";
 
        // We still have stocks of the item - offer to sell.
        // The processbuy.php script should process the buy request.
        echo "<form action=\"processbuy.php\" method=\"POST\">";?>
<form method="post" action="http://www.zoaphoria.co.uk/cgi-bin/cart/ppcal.cgi">
                        <input type="image" id="submit1" onMouseOver="document.getElementById('submit1').src = 'images/Shoppingcart2.bmp' " onMouseOut = "document.getElementById('submit1').src = 'images/Shoppingcart1.bmp' "
src="images/Shoppingcart1.bmp" border="0" name="submit1" alt="View Paypal Cart">
<?php         // This is required for processbuy.php to know what the visitor wants to buy.
        echo "<input type=\"hidden\" name=\"db_item\" value=\"{$db_item_info["no"]}\" />";
 
        echo "<input type=\"submit\" value=\"Buy Now!\" />";
?>                        <input type=hidden name=user value="1">
                        <input name="item_quantity" value="1" type="hidden">
                      </form>
<?php 
}
?>

Open in new window

0
 

Author Comment

by:creativepresence
ID: 20410993
Hi, get error "Parse error: parse error, unexpected T_ELSE in /home/zoapho90/public_html/sandbox/info.php on line 73" and line 73 is "<?php else {"

Thanks,
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Accepted Solution

by:
yjwong earned 100 total points
ID: 20411119
Hi, this code should work for you. And short open tags (<?) aren't good for portability...
<?php
// Check for availability of the item.
if($db_item_info["status"] == 0){
        echo "<b>Status:</b> <span style=\"color:red;\">sold</span><br />\n";
        // Don't show the button if the item is sold.
        
} else {
	// echo "<b>Status:</b> For Sale - {$db_item_info["status"]}<br />\n";
	// We still have stocks of the item - offer to sell.
	// The processbuy.php script should process the buy request.
	echo "<form method=\"post\" action=\"http://www.zoaphoria.co.uk/cgi-bin/cart/ppcal.cgi\">";
	echo "<input type=\"image\" id=\"submit1\" ";
	echo "onMouseOver=\"document.getElementById('submit1').src = 'images/Shoppingcart2.bmp'\" ";
	echo "onMouseOut =\"document.getElementById('submit1').src = 'images/Shoppingcart1.bmp'\" ";
	echo "src=\"images/Shoppingcart1.bmp\" border=\"0\" name=\"submit1\" alt=\"View Paypal Cart\">";
	
	// This is required for processbuy.php to know what the visitor wants to buy.
	echo "<input type=\"hidden\" name=\"db_item\" value=\"{$db_item_info["no"]}\" />";
	echo "<input type=\"submit\" value=\"Buy Now!\" />";
	echo "<input type=\"hidden\" name=\"user\" value=\"1\" />";
	echo "<input name=\"item_quantity\" value=\"1\" type=\"hidden\" />";
	echo "</form>"; 
}
 
?>

Open in new window

0
 

Author Comment

by:creativepresence
ID: 20411218
Hi and thanks, was hoping you would pick this question up considering you were the one that coded it yesterday.

Currently, when the button disappears, the "Status: Sold" message appears & this line of code       // echo "<b>Status:</b> For Sale - {$db_item_info["status"]}<br />\n";
is displaying that message, but as the previous code also displays that message, there is no need for the message to be displayed instead of the button.  Therefore can the whole or part of this line go?

Also, currently 2 buttons are showing, my rollover button and a standard button, can the standard button be removed?
0
 
LVL 3

Expert Comment

by:yjwong
ID: 20411296
Hi again, you can remove that line you referenced (since you said there's no need for it, and that line has already been disabled). Just delete the whole line, it will still work :)

Yep, you can safely remove the standard button. Just remove this line:
        echo "<input type=\"submit\" value=\"Buy Now!\" />";
0
 

Author Comment

by:creativepresence
ID: 20411345
almost there,
i should have noticed that line was already disabled and therefore there must be another line displaying the "Status: Sold" and it still appears when the button disappears.

Item No: 11
Price: 10.00
Status: sold
Info: Radioactive Dragon Eye
Status: sold

I take it is being called by the 4th line...
 echo "<b>Status:</b> <span style=\"color:red;\">sold</span><br />\n";
and therefore can this be removed or would it effect the code?
0
 
LVL 18

Expert Comment

by:Mark Gilbert
ID: 20411363
Sorry for not checking my code.  You can remove anything in an echo statement.  Make sure you get all of the line, including the echo and the stuff between the speech marks, along with the semi-colon:

echo "some stuff here";
0
 

Author Comment

by:creativepresence
ID: 20411484
I just deleted "status" and "sold" and that worked.

echo "<b>Status:</b> <span style=\"color:red;\">sold</span><br />\n";

Thanks,
0
 

Author Closing Comment

by:creativepresence
ID: 31412823
Split points as Ingwa offer solution, although i never accepted it.
Thanks guys or girls
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP Query return divisible by 3 3 25
php help 34 58
Having trouble getting Imagick working with php on windows. 2 16
Reference key in foreach loop 4 15
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question