Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
phpstuff

Ch 5, Pg 136 - Mysql Terminal Error 1064 (42000)

Recommended Posts

I entered in the below code into terminal and got the error below in red.  Not sure where the error is?  I double checked it but operating on minimal sleep so maybe a dumb error...

INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES    
('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()),
('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW()),
('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());


ERROR 1064 (42000): 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 'VALUES
('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
('Paul'' at line 1

Share this post


Link to post
Share on other sites

That's very strange. I don't see anything obvious there. Could you lay out the steps you took to get to that point (what you did before running that query)?

Share this post


Link to post
Share on other sites

Sure here is all the code below.  There is an error towards the bottom (George Harrison) I did find, but, as you'll see after that I corrected it (it was missing 1 parenthesis on the NOW ).  Maybe you can find something.  Maybe restart everything??

mysql> use sitename;
Database changed
mysql> CREATE TABLE users (
    -> user_id MEDIUMINT UNSIGNED NOT NULL
    -> AUTO_INCREMENT,
    -> first_name VARCHAR(20) NOT NULL,
    -> last_name VARCHAR(40) NOT NULL,
    -> email VARCHAR(60) NOT NULL,
    -> pass CHAR(40) NOT NULL,
    -> registration_date DATETIME NOT NULL,
    -> PRIMARY KEY (user_id)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> SHOW TABLES;
+--------------------+
| Tables_in_sitename |
+--------------------+
| users              |
+--------------------+
1 row in set (0.00 sec)

mysql> SHOW COLUMNS FROM users;
+-------------------+-----------------------+------+-----+---------+----------------+
| Field             | Type                  | Null | Key | Default | Extra          |
+-------------------+-----------------------+------+-----+---------+----------------+
| user_id           | mediumint(8) unsigned | NO   | PRI | NULL    | auto_increment |
| first_name        | varchar(20)           | NO   |     | NULL    |                |
| last_name         | varchar(40)           | NO   |     | NULL    |                |
| email             | varchar(60)           | NO   |     | NULL    |                |
| pass              | char(40)              | NO   |     | NULL    |                |
| registration_date | datetime              | NO   |     | NULL    |                |
+-------------------+-----------------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)

mysql> INSERT INTO users 
    -> (first_name, last_name, email, pass, registration_date)
    -> VALUES ('John', 'smith', 'johnsmith@yahoo.com', SHA1('testpassword'), NOW());
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO users VALUES
    -> (NULL, 'Zoe', 'Isabella', 'email2@example.com', SHA1('mojito'), NOW());
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    44
Current database: sitename

Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES
    -> ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
    -> ('Paul', 'McCartney', 'paul@beatles.com', SHA1('lefITbe'), NOW()),
    -> ('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW(),
    -> ('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());
ERROR 1064 (42000): 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 '' at line 5
mysql> INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES    -> ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
    -> ('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()),
    -> ('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW()),
    -> ('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());
ERROR 1064 (42000): 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 'VALUES
('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
('Paul'' at line 1
mysql> INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), ('Paul', 'McCartney', 'paul@beatles.com', SHAe) VALUES ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), ('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()), ('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW()), ('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());
ERROR 1064 (42000): 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 'VALUES ('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()), ('Paul'' at line 1

Share this post


Link to post
Share on other sites

I entered in the below code into terminal and got the error below in red.  Not sure where the error is?  I double checked it but operating on minimal sleep so maybe a dumb error...

INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES    
('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),
('Paul', 'McCartney', 'paul@beatles.com', SHA1('letITbe'), NOW()),
('George', 'Harrison', 'george@beatles.com', SHA1('something'), NOW()),
('Ringo', 'Starr', 'ringo@beatles.com', SHA1('thisboy'), NOW());


ERROR 1064 (42000): 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 'VALUES

('John', 'Lennon', 'john@beatles.com', SHA1('Happin3ss'), NOW()),

('Paul'' at line 1

 

I tested this code and it worked for me without changing your code.

So I'm not sure why either.

Share this post


Link to post
Share on other sites

I've since quit using Terminal and have been using phpmyadmin with no issues.

 

If I have both PMA and Terminal open simultaneously would that screw up anything?

Share this post


Link to post
Share on other sites

It's very strange. I don't see any reason why you'd get that error. phpMyAdmin is fine, and there's no problem with having both open at once.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...