Jump to content

You have an error in your SQL syntax ?


balkan7

Recommended Posts

hi, i tested my code many times but whitout result where i wrong ?

 

i get this: You have an error in your SQL syntax near 'WHERE banner_id = 18' at line 2

 

<?php
      if ($data['banner_type'] == "0"){
	$banner_url = addslashes(stripinput($_POST['banner_url']));
	$banner_data = addslashes(stripinput($_POST['banner_img']));
	$bquery = "banner_url = '$banner_url', banner_img = '$banner_data'";
	} else {
	$banner_data = addslashes(stripinput($_POST['banner_url']));
	$bquery = "banner_url = '$banner_data'";
} 
      if ($banner_expire == 1) {
$expire = "banner_expire = NOW() + INTERVAL 1 MONTH";
      } elseif ($banner_expire == 2){
$expire = "banner_expire = NOW() + INTERVAL 2 MONTH";
      } elseif ($banner_expire == 3){
      	$expire = "banner_expire = NOW() + INTERVAL 3 MONTH";
      } elseif ($banner_expire == 4){
      	$expire = "banner_expire = NOW() + INTERVAL 6 MONTH";
      } elseif ($banner_expire == 5){
      	$expire = "banner_expire = NOW() + INTERVAL 1 YEAR";
      } else {
      	$expire = "";
      }
      if ($banner_name == "" || $banner_data == ""){
			echo "<center>".$locale['BB_112']."</center><br /><br />";
		} else {
			$update_banner = dbquery("UPDATE ".$db_prefix."btr_banners SET 
			banner_type = '$banner_type', banner_state = '$banner_state', banner_plans = '$banner_plans', client_id = '$client_id', banner_name = '$banner_name', ".$bquery.", ".$expire." WHERE banner_id = ".$banner_id);
			echo "<center>".$locale['BB_113']."</center><br /><br />";
		}?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/84384-you-have-an-error-in-your-sql-syntax/
Share on other sites

$expire looks like it was intended to use one of the date/time functions, but it is just the sum of two terms, which would probably generate a syntax error. However, when $expire is "", this will result in a trailing coma , from the previous term in the query, which will generate a syntax error.

 

Forming your query in a variable, so that it can be echoed to see what it actually contains will certainly help you debug this yourself.

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.