Link to home
Start Free TrialLog in
Avatar of creativepresence
creativepresence

asked on

Merge solution code with exisitng code

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.
Avatar of Mark Gilbert
Mark Gilbert
Flag of United States of America image

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

SOLUTION
Avatar of Mark Gilbert
Mark Gilbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of creativepresence
creativepresence

ASKER

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,
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
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!\" />";
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?
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";
I just deleted "status" and "sold" and that worked.

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

Thanks,
Split points as Ingwa offer solution, although i never accepted it.
Thanks guys or girls