Mysql Multiple Update in a PHP Web Page

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

    Mysql Multiple Update in a PHP Web Page

    I need to create a form using multiple quantities that can be updated by one
    single update.


    eg:
    (HTML PAGE)
    <form method="post" enctype = "multipart/formdata">
    <? do { ?>
    <?php echo $row_rsBasket['id']; ?>
    <input name="qty" type="text" value="<?php echo $row_rsBasket['qty']; ?>"
    size="3">
    <? } while ($row_rsBasket = mysql_fetch_ass oc($rsBasket)); ?>
    <input type="hidden" name="send" value="true">
    <input type ="submit" name = "update" value ="update">

    How do I create the multiple update when the page is submitted back to
    itself?

    (TOP OF THE HTML PAGE)
    <?
    if(isset($_POST['update']) && ($_POST['update'] == "true")){
    //loop thorugh each of the submitted qty values this is where I am stuck!!
    for each(){
    mysql_query = "UPDATE tblCart SET qty = $_POST['qty'] WHERE id = 'ID' // not
    sure how to pull out 'ID'
    }
    }
    ?>

    Any help will be grateful
    Craig



  • Marcin Dobrucki

    #2
    Re: Mysql Multiple Update in a PHP Web Page

    Craig Keightley wrote:
    ....[color=blue]
    > How do I create the multiple update when the page is submitted back to
    > itself?
    >
    > (TOP OF THE HTML PAGE)
    > <?
    > if(isset($_POST['update']) && ($_POST['update'] == "true")){
    > //loop thorugh each of the submitted qty values this is where I am stuck!!
    > for each(){
    > mysql_query = "UPDATE tblCart SET qty = $_POST['qty'] WHERE id = 'ID' // not
    > sure how to pull out 'ID'
    > }
    > }
    > ?>[/color]

    Hi Craig,

    uhm, a bit messy.

    Still didn't quite get what you are trying to do actually. You mean
    update several values into a mysql row with one statement? Something
    like this:

    <form method="post" target="_self">
    <input type="text" value="<?php echo $somevalue; ?>" name="a">
    <input type="text" value="<?php echo $othervalue; ?>" name="b">
    <input type="hidden" name="id" value="<?php echo $id; ?>">
    <input type="submit">
    </form>

    ....

    if ($_POST["id"]) {
    mysql_query("UP DATE INTO sometable VALUES ($_POST['id'],$_POST['a'],
    $_POST['b']");
    }

    if "id" is the primary key, then if it exists in the mysql table, the
    row will be updated. If not, then a new row will be created.

    Anyway, this looks like a very messy, and very hard-to-maintain way
    to code. Why not:
    1) use some ready shopping cart code
    2) use some ready libraries to handle form processing, db access, etc.

    /Marcin

    Comment

    • Craig Keightley

      #3
      Re: Mysql Multiple Update in a PHP Web Page

      sorry for not being thorough with th eproblem.
      I'll try again

      i want to be able to create a foreach loop thta creates multiple indivdual
      update queries
      so for each qty that is in the form, update the row in the table accordingly

      i hope this makes a bit more sense

      craig

      "Marcin Dobrucki" <Marcin.Dobruck i@TAKETHISAWAY. nokia.com> wrote in message
      news:ucHee.1236 $f4.19340@news1 .nokia.com...[color=blue]
      > Craig Keightley wrote:
      > ...[color=green]
      >> How do I create the multiple update when the page is submitted back to
      >> itself?
      >>
      >> (TOP OF THE HTML PAGE)
      >> <?
      >> if(isset($_POST['update']) && ($_POST['update'] == "true")){
      >> //loop thorugh each of the submitted qty values this is where I am
      >> stuck!!
      >> for each(){
      >> mysql_query = "UPDATE tblCart SET qty = $_POST['qty'] WHERE id = 'ID' //
      >> not
      >> sure how to pull out 'ID'
      >> }
      >> }
      >> ?>[/color]
      >
      > Hi Craig,
      >
      > uhm, a bit messy.
      >
      > Still didn't quite get what you are trying to do actually. You mean
      > update several values into a mysql row with one statement? Something like
      > this:
      >
      > <form method="post" target="_self">
      > <input type="text" value="<?php echo $somevalue; ?>" name="a">
      > <input type="text" value="<?php echo $othervalue; ?>" name="b">
      > <input type="hidden" name="id" value="<?php echo $id; ?>">
      > <input type="submit">
      > </form>
      >
      > ...
      >
      > if ($_POST["id"]) {
      > mysql_query("UP DATE INTO sometable VALUES ($_POST['id'],$_POST['a'],
      > $_POST['b']");
      > }
      >
      > if "id" is the primary key, then if it exists in the mysql table, the row
      > will be updated. If not, then a new row will be created.
      >
      > Anyway, this looks like a very messy, and very hard-to-maintain way to
      > code. Why not:
      > 1) use some ready shopping cart code
      > 2) use some ready libraries to handle form processing, db access, etc.
      >
      > /Marcin[/color]


      Comment

      Working...