Results 1 to 4 of 4

Thread: Calling functions

  1. #1
    Join Date
    Jun 2007
    Posts
    72
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Calling functions

    Hi, I have come across part of a shopping cart that I want to use, all I have is the functions the one below is just an example.
    PHP Code:
     function delete_item($table$session$product) {
                
    $query "DELETE FROM $table WHERE session='$session' AND product='$product' ";
                
    mysql_query($query);
            } 
    But now I am stuck, I dont actually know how to use the functions! This is all the documentation that came with the code:
    PHP Code:
    <?
        
    include("shoppingcart.php");
        
    $cart = new Cart;
        
    $mysql_link mysql_connect("localhost""wwwrun""");
        
    $mysql_select_db("kmartShopper"$mysql_link/* heh, use whatever database name you put the 2 tables under in place of kmartShopper */
    ?>
    Please could someone post a example code that would use the delete_item function?

    Thanks in advance for any help

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    http://php-mysql-tutorial.com
    read that... it'll help

    You need to first connect to the database then choose the actual database name you are using.

    After that, you can query the database for data.

    The function is easy, just use, as the names of the variables say, the table name, the session name and the name of the product, and it should delete it.

    delete_item('table', 'session', 'product');
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jun 2007
    Posts
    72
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default

    I know what I need to use, but I will make a page that will display the contents of the cart and there will be a delete button that when a customer clicks the button it will delete the relevant item, but I dont know the code that I need to send the right data to the correct function bearing in mind that there are other functions as well.
    Can I do it through by using something like: href=index.php?table=table1&session=1&product=product1

    But then if I use the above example how would I tell the page to use thats data with the delete function and not some other function using the same data?

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Well, you can retrieve any of that data with $_GET['name']. So, $_GET['table'] would be table1.
    Then just call delete_item($_GET['table',...);

    One method would be using if isset($_GET[....., and that would check if you have a value to use.

    Aside from that, I recommend any basic PHP tutorial which will show you typical if/else structures that should get your page functional.

    You can't just "tell a page", so think about a way to send data, etc, that will be checked by the page.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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