shadiadiph Posted July 16, 2014 Share Posted July 16, 2014 (edited) I keep getting the following error even though it is still inserting it it is driving me nuts any ideas? 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 '`campaignid`,`ipaddress`,`cc`,`country`,`oldadddate`,`oldaddtime`,`oldtimestring' at line 1 `oldrecordid`,`campaignid`,`ipaddress`,`cc`,`country`,`oldadddate`,`oldaddtime`,`oldtimestring`,`adddate`,`addtime`,`timestring`'1','1','58.9.96.60','TH','Thailand','2014-07-16','02:11:41','1405501901','2014-07-16','02:43:45','1405503825' my insert strings // INSERT IP RECORDS LOG $fi=""; $fi="`campaignid`,`ipaddress`,`cc`,`country`,`adddate`,`addtime`,`timestring`"; $fv=""; $fv="'$campaignid','$IpAddress','$cocode','$coname','$cdate','$ctime','$nowtime'"; echo "$fi<br />"; echo "$fv<br />"; $insertid="";$insertid=insertdata('iprecords',$fi,$fv,'yes'); my function which has always worked until today if(!function_exists('insertdata')){ function insertdata($table,$fields,$params,$idrequired){ global $db_host; global $db_name; global $db_user; global $db_pass; $db_con=mysqli_connect($db_host,$db_user,$db_pass,$db_name); if(mysqli_connect_errno($db_con)){return false;} $insertinfo="INSERT INTO $table ($fields) VALUES ($params)"; $rinsertinfo = mysqli_query($db_con,$insertinfo); if($idrequired=="yes"){ $insertid =mysqli_insert_id($db_con); if($insertid==true) { return $insertid; } // END if($insertid==true) else { return false; } // END else } // END if($idrequired=="yes") else { return $rinsertinfo; } // END else mysqli_close($db_con); } // END function insertdata($table,$fields,$params.$idrequired) } // END if(!function_exists('insertdata')) Edited July 16, 2014 by shadiadiph Quote Link to comment https://forums.phpfreaks.com/topic/289931-wierd-sql-error-even-though-it-is-inserting/ Share on other sites More sharing options...
Barand Posted July 16, 2014 Share Posted July 16, 2014 You need to post a printout of the entire SQL query that is being submitted Quote Link to comment https://forums.phpfreaks.com/topic/289931-wierd-sql-error-even-though-it-is-inserting/#findComment-1485430 Share on other sites More sharing options...
mac_gyver Posted July 16, 2014 Share Posted July 16, 2014 the error is coming from some other call to your function as the column names don't match. also, you should not be making the database connection inside your function, running one query, and closing the database connection. your main code should make ONE database connection and pass it into any functions that need it as a call time parameter (or inject it into any class that needs it.) Quote Link to comment https://forums.phpfreaks.com/topic/289931-wierd-sql-error-even-though-it-is-inserting/#findComment-1485444 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.