Current location: Hot Scripts Forums » Other Discussions » Database » Syntax error message confusion with PHP & MySQL


Syntax error message confusion with PHP & MySQL

Reply
  #1 (permalink)  
Old 03-29-11, 10:40 AM
tony2getit tony2getit is offline
Newbie Coder
 
Join Date: Mar 2011
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Syntax error message confusion with PHP & MySQL

Hi, please help as patience is wearing. I am receiving the following error message when running script to connect to MySQL database and then create some tables. I am using XAMPP and Notepad to write scripts if this info helps.

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 'EXIST moviesite' at line 1

For the life of me I can't see where the error is and have a feeling it lies somewhere else.
This is my first attempt at a database in PHP and I am eager to move on from here as well as learn where I am messing up. The script is here:

PHP Code:

<?php
//connect to MySQL



$db mysql_connect ('localhost''bp6am''*******') or
    die (
'Unable to connect. Check your connection parameters.');

//create the main database if it doesn't already exist
$query 'CREATE DATABASE IF NOT EXIST moviesite';
mysql_query($query$db) or die(mysql_error($db));

//make sure our recently created datbase is the active one 
mysql_select_db('moviesite'$db) or die(mysql_error($db));

//create the movie table
$query 'CREATE TABLE movie (

    movie_id    INTEGER UNSIGNED   NOT NULL AUTO_INCREMENT,
    movie_name    VARCHAR (255)       NOT NULL,
    movie_type    TINYINT           NOT NULL DEFAULT 0,
    movie_year    SMALLINT UNSIGNED  NOT NULL DEFAULT 0,
    movie_leadactor INTEGER UNSIGNED   NOT NULL DEFAULT 0,
    movie_director  INTEGER UNSIGNED   NOT NULL DEFAULT 0,

    PRIMARY KEY (movie_id),
    KEY movie_type (movie_type, movie_year)

    )
    
    ENGINE=MySAM'
;
mysql_query($query$db) or die (mysql_error($db));

//create the movietype table
$query 'CREATE TABLE movietype (
    movietype_id    TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
    movietype_label VARCHAR(100)     NOT NULL,
    PRIMARY KEY (movietype_id)
    )
    ENGINE=MySAM'
;
mysql_query($query$db) or die (mysql_error($db));

//create the people table
$query 'CREATE TABLE people (
    people_id      INTEGER UNSIGNED    NOT NULL AUTO_INCREMENT,
    people_fullname   VARCHAR (225)        NOT NULL,
    people_isactor    TINYINT (1) UNSIGNED    NOT NULL DEFAULT 0,
    people_isdirector TINYINT (1) UNSIGNED  NOT NULL DEAFULT 0,

    PRIMARY KEY (people_id)

    )
    ENGINE=MySAM'
;
mysql_query($query$db) or die (mysql_error($db));

echo 
'Movie database successfully created!';
?>
User name and password have been set in PHPMyAdmin and I assume these are fine. Tired of checking code over and over and not finding the error. A solution to this would enhance my day immensely as I have looked on various web links for an answer without success.

Last edited by Nico; 03-30-11 at 04:47 AM.
Reply With Quote
  #2 (permalink)  
Old 03-30-11, 04:54 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Code:
CREATE DATABASE IF NOT EXISTS moviesite
... you missed an S.
Reply With Quote
  #3 (permalink)  
Old 03-30-11, 10:18 AM
tony2getit tony2getit is offline
Newbie Coder
 
Join Date: Mar 2011
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Syntax error fixed but more fundamental error in place

Thanks for prompt reply Nico and what can I say but DOH! However, I did have a feeling that I may have other problems and now have the error message:

Access denied for user 'bp6am'@'localhost' to database 'moviesite'

I am assuming that this has to do with permissions for password etc. and set up folders and the like which I have not had a lot of experience of using XAMPP or WAMP as I have only had to worry about programme code previously. Was sure that setting it in XAMPP PHPMyAdmin was enough. Is there somewhere else I should look to change in another part of XAMPP.

I originally tried using the 'root' option which is installed by XAMPP as default but could not get any of the example script ****ions on the web to work. Sorry if this should be obvious but it's not to me at the moment and am trying desperately to get past this hurdle and crack on with working on database for real. On a real learning curve here.
Reply With Quote
  #4 (permalink)  
Old 03-30-11, 11:42 AM
tony2getit tony2getit is offline
Newbie Coder
 
Join Date: Mar 2011
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Access to database denied after fixing syntax error

Thanks for your prompt reply Nico and all I can say is DOH! In future will check with a fine tooth comb but was assuming a connection error which is what I now have with the following message:

Access denied for user 'bp6am'@'localhost' to database 'moviesite'

I have as far as my limited knowledge of admin procedures/permissions set the user and password correctly in PHPMyAdmin but maybe I need to change elsewhere such another Xampp program folder. Must admit this all a bit fiddly for me at the moment and not obvious as I am just used to getting on with coding in the past. Is there something else to look for here so that I can leap this hurdle and get down to the more satisfying task of creating my actual database.

I'm on a good learning curve here however, and really should learn all about administration of MySql for the future but only have books and knowlege of programming concepts.
Reply With Quote
  #5 (permalink)  
Old 03-30-11, 11:52 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
The default usename for XAMPP is "root", with no password. Have you tried that?

Although, since you're still learning, I suggest you move straight away from the mysql_* library. It's very old, slow, and insecure. Instead, look at the improved MySQLi version or PDO. It does look more complicated at the beginning, but you won't regret it.
Reply With Quote
  #6 (permalink)  
Old 03-31-11, 03:32 PM
tony2getit tony2getit is offline
Newbie Coder
 
Join Date: Mar 2011
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Hi Nico, had tried using root with no password previously and got the following error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\Program Files\xampp\htdocs\db_ch03-1.php on line 6
Unable to connect. Check your connection parameters.


The script I tried was this:

$db = mysql_connect ('localhost', 'root', ' ') or
die ('Unable to connect. Check your connection parameters.');


I found this example posted by other users but doesn;t work for me.

Obviously I have not done this correctly somewhere and not sure exactly how to change as I have played around with leaving password completely blank and using double quotes for password i.e " " as empty string all to no avail.

As for MySQLi, this sounds like a good idea but how would I now use this with my XAMPP already installed or should I do a new install package? Sorry if I'm not seeing what I should be and am waiting for that moment when it all falls into place.
Reply With Quote
  #7 (permalink)  
Old 03-31-11, 03:58 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I'm unable to help you, then. XAMPP doesn't have a default password, so you must have changed it somehow. You could see if you find something in your php.ini file.

As for MySQLi, it's enabled by default too, so it shouldn't be a problem.
Reply With Quote
  #8 (permalink)  
Old 05-26-11, 02:53 AM
stoopkid stoopkid is offline
New Member
 
Join Date: May 2011
Location: chicago, il
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Nico is correct, there is no password as a default setting. You can change it though in the config file, or by going to the security area locally: http://localhost/security/

I use XAMPP on a daily base at work so post back if you still encounter problems or check here:
apache friends - xampp for windows
Reply With Quote
  #9 (permalink)  
Old 05-27-11, 06:49 PM
tony2getit tony2getit is offline
Newbie Coder
 
Join Date: Mar 2011
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
MySql database access solved

Hi Nico

Been working on some other stuff and then came back to fix this error. Thanks for the advice and I looked for the settings in MySql in case they had been changed. I installed Wamp server and still had issues but then found a tutorial on how to re-set user name and password back to defaults using MySql console and was then able to connect.
Reply With Quote
  #10 (permalink)  
Old 05-28-11, 03:31 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Awesome! Mind posting that tutorial, in case someone else here has the same problem?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP variable syntax in MySQL WHERE clause kevin_k PHP 4 07-19-09 11:49 PM
WEB HOSTING - $4.99/MONTH For 1GB HD & 25GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 10-20-05 07:26 AM
RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 07-14-05 10:56 AM
Complex mysql sorting pb (Get cat_list from cids &pcids with 1 query, willing to pay) aqw PHP 1 06-23-05 07:02 PM
RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 10-30-04 01:19 PM


All times are GMT -5. The time now is 05:15 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.