Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving a string to a database

Tags:

php

mysql

I am trying to save a string which is just $id = "27491"; into a database table called users under a field called user id here's what I have tried currently but it's not working...

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

enter image description here

EDIT: The content just does not go into the database, the issue before was just a typo.

Also does not work with my $title string.

mysqli_query($DB,"INSERT INTO `users` SET `title` = '".mysqli_real_escape_string($DB,$title)."'");
like image 691
Placeholder Avatar asked Dec 08 '22 00:12

Placeholder


2 Answers

You can use like below, One more suggetion for you, this is not good practice to use space in field name. So, you can use field name like user_id, this 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."')";
like image 151
Kausha Mehta Avatar answered Dec 11 '22 10:12

Kausha Mehta


Parenthesis aren't closing in your code...

mysqli_query($DB,"INSERT INTO `users` SET `user id` = '".$id."'");
like image 33
Waqas Shahid Avatar answered Dec 11 '22 10:12

Waqas Shahid