Thread: Strange...

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Colombo, Western, Sri Lanka
    Posts
    41
    Rep Power
    15
    I cant seem to figure out why this piece of code doesn't work. Can someone please help me?


    It displays the data from the previous script within the loop correctly but doesn't update the db with this info. (This script receives data which is parsed by a previous script and is supposed to update the table products.)

    code is type varchar.
    stock_at_usa is type integer

    (Connection to db)

    $i=0;

    while ($i<$productsrows) {


    eval("$prod_code="$prod_code$i";");

    $stringprodcode="$prod_coden";

    echo $stringprodcode;

    echo "&nbsp;&nbsp;&nbsp;";

    eval("$stock="$stock$i";");

    $stringstock="$stockn";

    echo $stringstock;

    echo "<p>";

    mysql_query("update products set stock_at_usa='$stringstock' where code='$stringprodcode'");

    $i++;}

    ?>

    <p>Update completed successfully.

    </body>

    </html>
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Add the line:

    print mysql_error();

    right after the query so you can see what error mysql is returning and figure out what you are doing wrong.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Colombo, Western, Sri Lanka
    Posts
    41
    Rep Power
    15
    Nope. Didn't get any errors either. Feel like pulling my hair out.

    Any other ideas???

    I tried it with direct values (in the update statement) and it works fine.

    But it doesn't work with the $stringstock and $stringprodcode.

    I simply cant figure out why it doesn't work.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    0
    Rep Power
    0
    Try this:

    $MyAns = mysql_db_query($myDB,"update products set stock_at_usa='$stringstock' where code='$stringprodcode'");
    // MySQL_DB_Query returns 1 on success //

    If ($MyAns == 1) {echo "YESSS!!"} else
    {echo "NOOO!!"}
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Colombo, Western, Sri Lanka
    Posts
    41
    Rep Power
    15
    It says "yes" but it doesn't actually update the database.

    I'm puzzled.

    Could it have anything to do with the column type??

    If look at my code you will notice that the column stock_at_usa is of type INTEGER.

    The result $stringstock , is it a string value or an integer value??? note that $stringstock always = a number . My question is this: is this number a string value or an integer value??

    Somebody please me help me...thanks.

    [This message has been edited by ranesh_w (edited October 05, 2000).]
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Colombo, Western, Sri Lanka
    Posts
    41
    Rep Power
    15
    The problem is that $stringstock is a string (although it contains numerics only).

    Therefore $stringstock needs to be converted to type INTEGER before the pdate takes place.

    The question is, how do I do this conversion??
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Colombo, Western, Sri Lanka
    Posts
    41
    Rep Power
    15
    Whoopieee!!! Solved my problem.

    It had nothing to do with conversion.

    originally it was:

    $stringprodcode="$prod_code/n";

    I changed this to :

    $stringprodcode="$prod_code";

    Did the same for $stringstock.

    And it worked!!!!!

Similar Threads

  1. strange echo behaviour
    By hade in forum PHP Development
    Replies: 3
    Last Post: June 6th, 2003, 08:17 AM
  2. I have code solution - but it seems strange!
    By dreamstring in forum PHP Development
    Replies: 1
    Last Post: August 28th, 2002, 03:32 PM
  3. strange session problem
    By jdk in forum PHP Development
    Replies: 18
    Last Post: May 8th, 2002, 10:40 AM
  4. Help!! Strange problem with VARCHAR
    By forzagrifo in forum MySQL Help
    Replies: 5
    Last Post: April 18th, 2002, 11:51 AM
  5. strange parse error
    By johncogan in forum PHP Development
    Replies: 4
    Last Post: August 21st, 2001, 04:57 AM

IMN logo majestic logo threadwatch logo seochat tools logo