jeudi 18 septembre 2014

Using PHP printf to produce sql queries


Vote count:

0




I tried to produce an SQL query with printf:



$query = printf("INSERT INTO author VALUES (null,'%s','%s','%s',null,null,null,null,null)",
$command['pseudonym'],$command['name'],$command['surname']);


But the result is this weird error:



INSERT INTO author VALUES (null,'pseudo','nome','cognome',null,null,null,null,null)
Database access failed: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near '83' at line 1


The produced query perfectly wors in PhpMyadmin. I tried also a version of the code without printf and it works:



$pseudo = $command['pseudonym'];
$name = $command['name'];
$surname = $command['surname'];
$query = "INSERT INTO author VALUES (null,'$pseudo','$name','$surname',null,null,null,null,null)";


What's wrong with the version using printf?



asked 1 min ago

Uccio

148






Using PHP printf to produce sql queries

Aucun commentaire:

Enregistrer un commentaire