Jump to content

Wierd SQL error even though it is inserting


shadiadiph

Recommended Posts

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'))

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.)

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.