query works in mysql terminal but not in php -


I dynamically create my query in PHP, and when I try to execute it, it Fails When I copy the query and paste it into a MySQL terminal and run it, it works fine. The error I get is "There is an error in your SQL syntax; The manual, which is related to your" MySQL server version, "has the right syntax to use." On line 1 for the following query:

  UPDATE events SET event = 'orgo lecture', start = '2014-07-24 16:00:00' where UserID = 1 and eventID = 5   

The code that generates the query is dynamically low:

  $ query = "UPDATE events SET"; $ Query_list = Array (); If ($ set_event) {$ query_list [] = "event = '{$ event}'"; } If ($ set_start) {$ query_list [] = "start = '{$ start}'"; } If ($ set_end) {$ query_list [] = "end = '{$ end}'"; } $ Query_list_size = count ($ query_list); ($ I = 0; $ i & lt; $ query_list_size - 1; $ i ++) {$ query for = $ Query_list [$ i]; $ Query = "," ;;; } $ Query = $ Query_list [$ query_list_size - 1]; $ Query = "WHERE userID = {$ userID} and eventID = {$ eventID}"; Echo $ query. = "& Lt; br / & gt;"; $ Query_result = mysqli_query ($ connection, $ query) or die (mysqli_error ($ connection));    

This problem is:

  resonance $ Query = "& Lt; br / & gt;";   

should be $ query echo "
";

Ironically, by checking your query you were breaking it.

As a side note,

  $ query_list_size = count ($ query_list); ($ I = 0; $ i & lt; $ query_list_size - 1; $ i ++) {$ query for = $ Query_list [$ i]; $ Query = "," ;;; } $ Query = $ Query_list [$ query_list_size - 1];   

can be reduced:

  $ query. = Implode (",", $ query_list);    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -