SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: UPDATE problem.

  1. #1
    SitePoint Member
    Join Date
    Apr 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i dont know why, but this little script doesnt update at all. i mean the only that i need is that this script update the values from a previous form. im using POST in the form.
    but i doesnt update.


    <?php

    $db = mysql_connect("localhost", "root");

    mysql_select_db("altovalle",$db);

    ?>
    <?php


    $sql = "UPDATE fruta SET KgBulto='$kgbulto',PrecioBulto='$preciobulto',PrecioKg='$preciokg' WHERE (id LIKE '$id')";

    // print the id for editing

    ?>

    thanx in adv.
    my pet its bat...so what?

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    of course it doesn't update - you dont ever run the query.

    you need to do this:

    mysql_query($sql, $db);
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    SitePoint Member
    Join Date
    Apr 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    good point...but where i must put the query....after or before the $sql = UPDATE .... ?

    i maybe sound dumb...im very new at php

    thanx for you help.
    my pet its bat...so what?

  4. #4
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    after

    See your $sql is just a string variable.

    You could call it $pancakes if you like - it wouldn't matter

    You don't even need it really.

    You can do this:

    mysql_query("Insert into blah blah", $db);

    and it's the same thing as

    $sql = "Insert into blah blah";
    mysql_query($sql, $db);
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  5. #5
    SitePoint Member
    Join Date
    Apr 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx but im getting not updates at all

    <?php

    $db = mysql_connect("localhost", "root");

    mysql_select_db("altovalle",$db);

    ?>

    <?php

    mysql_query("UPDATE fruta SET KgBulto=´$kgbulto´,PrecioBulto=´$preciobulto´,PrecioKg=´$preciokg´,Producto=´$producto´ WHERE id=´$id´", $db);

    ?>

    im trying to figure it out what the hell im missing....
    my pet its bat...so what?

  6. #6
    SitePoint Zealot DarkMonkey's Avatar
    Join Date
    Apr 2001
    Location
    uk
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's a tricky one (for me ) but try giving your query a variable handle, so you can like test it's been executed and the like.

    $updatequery = mysql_query("UPDATE fruta SET KgBulto= $kgbulto ,PrecioBulto= $preciobulto ,PrecioKg= $preciokg ,Producto= $producto WHERE id= $id ", $db);

    if($updatequery){
    echo "It worked";
    } else { echo "it didn't"; }

    Hey you never know, *ahem* check all your variables, sometimes if you try to pass an empty variable (because you've misnamed it) to your table and you have selected like 'no null' or something like that then it wont update, unless it has a value.

  7. #7
    SitePoint Member
    Join Date
    Apr 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think that the problem comes with the parsing id, because i try to echo all the vars, and the only one that doesnt appear is id....

    the strange thing is that my form parse the id too with the other vars.....

    strange....i will try to figure it out...thanx both for your help
    my pet its bat...so what?

  8. #8
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe not a solution to your problem but some ideas.
    1. If your query is not working, try to print it on screen
    SQL="UPDATE ......";
    print SQL;

    2. I recommend you to use AddSlashes function for every text variables you have before inserting/updating. Otherwise special characters can cause your query not work(if magic quotas are not on)

    $kgbulto = AddSlashes($kgbulto);
    $sql = "UPDATE fruta SET KgBulto='$kgbulto' WHERE (id LIKE '$id')";

    of course in this case when you read from database you have to StripSlashes function. You can read details about these functions in www.php.net

    MHO

  9. #9
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How is the variable $id being passed to the script from a form?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •