Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php with mysql

Options
  • 20-08-2004 7:33pm
    #1
    Closed Accounts Posts: 107 ✭✭


    Hello
    I have created a page for inserting values into the database and then updating them this all works perfectly but one problem remains.When the record has a value of 0(zero) it will not delete it from the database despite my efforts of an if statement to do just that it does not delete the record and does not notice when a value is greater than what is in the database.Please examine my code and help me solve this:

    $sql = "UPDATE portfolio SET amount = '$amount3' WHERE username = '$username1' && password = '$password1'";
    mysql_query($sql);

    if ($amount=0.000)
    {
    $delete = "delete * from portfolio where amount== 0.000 and stockname= '$stockname'";
    mysql_query($delete);
    }

    echo "<br>$sql";
    }


    mysql_close($connection);
    ?>
    </body>
    </html>

    Any suggestions will be tried and thank you in advance


Comments

  • Registered Users Posts: 2,426 ✭✭✭ressem


    First bleary eyed glance

    In the delete line
    Don't need the *, and is the == a typo?


    Other than that
    Other compsci stuff like what type is "amount", decimal, float? In general relying on = in comparisions, when dealing with non integer types leads to trouble. As value might be 0.0000125, intended to go but fail the match depending on what maths you're using on it. How about less than 0.001 AND greater than -0.001 (assuming value is signed).


  • Registered Users Posts: 1,967 ✭✭✭Dun


    Your if statement should have a == instead of = , and the following sql statement should have = instead of ==.
    [php]
    if ($amount==0.000)
    [/php]
    and:
    where amount=0.000


Advertisement