1

Here is the problem. I want use php to store how many people choose mango as their favorite fruit.Here is the code:

mysql_select_db("assignment2", $con);
    //$fruitresult = mysql_query("SELECT * FROM Persons");

    if(strcasecmp("mango",$fruit)==0){
        $fruitsql = mysql_query("SELECT Mango FROM assignment2.fruit");
        $fruitresult= mysql_fetch_assoc($fruitsql);
        $fruitresult['Mango']=(int)$fruitresult['Mango'];
        $fruitresult['Mango']=$fruitresult['Mango']+1;

        mysql_query(UPDATE assignment2.fruit SET Mango=".fruitresult['Mango']" WHERE fid=2);

        echo"There are total ";
        echo $fruitresult["Mango"];
        echo " mango <br>";
        //echo " testing work";
    }

Before I add update query, it can get the number of mango and calculate it, but when I add update query, error occur:

Parse error: syntax error, unexpected 'assignment2' (T_STRING).

How can I fix it ?

Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
  • 3
    Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 01 '15 at 14:30
  • Also adding to Jay Blanchard in your update query inverted comma is missing at the start and end. – Alive to die - Anant May 01 '15 at 14:31
  • inverted comma? That's an interested term for a quote. – Jessica May 01 '15 at 14:34

1 Answers1

1

You're missing an opening quote on this line. And a closing one for that matter. AND a $. Use an IDE!!

mysql_query(UPDATE assignment2.fruit SET Mango=".fruitresult['Mango']" WHERE fid=2);

Should be:

mysql_query("UPDATE assignment2.fruit SET Mango={$fruitresult['Mango']} WHERE fid=2");
Jessica
  • 7,075
  • 28
  • 39