Solved

Merge solution code with exisitng code

Posted on 2007-12-05
10
244 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:ingwa
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:ingwa
ingwa 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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:ingwa
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 look for a specific file type in a local or remote server directory using PHP.

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now