1

I am updating my database with a form. I have it outputting the values of everything to check to make sure everyting is working correctly and it is, but when it adds it to the database everything is wrong. If the quantity is 20000 it just changes the quantity in the inventory to 1. I dont understand. I am still learning MySQL but this is irritating

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
    require("serverInfo.php");
    for($i = 0; $i < 10; $i++){
        $quantity = $_POST['quantity'.$i];
        $company = $_POST['company'.$i];
        $size = $_POST['cardSize'.$i];

        if(isset($_POST['box'.$i])){
            echo $quantity . "<br / >";
            echo $size . "<br / >";
            echo $company . "<br / >";
            mysql_query("UPDATE `printRun` SET Quantity = '$quantity' AND Size = '$size'  where status='Open' AND Company = '$company'");
        }
    }
    mysql_close($link);
}
?>
2
  • What are the "Types" set as? What character limit did you give them? Commented Apr 6, 2012 at 20:35
  • In other words, is the database columnn Quantity an integer or a character string (varchar)? Commented Apr 6, 2012 at 20:37

2 Answers 2

4

I will spare you the usual lecture about echoing and updating into your database unfiltered form data .... but your update syntax is incorrect. Try this instead (no AND in the column list)

UPDATE printRun SET quantity='$quantity', size = '$size' where status='Open' AND Company = '$company'

http://dev.mysql.com/doc/refman/4.1/en/update.html

Sign up to request clarification or add additional context in comments.

1 Comment

I would most certainly research MySQL prepared statements which will help you to maintain your code more effectively and ward off the most blatant of attacks such as SQL injection.
3

Try

mysql_query("UPDATE `printRun` SET Quantity = '$quantity', Size = '$size'  where status='Open' AND Company = '$company'");

1 Comment

that did indeed fix it. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.