Mysql query: date_format and sprintf ()

I want to use sprintf () along with date_format in a MySQL query.

Here is the request:

mysql_select_db($database_exdb, $expdb);
$query_eventeditrs = sprintf("SELECT eventid, groupid, title, DATE_FORMAT(dateofevent, '%W, %M %d, %Y'), timeofevent, location, details, presenter, bio FROM events WHERE eventid = %s", GetSQLValueString($colname_eventeditrs, "int")); 

I get an error message:

"Warning: sprintf() [fun
ction.sprintf]: Too few arguments. Query was Empty" 

Help Plz

+5
source share
3 answers

You need to avoid date format string with extra% s, try the following:

sprintf("SELECT eventid, groupid, title, 
DATE_FORMAT(dateofevent, '%%W, %%M %%d, %%Y'), 
ti meofevent, location, details, presenter, bio 
FROM events 
WHERE eventid = %s", GetSQLValueString($colname_eventeditrs, "int"));
+8
source

In the sprintf line you have:

"SELECT eventid, groupid, title, DATE_FORMAT(dateofevent, '%W, %M %d, %Y'), 
      timeofevent, location, details, presenter, 
       bio FROM events WHERE eventid = %s"

That has inputs 5, but you only put one ( GetSQLValueString($colname_eventeditrs, "int")), add 4 more and you should be gold (or, as said in the comments below, escape 4 from the inputs, which should also work)

0
source

All Articles