MySQL $query format

In MySQL, you can create your query string like this:

$query = "INSERT INTO NameDB (field1, field2, ....) VALUES ('$value1', '$value2',....)";

Note that $values must be enclosed in quotes, otherwise you get an SQL error.

In a way, this is easier than building query strings in ASP/MSSQL where you have to concatenate strings and variables. In PHP, you can use the variable name within the string ($value1, $value2)… just make sure to put quote marks around it.

This entry was posted in Uncategorized. Bookmark the permalink.