?
Solved

Merge solution code with exisitng code

Posted on 2007-12-05
10
Medium Priority
?
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 100 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
yjwong earned 400 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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

762 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