Saving a row in a database

I am trying to save a row that is simple $id = "27491";, in a database table called usersunder the field user idhere, that I have tried at present, but it does not work ...

mysqli_query($DB,"INSERT INTO `users` SET `id` = '".$id."'");

enter image description here

EDIT . The content is simply not included in the database, the problem was only a typo.

Also does not work with my string $title.

mysqli_query($DB,"INSERT INTO `users` SET `title` = '".mysqli_real_escape_string($DB,$title)."'");
+4
source share
3 answers

You can use, as shown below, Another suggestion for you is not a good practice to use the space in the field name. This way you can use a field name like user_id, which is good to go .:

mysqli_query($DB,"INSERT INTO `users` SET `user id` = '".$id."'");
//                                                              ^ you miss

OR

mysqli_query($DB,"INSERT INTO `users` (`user id`) VALUES('".$id."')";
+7
source

...

mysqli_query($DB,"INSERT INTO `users` SET `user id` = '".$id."'");
+7

. , . -

mysqli_query($DB,"INSERT INTO `users` SET `title` = ".mysqli_real_escape_string($DB,$title));
0

Source: https://habr.com/ru/post/1621378/


All Articles