0

I'm getting the "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'long, ul_lat, ul_long, lr_lat, lr_long, buffer, study_area, from_date, to_dat...' at line 1 )" error.

I've dumped and checked variables. All have values or are NULL. The query table has first value queryid not included insert as it is an autoincrement primary key.

I have another function in this file that inserts in the exact same way, with an autoincrement variable, but all varibles in that table are strings and this one is a mix of int, varchar, decimal, dates. Cannot figure out what it's complaining about!

$stmt = $conn->prepare("select * from query where queryid = :queryid");
    
$insert = $conn->prepare("insert into query(lat, long, ul_lat, ul_long, lr_lat, lr_long, buffer, study_area, from_date, to_date, ge, wv, qb, ov, ik, email, status, request_date, search_date, inventory, cidr, num_images, delivery_date, wv2, wv3, NCCSmvDate)VALUES(:lat, :long, :ul_lat, :ul_long, :lr_lat, :lr_long, :buffer, :study_area, :from_date, :to_date, :ge, :wv, :qb, :ov, :ik, :email, :status, :request_date, :search_date, :inventory, :cidr, :num_images, :delivery_date, :wv2, :wv3, :NCCSmvDate)
");

//Begin Transaction
$conn->beginTransaction();
 
try {
    $res = $stmt->execute(array( ':queryid'=>$queryid));

    if (!$res) {
        throw new Exception('<p>Could not execute query. </p>');
    }
    if ($stmt->rowCount()>0){     
        throw new Exception('<p>That queryID is taken.</p>');
    }
    $res = $insert->execute(array(
        ':lat'=>$lat,
        ':long'=>$long,
        ':ul_lat'=>$ul_lat,
        ':ul_long'=>$ul_long,
        ':lr_lat'=>$lr_lat,
        ':lr_long'=>$lr_long,
        ':buffer'=>trim($buffer),
        ':study_area'=>trim($study_area),
        ':from_date'=>$from_date,
        ':to_date'=>$to_date,
        ':ge'=>trim($ge),
        ':wv'=>trim($wv),
        ':qb'=>trim($qb),
        ':ov'=>trim($ov),
        ':ik'=>trim($ik),
        ':email'=>trim($email),
        ':status'=>trim($status),
        ':request_date'=>$request_date,
        ':search_date'=>$search_date,
        ':inventory'=>trim($inventory),
        ':cidr'=>trim($cidr),
        ':num_images'=>$num_images,
        ':delivery_date'=>$delivery_date,
        ':wv2'=>trim($wv2),
        ':wv3'=>trim($wv3),
        ':NCCSmvDate'=>$NCCSmvDate
    ));
user3783243
  • 5,368
  • 5
  • 22
  • 41
  • `long` is reserved. That needs to be in backticks. https://mariadb.com/kb/en/reserved-words/ `Reserved words cannot be used as Identifiers, unless they are quoted.` – user3783243 May 17 '22 at 15:55
  • ^(Disregard the "as table name" bit, same concept) – user3783243 May 17 '22 at 15:58
  • Oh geez! THANK YOU! I had changed that from lon to long (short for longitude) and introduced that error in the code that used to work just fine! I saw errors in here for other reserved words, NEVER clicked that I had one!! I hate to admit how much I've banged my head against the wall on this one. – user1546622 May 17 '22 at 16:09

0 Answers0