Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2008, 01:33 AM
Registered User
 
Join Date: Apr 2008
Location: Peshawar, N.W.F.P, Pakistan.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default php


When I running this programme to retrieve the data from table,
its gives me this type of error in browser window, given below .


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 '>1990 ORDER BY movie_type' at line 1.



Please tell me about its solution.

Thank You.

This is the programme given below.

<?php
$connect=mysql_connect("localhost","root","asimpc" )
or die("Hey loser,check your server connection.");
mysql_select_db("moviesite");


$query="SELECT movie_name,movie_type ".
       "FROM MOVIE".
       "WHERE movie_year>1990 ".
       "ORDER BY movie_type ";
$results=mysql_query($query)
or die(mysql_error());


while($row=mysql_fetch_array($results))
{
extract($row);
echo $movie_name;
echo " - ";
echo $movie_type;
echo "<br>";
}
?>





 
Old May 13th, 2008, 09:16 AM
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

A quick hint on debugging sql problems is to print your sql statement. It would have helped here ;)

Code:
$query="SELECT  movie_name,movie_type ".
       "FROM MOVIE".
       "WHERE movie_year>1990 ".
       "ORDER BY movie_type ";
echo $query;
Gives us:
Code:
SELECT  movie_name,movie_type FROM MOVIEWHERE movie_year>1990 ORDER BY movie_type
See the missing space? So, try:
Code:
$query="SELECT  movie_name,movie_type ".
       "FROM MOVIE ". // <-- extra space here
       "WHERE movie_year>1990 ".
       "ORDER BY movie_type ";
echo $query;
And we get:
Code:
SELECT  movie_name,movie_type FROM MOVIE WHERE movie_year>1990 ORDER BY movie_type
HTH
Charlie

--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk




Similar Threads
Thread Thread Starter Forum Replies Last Post
Beg. PHP 5 > Ch. 11 - fetch_field.php crater BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 January 2nd, 2007 12:20 PM
PHP Warning: PHP Startup: Unable to load dynamic l surendran Beginning PHP 1 May 29th, 2006 08:49 AM
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 10:57 AM
Error: movie.php & commit.php on p182-186, ch6 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 12th, 2004 02:48 PM
Ch. 1: PHP Installation Troubles: php3 vs php manjito BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 4 June 12th, 2003 03:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.