简体   繁体   中英

what's wrong with this $_POST and sql code?

The following code runs fine, but it doesn't update the mysql database.

The sql query isn't the problem because I commented out the if statement and the MySQL database updates fine. It has to do with the $_POST array. I have a feeling when I put in the $row["id"] into the $_POST array, it's not going in nicely.

if (isset($_POST["
         {$row["id"]}
         "]) && !empty($_POST["
                      {$row["id"]}
                      "])){
  print_r($_POST);
 $food_id = $_POST[$row["id"]];



 $query = "INSERT INTO `users_foods`
VALUES('','1','7','','','','')";

//$_SESSION['user_id']

   $query_run = mysql_query($query);

}

I think you have a problem with the quotes

isset($_POST["{$row["id"]}"] is wrong, you probably want:

  • isset($_POST[$row["id"]] or
  • isset($_POST[{$row["id"]}] or
  • isset($_POST["{$row[\\"id\\"]}"] (use the scape to mark the quotes are part of the string)

But I guess you are looking for the first one

{$row["id"]}

应该

{$row['id']}

if语句中的引号...尝试使用

    $_POST[row["id"]];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM