Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.61 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to construct a mysql query that puts quotes around strings but not numbers?
  2. function mysql_insert($table, $arr){
  3. if($arr!=''){
  4.     $values = array_map('mysql_real_escape_string', array_values($arr));
  5.     $keys = array_keys($arr);
  6.     $q=('INSERT INTO `'.$table.'` (`'.implode('`,`', $keys).'`) VALUES (''.implode('','', $values).'')');
  7.     //$res = mysql_query($q)OR die(mysql_error());
  8.     return $q;
  9. }else{
  10.     return false;
  11. }
  12.        
  13. if($crud=='insert'){
  14. $field= array(  'col1' => 'apel',
  15.         'c0l2' => 'box1',
  16.         'col3' => 200,//integer Quantity
  17.     );
  18. $data=mysql_insert('wh',$field);}echo json_encode($data);