Solved

Merge solution code with exisitng code

Posted on 2007-12-05
10
266 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
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…

785 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