Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New Coder
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    80
    Thanks
    1
    Thanked 8 Times in 8 Posts
    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.

  • Users who have thanked Truffle for this post:

    johnwboyd (08-05-2011)

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    johnwboyd (08-05-2011)

  • #4
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Yeah it just posts the data to the cart not server. Thanks.

  • #5
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    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...

  • #6
    New Coder
    Join Date
    Feb 2006
    Location
    Texas
    Posts
    80
    Thanks
    1
    Thanked 8 Times in 8 Posts
    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

  • Users who have thanked Truffle for this post:

    johnwboyd (08-06-2011)

  • #7
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    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.

  • #8
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    //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?

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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..
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #11
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    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.

  • #12
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Check out the number_format function on the php.net manual:

    http://www.php.net/number_format
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #13
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    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);
    }
    ?>

  • #14
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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); 
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #15
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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!
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    johnwboyd (08-08-2011)


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •