Inserting into database using a PDO

后端 未结 4 1078
借酒劲吻你
借酒劲吻你 2021-01-23 02:08

I\'m trying to insert data into a database that I have on my server.

To connect to my database I have the following code:



        
4条回答
  •  孤独总比滥情好
    2021-01-23 02:45

    Why are you back-ticking the values? Try just single quotes:

    $sql = "INSERT INTO USERS (userName, password) VALUES ('test', 'testy')";
    

    Also, check your PHP error log, it may give you some insight.

    And according to the docs, I believe you have to use exec() vs query(), for doing non-select queries such as inserting, updating, and deleting. If you plan on passing in variables to the $sql variable, you should also read up on prepare.

提交回复
热议问题