MySQL - freezing when I try INSERT INTO
Note, I am a relative newbie and ran into a problem using a book to learn PHP and Mysql.
In a database named "zips" with one existing table named "zip_codes," I added a table named stores successfully in mysql using this code
CREATE TABLE stores (
store_id SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(60) NOT NULL,
address1 VARCHAR(100) NOT NULL,
address2 VARCHAR(100) default NULL,
zip_code INT(5) UNSIGNED ZEROFILL NOT NULL,
phone VARCHAR(15) NOT NULL,
PRIMARY KEY (store_id),
KEY (zip_code)
);
Afterwards, I inserted the 15 or so lines of data below into the table, but during the numerous times that I tried it just seemed to freeze things. For example, instead of giving me the usual rows affected output, the command line just shows an '>
and I am unable to enter anymore SQL, can't even quit.
So I manually shut down the command line and opened it up again and tried the same thing with the same result. For the sake of variation, I also tried to just enter one row of data (intead of the 15) but got the same result.
Does anyone know what's happening?
INSERT INTO stores (name, address1, address2, zip_code, phone) VALUES
(‘Ray''s Shop', ‘49 Main Street', NULL, ‘63939', ‘(123) 456-7890'),
(‘Little Lulu''s', ‘12904 Rockville Pike', ‘#310', ‘10580', ‘(123) 654- 7890'),
(‘The Store Store', ‘8200 Leesburg Pike', NULL, ‘02461', ‘(123) 456- 8989'),
(‘Smart Shop', ‘9 Commercial Way', NULL, ‘02141', ‘(123) 555-7890'),
(‘Megastore', ‘34 Suburban View', NULL, ‘31066', ‘(555) 456-7890'),
(‘Chain Chain Chain', ‘8th & Eastwood', NULL, ‘80726', ‘(123) 808-7890'),
(‘Kiosk', ‘St. Charles Towncenter', ‘3890 Crain Highway', ‘63384', ‘(123) 888-4444'),
(‘Another Place', ‘1600 Pennsylvania Avenue', NULL, ‘05491', ‘(111) 456- 7890'),
(‘Fishmonger''s Heaven', ‘Pier 9', NULL, ‘53571', ‘(123) 000-7890'),
(‘Hoo New', ‘576b Little River Turnpike', NULL, ‘08098', ‘(123) 456-0000'),
(‘Va开发者_如何学Pythonmps ‘'R'' Us', ‘Our Location', ‘Atwood Mall', ‘02062', ‘(222) 456- 7890'),
(‘Five and Dime', ‘9 Constitution Avenue', NULL, ‘73503', ‘(123) 446- 7890'),
(‘A & P', ‘890 North Broadway', NULL, ‘85329', ‘(123) 456-2323'),
(‘Spend Money Here', ‘1209 Columbia Pike', NULL, ‘10583', ‘(321) 456- 7890');
The problem appears to be with your quotation marks--they don't match. You should put strings in either single quotes '
or double quotes "
(same opening and closing mark).
INSERT INTO stores (name, address1, address2, zip_code, phone) VALUES
("Ray's Shop", '49 Main Street', NULL, '63939', '(123) 456-7890');
...and so forth.
The >
prompt on the mysql command line indicates that it's waiting for further input. In practice, I find this usually happens when I omit the ending semicolon. However, if the interpreter thinks you're in the midst of entering a string, it will assume your semicolon is part of that string and happily wait for you to finish.
Use mysql_real_escape_string() function like below example
$query = sprintf("INSERT INTO product_description (language_id,name) VALUES ( '1','%s') ",mysql_real_escape_string($product_name));
mysql_query($query) or die(mysql_error());
i tried you code in phpmyadmin, it was some mistake there. Try this:
INSERT INTO `stores` (`store_id`, `name`, `address1`, `address2`, `zip_code`, `phone`)
VALUES (NULL, "Ray's Shop", '49 Main Street', NULL, '63939', '(123) 456-7890');
精彩评论