how do i INSERT a value that contains a variable into a mySQL database?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jean

    how do i INSERT a value that contains a variable into a mySQL database?

    i'm trying to insert values into my database that contain a variable
    that gets incremented by one for each item in a shopping cart.
    item_name becomes item_name1, item_name2, item_name3, and so on for
    the total number of items in the cart.

    this code works great when i only have one shopping cart item to deal
    with.

    $sql = mysql_query("IN SERT into PPorder_details
    (txn_id, productID)
    VALUES
    ('$txn_id', '$item_number') ");

    for multiple cart items, here is my code:

    if($num_cart_it ems) {

    for($i = 1; $i <= $num_cart_items ; $i++) {

    // loop thru cart and add "$i" to item_name
    $sql = mysql_query("IN SERT into PPorder_details
    (txn_id, productID)
    VALUES
    ('$txn_id', '$(item_number$ i)')");
    }
    }

    i have tried numerous different iterations, none of which evaluate the
    string correctly and insert the proper value.

    please help! i am a newbie, and this is beyond me.

    thank you,
    jean
  • Geoff Berrow

    #2
    Re: how do i INSERT a value that contains a variable into a mySQL database?

    I noticed that Message-ID:
    <f54694cf.04111 92328.29288fcb@ posting.google. com> from jean contained
    the following:
    [color=blue]
    >i'm trying to insert values into my database that contain a variable
    >that gets incremented by one for each item in a shopping cart.
    >item_name becomes item_name1, item_name2, item_name3, and so on for
    >the total number of items in the cart.[/color]


    You really want this? Surely you want to store the product ID?

    Add products ordered to an array. Let us say the array is called $items
    then:

    for($i = 0; $i <count($items ); $i++) {
    // loop thru cart and get next product ID
    $sql = mysql_query("IN SERT into PPorder_details
    (txn_id, productID)
    VALUES('$txn_id ','$items[$i]')");
    }

    Should do what you want
    (needs some error checking though)
    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • jean

      #3
      Re: how do i INSERT a value that contains a variable into a mySQL database?

      Thanks, Geoff, for responding.
      as to the array and the use of 'count'.
      i am hooking up to Paypal, and i am stuck with the variable that they
      pass to me: $num_cart_items .
      also, yes, i want to store the product ID, they call it "item_numbe r".

      does this information change the advice you've given me?

      thanks again,
      jean

      Geoff Berrow <blthecat@ckdog .co.uk> wrote in message news:<8svtp0ld8 q1kqj8qbd4rrefd 7hnjnjjne4@4ax. com>...
      [color=blue]
      > You really want this? Surely you want to store the product ID?
      >
      > Add products ordered to an array. Let us say the array is called $items
      > then:
      >
      > for($i = 0; $i <count($items ); $i++) {
      > // loop thru cart and get next product ID
      > $sql = mysql_query("IN SERT into PPorder_details
      > (txn_id, productID)
      > VALUES('$txn_id ','$items[$i]')");
      > }[/color]

      Comment

      • Gary L. Burnore

        #4
        Re: how do i INSERT a value that contains a variable into a mySQL database?

        On 20 Nov 2004 19:16:23 -0800, jean@matuska.co m (jean) annoyingly top
        posted:
        [color=blue]
        >Thanks, Geoff, for responding.
        >as to the array and the use of 'count'.
        >i am hooking up to Paypal, and i am stuck with the variable that they
        >pass to me: $num_cart_items .
        >also, yes, i want to store the product ID, they call it "item_numbe r".
        >
        >does this information change the advice you've given me?[/color]

        There's an entire section on PayPal about how to do this. Have you
        read it?


        --
        gburnore@databa six dot com
        ---------------------------------------------------------------------------
        How you look depends on where you go.
        ---------------------------------------------------------------------------
        Gary L. Burnore | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
        | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
        DataBasix | ÝÛ³ºÝ³Þ³ºÝ³³ÝÛº ݳ޳ºÝ³Ý³Þ³ºÝ³Ý ÝÛ³
        | ÝÛ³ 3 4 1 4 2 ݳ޳ 6 9 0 6 9 ÝÛ³
        Black Helicopter Repair Svcs Division | Official Proof of Purchase
        =============== =============== =============== =============== ===============
        Want one? GET one! http://signup.databasix.com
        =============== =============== =============== =============== ===============

        Comment

        • jean

          #5
          Re: how do i INSERT a value that contains a variable into a mySQL database?

          yes, i have read every word in PayPal's integration guide.
          they don't specifically give the PHP code for this loop. they
          basically just say loop through to grab the values. that's what i'm
          trying to do, but my code is not yet correct.

          Gary L. Burnore <gburnore@datab asix.com> wrote in message news:<cnp1es$e8 5$3@blackhelico pter.databasix. com>...
          [color=blue]
          > There's an entire section on PayPal about how to do this. Have you
          > read it?
          >
          > gburnore@databa six dot com[/color]

          Comment

          • Geoff Berrow

            #6
            Re: how do i INSERT a value that contains a variable into a mySQL database?

            I noticed that Message-ID:
            <f54694cf.04112 01916.6715823d@ posting.google. com> from jean contained
            the following:
            [color=blue]
            >Thanks, Geoff, for responding.
            >as to the array and the use of 'count'.
            >i am hooking up to Paypal, and i am stuck with the variable that they
            >pass to me: $num_cart_items .
            >also, yes, i want to store the product ID, they call it "item_numbe r".
            >
            >does this information change the advice you've given me?[/color]

            Is item_number an array containing /your/ item numbers or item numbers
            allocated by pay pal?

            --
            Geoff Berrow (put thecat out to email)
            It's only Usenet, no one dies.
            My opinions, not the committee's, mine.
            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

            Comment

            • jean

              #7
              Re: how do i INSERT a value that contains a variable into a mySQL database?

              Geoff Berrow <blthecat@ckdog .co.uk> wrote in message news:<0ep1q01ic 91bcdp1f43ssrk1 4e3i94c50v@4ax. com>...
              [color=blue]
              > Is item_number an array containing /your/ item numbers or item numbers
              > allocated by pay pal?[/color]

              Geoff -
              thanks again for being willing to help me.
              the array contains MY item numbers that i assigned them in my products
              dbase.

              someone else told me to get the value of my variable this way, and
              it's working great.

              if($num_cart_it ems){
              for($i=1; $i<=$num_cart_i tems; $i++){

              $var_num="item_ number";
              $var_num.=$i;

              $sqlorder_detai ls = mysql_query("IN SERT into PPorder_details
              (txn_id, productID)
              VALUES
              ('$txn_id', '".$$var_num."' )");
              }
              }

              thanks again!
              jean

              Comment

              • Geoff Berrow

                #8
                Re: how do i INSERT a value that contains a variable into a mySQL database?

                I noticed that Message-ID:
                <f54694cf.04112 12253.3c03eb0b@ posting.google. com> from jean contained
                the following:
                [color=blue]
                >thanks again for being willing to help me.
                >the array contains MY item numbers that i assigned them in my products
                >dbase.
                >
                >someone else told me to get the value of my variable this way, and
                >it's working great.[/color]

                You sure?

                $var_num="item_ number";
                $var_num.=$i;

                That will give you literally
                item_number1,it em_number2 and so on

                Still, if you are happy.
                --
                Geoff Berrow (put thecat out to email)
                It's only Usenet, no one dies.
                My opinions, not the committee's, mine.
                Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                Comment

                • Geoff Berrow

                  #9
                  Re: how do i INSERT a value that contains a variable into a mySQL database?

                  I noticed that Message-ID: <4663q0hrslf5cj pjaaer5jurao0p0 gi0u2@4ax.com>
                  from Geoff Berrow contained the following:
                  [color=blue]
                  >That will give you literally
                  >item_number1,i tem_number2 and so on[/color]

                  Oops, missed the variable variable. Does this mean that the PayPal
                  information is returned as separate variables named
                  item_number1,it em_number2 and so on?

                  --
                  Geoff Berrow (put thecat out to email)
                  It's only Usenet, no one dies.
                  My opinions, not the committee's, mine.
                  Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                  Comment

                  Working...