Jump to content

[SOLVED] sprintf(): Too few arguments -- Pls Help me


abdul_zu

Recommended Posts

When i am using below code i am getting error.

Warning: sprintf(): Too few arguments in /var/www/html/Cdr.php on line 120

 

Please help me to find where is the issue.

 

$sql = "SELECT `id_call`,`id_client`, `ip_number`, `caller_id`, `called_number`, `call_start`, `route_type`, `id_tariff`, `cost`, `duration`, `tariff_prefix`, `client_type`, `pdd`, `costR1`, `costR2`, `costR3`, `id_reseller`, `tariffdesc`, `client_pdd`, `orig_call_id`, `term_call_id` from calls WHERE client_type = %s ";
$sval = "mysql_real_escape_string($pc),";
if($number <> ""){$sql .= "AND called_number LIKE '%s' "; $sval .= "mysql_real_escape_string('$number%'),";}
if($duration <> ""){$sql .= "AND duration $dc '%s' "; $sval .= "mysql_real_escape_string($duration),";}
if($ip <> ""){$sql .= "AND ip_number LIKE '%s' "; $sval .= "mysql_real_escape_string('$ip%'),";}
if($cid <> ""){$sql .= "AND caller_id LIKE '%s' "; $sval .= "mysql_real_escape_string('$cid%'),";}
$sql .= " AND call_start >= '%s' AND call_start <= '%s'";
$sval .= "mysql_real_escape_string($fromdate),";
$sval .= "mysql_real_escape_string($enddate)";
$sva = "mysql_real_escape_string($number)";
//echo $sval;
$tq = sprintf($sql,$sval);	

echo $tq;

There's a fair few issues with your code. You have mysql_real_escape_string as a string, this will not call the function it will simply submit that as a string to the database. The sprintf function expects an argument for every %s (or other substitution value) in the string, you are only passing one argument whereas it would appear that in certain instances you would require two.

Cags,

 

Thank you for your hint, i use the following and its working well...

 

$sql = sprintf("SELECT `id_call`,`id_client`, `ip_number`, `caller_id`, `called_number`, `call_start`, `route_type`, `id_tariff`, `cost`, `duration`, `tariff_prefix`, `client_type`, `pdd`, `costR1`, `costR2`, `costR3`, `id_reseller`, `tariffdesc`, `client_pdd`, `orig_call_id`, `term_call_id` from calls WHERE client_type = %s ", mysql_real_escape_string($pc));

if($number <> ""){$sql .= sprintf(" AND called_number LIKE '%s'", mysql_real_escape_string("$number%"));}

if($duration <> ""){$sql .= sprintf(" AND duration $dc '%s'", mysql_real_escape_string($duration));}

if($ip <> ""){$sql .= sprintf(" AND ip_number LIKE '%s'", mysql_real_escape_string("$ip%"));}

if($cid <> ""){$sql .= sprintf(" AND caller_id LIKE '%s'",mysql_real_escape_string($cid));}

$sql .= sprintf(" AND call_start >= '%s' AND call_start <= '%s'",mysql_real_escape_string($fromdate),mysql_real_escape_string($enddate));

 

 

echo $sql;

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.