1

My MySQL statement is not running properly on my PHP page. The statement itself appears to be getting cut off. Others have had similar problems—as shown in this thread as well as this thread—but they were using reserved words in their statements.

But according to what I can see from the MySQL documentation, I don't believe I am using any.

When I run this query:

$ticket_query = "
SELECT  myticket.number,
    myticket.status,
    myticket.created,
    myticket.source,
    myticket.ticket_id,
    myticket.lastresponse,
    myticket__cdata.subject,
    myticket__cdata.priority,
FROM myticket
    INNER JOIN myticket__cdata
    ON myticket.ticket_id = myticket__cdata.ticket_id
WHERE   (myticket.status = 'open');";

I get this error on my PHP page:

There was an error running the ticket query [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 'FROM myticket INNER JOIN myticket__cdata ON myticket.ticket_id = o' at line 9]

However, when I run it formatted like this:

$ticket_query = "
SELECT  myticket.number,
    myticket.status,
    myticket.created,
    myticket.source,
    myticket.ticket_id,
    myticket.lastresponse,
    myticket__cdata.subject,
    myticket__cdata.priority,
FROM myticket INNER JOIN myticket__cdata ON myticket.ticket_id = myticket__cdata.ticket_id
WHERE   (myticket.status = 'open');";

I get this error on my PHP page:

There was an error running the ticket query [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 'FROM myticket INNER JOIN myticket__cdata ON myticket.ticket_id = osti_t' at line 9]

I'm kind of stuck here and I'm assuming it is something small I am missing.

Community
  • 1
  • 1
user3255843
  • 69
  • 1
  • 8
  • 1
    This is your problem, `myticket__cdata.priority, FROM myticket`. That extra comma after `myticket__cdata.priority` is causing the error. – Giacomo1968 Oct 14 '14 at 14:28

1 Answers1

1

you had an extra comma just before the FROM

$ticket_query = "
SELECT  myticket.number,
    myticket.status,
    myticket.created,
    myticket.source,
    myticket.ticket_id,
    myticket.lastresponse,
    myticket__cdata.subject,
    myticket__cdata.priority /*removed comma from here*/
FROM myticket
    INNER JOIN myticket__cdata
    ON myticket.ticket_id = myticket__cdata.ticket_id
WHERE   (myticket.status = 'open');";
Pentium10
  • 204,586
  • 122
  • 423
  • 502