Monday, 3 September 2018

Inserting the variable into the mysql table does not work

I'm trying to insert a variable into mysql table, but it does not do what i want (no error, it simply does not work)

$string = 'this is an example';
mysql_query("insert into tablename (columnname) values ????");

Anyone can help me how to insert $string into table tablename? I tried replacing ???? with ($string)(".$string.")$string, but all of them does not insert the $string variable into the database.
Thanks in advance!

You can use \" (an escaped quotation mark) to include quotes inside your query, like so:
$string = 'this is an example';
mysql_query("insert into tablename (columnname) values (\"$string\")");

0 comments:

Post a Comment