I cant get the form data to go into database. What am I doing wrong?

前端 未结 4 713
一个人的身影
一个人的身影 2020-12-21 18:47

CODE UPDATED, STILL NOT WORKING. I know I´m apparently using mysql function which will be outdated. But for now all I want is for this code to work. I want to know what I´m

4条回答
  •  失恋的感觉
    2020-12-21 19:32

    Your insert query is wrong and also open to SQL injections. Here's how it should be:

    $query = "INSERT INTO `test`.`test_tabell` 
        VALUES ('', '" . mysql_real_escape_string($firstname) . "', '" . mysql_real_escape_string($surname) . "')";
    

    Notice the changing of all backticks to apostrophe.


    Also, you're trying to execute the query before defining it.


    EDIT

    As per your information related to table definition, you can skip the id field from your table. The INSERT query will become:

    $query = "INSERT INTO `test`.`test_tabell` (`FIRSTNAME`, `SURNAME`)
        VALUES ('" . mysql_real_escape_string($firstname) . "', '" . mysql_real_escape_string($surname) . "')";
    $query_run = mysql_query( $query );
    

提交回复
热议问题