SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    adding a value in a database

    hi guys,

    i am trying to insert a value called $total into a table called members. The value is created by picking up the product price from product table(*times)quantity of the product.

    e.g. 14.00 * 2 = 28.00($total)

    what i want to do is insert the value $total into the column called total in the latest row to be inserted into the member table basically recording the order of the member.


    if anyone has any examples on doing this.


    thanks

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    al1, provide also what kind of database you are using, MySQL, Postgres, Oracle, etc.

    Probably MySQL, you can look here http://us2.php.net/manual/en/function.mysql-query.php

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i am trying to update the data of the table member which has existing information on the member like name address etc. i just want to add the total from their shopping into the total column of the last row.

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    It's called an update
    Code:
    UPDATE member
    SET total = $total
    WHERE member_id = $memberid
    Of course, if the field with the member id isn't called member_id, you'll have to change the query

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the code to show total in shopping.php is :

    PHP Code:

    $output
    [] = '<p>Grand total: <strong>&pound;'.$total.'</strong></p>'
    at checkout.php the code for inserting shipping details:
    PHP Code:
    <form action="payment.php" method="post">
    name: <input type="name" name="name" size="20"><br>
    Surname: <input type="Surname" name="Surname" size="20"><br>
    Address: <input type="Address" name="Address" size="20"><br>
    <
    input type="submit" value="Submit">
    </
    form
    payment.php - displaying the user details

    PHP Code:
    $rResult mysqli_query($rConnection'SELECT * FROM `member` ORDER BY `OrderId` DESC LIMIT 1 ');

    while (
    $aDatabaseRow mysqli_fetch_assoc($rResult))
    {    
    printf(    
    '<ul>        
    <li>memberId: %s</li>  
    <li>location: %s</li>         
             </ul>'
    ,
          
    $aDatabaseRow['memberid'], 
          
    $aDatabaseRow['location']     } 
    how do i place the value .$total.' next to the user details without post method as i don't want users to manually enter the total i want it to be placed automatically into the database.

    thanks guys.

  7. #7
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    put it in a sessions array
    my mobile portal
    ghiris.ro

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please if you could provide examples as i am new to php

  9. #9
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in shopping.php
    PHP Code:
    <?php
    session_start
    ();

    $total 50// example

    $output[] = '<p>Grand total: <strong>&pound;'.$total.'</strong></p>';

    $_SESSION['total'] = $total;
    in checkout.php
    PHP Code:
    session_start();

    $total $_SESSION['total'];

    mysql_query("INSERT INTO member SET total='$total', ... 
    my mobile portal
    ghiris.ro


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
  •