abdul_zu Posted November 15, 2009 Share Posted November 15, 2009 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; Link to comment https://forums.phpfreaks.com/topic/181604-solved-sprintf-too-few-arguments-pls-help-me/ Share on other sites More sharing options...
cags Posted November 15, 2009 Share Posted November 15, 2009 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. Link to comment https://forums.phpfreaks.com/topic/181604-solved-sprintf-too-few-arguments-pls-help-me/#findComment-957912 Share on other sites More sharing options...
abdul_zu Posted November 15, 2009 Author Share Posted November 15, 2009 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; Link to comment https://forums.phpfreaks.com/topic/181604-solved-sprintf-too-few-arguments-pls-help-me/#findComment-957917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.