Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-05-2011, 10:17 PM   PM User | #1
johnwboyd
New Coder

 
Join Date: Feb 2008
Posts: 54
Thanks: 19
Thanked 0 Times in 0 Posts
johnwboyd is an unknown quantity at this point
Linking to Data for Pages (pricing) in Layman's Terms

I have prices coded in 2 places on our site for the product pages. For example:

<td class="tablecelg" >$139</td>

and

<input type="image" class="i" onclick="addtocart('xyz description','paymentmethod','139','xyz')" value="Add To Cart" src="images/addtocart.png" />

PLUS There are 2 other pages where the product is listed same as this:
<td class="tablecelg" >$139</td>

What I'd like to do is have either a spreadsheet or a webpage where the prices could be updated on all 3 pages and the totals for the price 139 in the example above would be automatically updated. Basically a CMS.
johnwboyd is offline   Reply With Quote
Old 08-05-2011, 10:28 PM   PM User | #2
Truffle
New Coder

 
Join Date: Feb 2006
Location: Texas
Posts: 80
Thanks: 1
Thanked 8 Times in 8 Posts
Truffle is an unknown quantity at this point
hmm well this appears to be really basic php stuff. One way of accomplishing this is to create one php file that stores the price of the products in a variable then refer to that variable name on each page

Say you have prices.php to store your prices with this code

PHP Code:
<?php
$xyz_price 
139;
?>
Then on each web page you add this code near the top

PHP Code:
<?php
include_once("prices.php");
?>
And wherever you have 139 on the page replace with this code
PHP Code:
<?php echo $xyz_price?>
Not a CMS but you only have to edit one file in a text editor instead of all your files. Your just using an include on each page so that the $xyz_price variable can be found in each page.

Hope this is what you mean, because a cms is alot more complex.

If i misunderstood then I apologize and I blame it on noise distractions

Last edited by Truffle; 08-05-2011 at 10:31 PM..
Truffle is offline   Reply With Quote
Users who have thanked Truffle for this post:
johnwboyd (08-05-2011)
Old 08-05-2011, 10:39 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,513
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by johnwboyd View Post
<input type="image" class="i" onclick="addtocart('xyz description','paymentmethod','139','xyz')" value="Add To Cart" src="images/addtocart.png" />
Just a quick tip, never rely on the prices set in the users browser for your order. EG When totalling up the order total on the users screen in J.script, do not use this value and then send it to the server - doing that can create massive problems (eg a user could order a $600 product for $1).

Sure, for displaying totals to the user locally its fine but ALWAYS calculate the actual numbers on the server from data held on the server.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
johnwboyd (08-05-2011)
Old 08-05-2011, 11:13 PM   PM User | #4
johnwboyd
New Coder

 
Join Date: Feb 2008
Posts: 54
Thanks: 19
Thanked 0 Times in 0 Posts
johnwboyd is an unknown quantity at this point
Yeah it just posts the data to the cart not server. Thanks.
johnwboyd is offline   Reply With Quote
Old 08-06-2011, 12:00 AM   PM User | #5
johnwboyd
New Coder

 
Join Date: Feb 2008
Posts: 54
Thanks: 19
Thanked 0 Times in 0 Posts
johnwboyd is an unknown quantity at this point
Sweet!

Truffle it worked even with the javascript. So how complicated would it be to make a CMS where there could be a form for the customer which would post into a database or something to update the prices.php page?

Step by step...
johnwboyd is offline   Reply With Quote
Old 08-06-2011, 01:13 AM   PM User | #6
Truffle
New Coder

 
Join Date: Feb 2006
Location: Texas
Posts: 80
Thanks: 1
Thanked 8 Times in 8 Posts
Truffle is an unknown quantity at this point
To make a CMS system you have to build one from the ground up so unfortunately step by step instructions would be like writing a book.

Are you already using a shopping cart system taking orders?

Also as tangoforce said, don't rely on the price that is in the javascript since that could potentially be manipulated by the user.

trustno1
Truffle is offline   Reply With Quote
Users who have thanked Truffle for this post:
johnwboyd (08-06-2011)
Old 08-06-2011, 01:37 AM   PM User | #7
johnwboyd
New Coder

 
Join Date: Feb 2008
Posts: 54
Thanks: 19
Thanked 0 Times in 0 Posts
johnwboyd is an unknown quantity at this point
Ok no probs. Yeah well there is no charge till the order is confirmed and we haven't had any issues so far with price manipulation. Our customers aren't developers I guess : ).

I found a poor man's way to have our clients update pricing and it would just involve me to copy and paste their updates into that pricing.php page and upload... 30 seconds of work. Still beats the heck out of manually updating 26 product pages : ).

$product1p = 139;
$product2p = 239;
$product3p = 309;
$product4p = 399;
$product5p = 559;

..etc.

Thanks again guys.
johnwboyd is offline   Reply With Quote
Old 08-06-2011, 02:01 AM   PM User | #8
fireye
New to the CF scene

 
Join Date: Aug 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
fireye has a little shameless behaviour in the past
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.

HOW CAN?
fireye is offline   Reply With Quote
Old 08-06-2011, 01:55 PM   PM User | #9
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,513
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by fireye View Post
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value.

HOW CAN?
Are you trying to derail this thread?

IE has a bug. If your cursor is in a text box and you hit return, the submit button is not sent. If you click it with the mouse, it is. This is why you should ALWAYS test for another form field instead.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 08-06-2011, 02:35 PM   PM User | #10
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,513
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by johnwboyd View Post
Ok no probs. Yeah well there is no charge till the order is confirmed and we haven't had any issues so far with price manipulation. Our customers aren't developers I guess : ).
Don't be reliant on that. Someone will stumble on any weakness you have and it will be abused. Thats a fact. It's just the way the web works. If people can get something cheap they will do anything.

Quote:
Originally Posted by johnwboyd View Post
I found a poor man's way to have our clients update pricing and it would just involve me to copy and paste their updates into that pricing.php page and upload... 30 seconds of work. Still beats the heck out of manually updating 26 product pages : ).
Not quite clear on what you're saying here..
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 08-08-2011, 10:35 AM   PM User | #11
johnwboyd
New Coder

 
Join Date: Feb 2008
Posts: 54
Thanks: 19
Thanked 0 Times in 0 Posts
johnwboyd is an unknown quantity at this point
No worries. I appreciate your concern but we're not charging them till we confirm the order so if they're trying to scam up front we'll know already not to do business with them : ).

I have a question guys would it be possible to put a comma here:

$Product = 1,500;

If I put it like the above it throws an error.

Thanks.
johnwboyd is offline   Reply With Quote
Old 08-08-2011, 01:04 PM   PM User | #12
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,513
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Check out the number_format function on the php.net manual:

http://www.php.net/number_format
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 08-08-2011, 05:04 PM   PM User | #13
johnwboyd
New Coder

 
Join Date: Feb 2008
Posts: 54
Thanks: 19
Thanked 0 Times in 0 Posts
johnwboyd is an unknown quantity at this point
Quote:
Originally Posted by tangoforce View Post
Check out the number_format function on the php.net manual:

http://www.php.net/number_format
I put this above the prices on the prices.php page and it didn't do anything

Seems I missed a step they failed to mention?

<?php
function numberFormat($num)
{
return preg_replace("/(?<=\d)(?=(\d{3})+(?!\d))/",",",$num);
}
?>
johnwboyd is offline   Reply With Quote
Old 08-08-2011, 05:16 PM   PM User | #14
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,513
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Description

string number_format ( float $number [, int $decimals = 0 ] )
string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )

This function accepts either one, two, or four parameters (not three):

If only one parameter is given, number will be formatted without decimals, but with a comma (",") between every group of thousands.

If two parameters are given, number will be formatted with decimals decimals with a dot (".") in front, and a comma (",") between every group of thousands.

If all four parameters are given, number will be formatted with decimals decimals, dec_point instead of a dot (".") before the decimals and thousands_sep instead of a comma (",") between every group of thousands.
PHP Code:
$Product 1500;
print 
number_format($Product); 
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 08-08-2011, 05:19 PM   PM User | #15
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,513
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Oops, Sorry I've completely misunderstood you (That'll teach me for replying straight after getting up eh?)..

To put a comma here:
$Product = 1,500;

Just change it to a string:
$Product = '1,500';

Note that you won't be able to do any calculations on it though as far as I'm aware (I may well be wrong on this though). However using str_replace to strip out the comma prior to calcs will allow you to use it.

<== Feels ruddy stupid!
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
johnwboyd (08-08-2011)
Reply

Bookmarks

Tags
cms, linking data

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:37 PM.


Advertisement
Log in to turn off these ads.