This is a discussion on like problem within the MySQL Database forums, part of the Database Forums category; I am new to MYSQL and the solution is probably quite simple. In a php application I am writing, I ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I am new to MYSQL and the solution is probably quite simple. In a php
application I am writing, I am trying trying to write a query to select all record beginning with an initial, in this case the letter M. PHP CODE: ----- $query = "SELECT id, surname, useName FROM individuals ORDER BY surname, useName ASC WHERE surname LIKE '" . $initial . "%'" ; $result = mysql_query($query, $link) or die ('<br />Error in query: ' . $query . '<br />' . mysql_error()); ----- When I run the page, I get an error message reporting a SQL syntax error with the query. Error message: ----- Error in query: SELECT id, surname, useName FROM individuals ORDER BY surname, useName ASC WHERE surname LIKE 'M%' 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 'WHERE surname LIKE 'M%'' at line 1 ----- When I copy & paste the query into phpmyadmin, I get the same message. When I use the phpadmin query panel to create the query, it works. Any suggestions? Thanks, Carolyn |
|
|||
|
Carolyn Marenger <cajunk@marenger.com> wrote in news:d7867$478c40f5
$cf70133e$18160@PRIMUS.CA: > I am new to MYSQL and the solution is probably quite simple. In a php > application I am writing, I am trying trying to write a query to select > all record beginning with an initial, in this case the letter M. > > PHP CODE: > ----- > $query = "SELECT id, surname, useName FROM individuals ORDER BY surname, > useName ASC WHERE surname LIKE '" . $initial . "%'" ; > > $result = mysql_query($query, $link) or die ('<br />Error in query: ' . > $query . '<br />' . mysql_error()); > ----- > > > When I run the page, I get an error message reporting a SQL syntax error > with the query. > > Error message: > ----- > Error in query: SELECT id, surname, useName FROM individuals ORDER BY > surname, useName ASC WHERE surname LIKE 'M%' > > 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 'WHERE > surname LIKE 'M%'' at line 1 > ----- > > When I copy & paste the query into phpmyadmin, I get the same message. > When I use the phpadmin query panel to create the query, it works. > > Any suggestions? > > Thanks, > > Carolyn > SELECT id, surname, useName FROM individuals WHERE surname LIKE 'M%' ORDER BY surname, useName ASC |
|
|||
|
Ana C. Dent wrote:
> Carolyn Marenger <cajunk@marenger.com> wrote in news:d7867$478c40f5 > $cf70133e$18160@PRIMUS.CA: > >> I am new to MYSQL and the solution is probably quite simple. In a php >> application I am writing, I am trying trying to write a query to > select >> all record beginning with an initial, in this case the letter M. >> >> PHP CODE: >> ----- >> $query = "SELECT id, surname, useName FROM individuals ORDER BY > surname, >> useName ASC WHERE surname LIKE '" . $initial . "%'" ; >> >> $result = mysql_query($query, $link) or die ('<br />Error in query: > ' . >> $query . '<br />' . mysql_error()); >> ----- >> >> >> When I run the page, I get an error message reporting a SQL syntax > error >> with the query. >> >> Error message: >> ----- >> Error in query: SELECT id, surname, useName FROM individuals ORDER BY >> surname, useName ASC WHERE surname LIKE 'M%' >> >> 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 'WHERE >> surname LIKE 'M%'' at line 1 >> ----- >> >> When I copy & paste the query into phpmyadmin, I get the same message. >> When I use the phpadmin query panel to create the query, it works. >> >> Any suggestions? >> >> Thanks, >> >> Carolyn >> > > SELECT id, surname, useName FROM individuals > WHERE surname LIKE 'M%' > ORDER BY surname, useName ASC Thanks! It still needs some tweaking, but no error messages any more. :) Carolyn |