Create a Function from a button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

NYColt
Forum Newbie
Posts: 17
Joined: Wed Apr 07, 2004 4:49 pm

Post by NYColt »

Hmmm not quite, but it DID call the values just not with in the button it placed the vales nex to the button see here

http://buysellandsearch.com/listingview ... istingID=4

I think that is getting closer!
NYColt
Forum Newbie
Posts: 17
Joined: Wed Apr 07, 2004 4:49 pm

Post by NYColt »

I need the email address, ItemID which is puppies and the price which is 1500.00 they are all called but just not within the button.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Okay, seeing what your stuff it outputing, those functions are definitely echoing. Here's what to do, replace this:

Code: Select all

<?php
function renderpaypal() {
echo "<form action="https://www.paypal.com/cgi-bin/webscr" method="post">\n";
echo "<input type="hidden" name="cmd" value="_xclick" />\n";
echo "<input type="hidden" name="business" value="" . renderSingleListingItemRaw($listingID, "email") . "" />\n";
echo "<input type="hidden" name="item_name" value="" . renderSingleListingItemRaw($listingID, "item_name") . "" />\n";

echo "<input type="hidden" name="amount" value="" . renderSingleListingItemRaw($listingID, "amount") . "" />\n";
echo "<input type="hidden" name="return" value="http://www.mysite.com" />\n";
echo "<input type="hidden" name="notify_url" value="http://www.mysite.com" />\n";
echo "<input type="image" src="https://www.paypal.com/images/x-click-but23.gif" name="submit" />\n";
echo "</form>\n";
}
renderpaypal();  // Now we are calling it ..
?>
with:

Code: Select all

<?php
function renderpaypal() {
$listingID = $GLOBALS['listingID'];
echo '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">\n';
echo '<input type="hidden" name="cmd" value="_xclick" />\n';
echo '<input type="hidden" name="business" value="';
renderSingleListingItemRaw($listingID, "email");
echo '" />\n';
echo '<input type="hidden" name="item_name" value="';
renderSingleListingItemRaw($listingID, "item_name");
echo '" />\n';

echo '<input type="hidden" name="amount" value="';
renderSingleListingItemRaw($listingID, "amount");
echo '" />\n';
echo '<input type="hidden" name="return" value="http://www.mysite.com" />\n';
echo '<input type="hidden" name="notify_url" value="http://www.mysite.com" />\n';
echo '<input type="image" src="https://www.paypal.com/images/x-click-but23.gif" name="submit" />\n';
echo '</form>\n';
}
renderpaypal();  // Now we are calling it ..
?>
or:

Code: Select all

<?php
function renderpaypal() {
$listingID = $GLOBALS['listingID'];
?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">\n;
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="<? renderSingleListingItemRaw($listingID, "email"); ?>" />
<input type="hidden" name="item_name" value="<? renderSingleListingItemRaw($listingID, "item_name"); ?>" />
<input type="hidden" name="amount" value="<? renderSingleListingItemRaw($listingID, "amount"); ?>" />
<input type="hidden" name="return" value="http://www.mysite.com" />
<input type="hidden" name="notify_url" value="http://www.mysite.com" />
<input type="image" src="https://www.paypal.com/images/x-click-but23.gif" name="submit" />
</form>
<?
}
renderpaypal();  // Now we are calling it ..
?>
there are a few more ways to do it, but that gets it done.
NYColt
Forum Newbie
Posts: 17
Joined: Wed Apr 07, 2004 4:49 pm

Post by NYColt »

BEAUTIFUL! :D Put there are a bunch of \n \n all around it ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

just remove the \n's from the php then.. I guess.
NYColt
Forum Newbie
Posts: 17
Joined: Wed Apr 07, 2004 4:49 pm

Post by NYColt »

Whoa! Thats perfect! Just what I needed. Thank you sooo much for the help man I've been messin with this ALL Day! I really appreciate it!

Thanks.
NYColt

Next thing I need to do is create an "if" statement for the item_name field. if the item_name is empty I don't want the button to show. if the item_name field is Full then I want the button to appear. That is what I need to do right? I mean an if statement is what I need right? is there something better or something easier that you know of?

Hey THANKS AGAIN! Goin to BED :D
Have a Good one!
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Yes

Edit: To late way to late lol..........
NYColt
Forum Newbie
Posts: 17
Joined: Wed Apr 07, 2004 4:49 pm

Post by NYColt »

I was wondering if you could take a look at this and give me an idea as to how far off I am.

<?php
if (renderSingleListingItemRaw ($listingID, "paypalseller" = "yes")
{
renderpaypal();
}
?>

In case I am sooo far off that you can't tell what I want to do here, I am trying to call the function renderpaypal(); with an if statement
if paypalseller = yes

Any help would be GREAT!

Thanks
NYColt
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

okay. well, the way you wrote that code, you'll get an error of unexpected {.
Where is the paypalseller variable stored?
NYColt
Forum Newbie
Posts: 17
Joined: Wed Apr 07, 2004 4:49 pm

Post by NYColt »

Database
NYColt
Forum Newbie
Posts: 17
Joined: Wed Apr 07, 2004 4:49 pm

Post by NYColt »

I will have to do a Query right?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you'll have to do a query somewhere along the line to get that variable, so yeah.
NYColt
Forum Newbie
Posts: 17
Joined: Wed Apr 07, 2004 4:49 pm

Post by NYColt »

Would I do that within the function itself? Would I add something like this to the function or can I do it seperate from the function?

$listingID = make_db_extra_safe($listingID);
$sql = "SELECT ID, field_name FROM " . "default_listingsDBElements WHERE (paypaluser);
if ($listingID, "paypalseller" = "yes")
{
renderpaypal();
}


feyd wrote:you'll have to do a query somewhere along the line to get that variable, so yeah.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if you want it done for each instance of renderpaypal() do it in the function. If it's just for this instance, then do it outside.
NYColt
Forum Newbie
Posts: 17
Joined: Wed Apr 07, 2004 4:49 pm

Post by NYColt »

I would want it done for each instance.

Is my code way off in my last post?
feyd wrote:if you want it done for each instance of renderpaypal() do it in the function. If it's just for this instance, then do it outside.
Post Reply