Error when uploading mySQL file - mysql

After i used the new answer i uploaded the file and this is what i get now.
SQL query:
CREATE TABLE IF NOT EXISTS `games` ( ) INSERT INTO `games` (`name`, `creatorid`, `gameid`, `id`, `plays) VALUES ('בדיקה', 'לא ידוע', 1,1,0) CREATE TABLE IF NOT EXISTS `gamewall` ( `userid` int(11) NOT NULL, `reason` text NOT NULL, `comment` text NOT NULL, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `bannedbyid` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; CREATE TABLE IF NOT EXISTS `bans_IP` ( `IP` mediumtext NOT NULL, `id` int(11) NOT NULL AUTO_INCREMENT, `bannerid` int(11) NOT NULL, `reason` mediumtext NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; CREATE TABLE IF NOT EXISTS `buysell` ( `buysell` int(11) NOT NULL, `sellerid` int(11) NOT NULL, `price` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; CREATE TABLE IF NOT EXISTS `competitions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` mediumtext NOT NULL, `startedbyid` int(11) NOT NULL, `descripti[...]
MySQL said: Documentation
#1064 - 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 ')
INSERT INTO `games` (`name`, `creatorid`, `gameid`, `id`, `plays) VALUES
('' at line 3

You are receiving this error because you have selected all the columns of your table but values are available for first 11 columns and you missed ) in last
This code will fix your problem
INSERT INTO `accounts` (
`Username`,
`Password`,
`Email`,
`salt`,
`Reebs`,
`online`,
`lastOnline`,
`lastOnlineMinutes`,
`lastOnlineHours`,
`status`,
`blurb`
)
VALUES
(
'AvatarLife',
'df3ed1ad53c4cc2f3b5c6bdf04d33a9f094df53b',
'fawrsnipng#gmail.com',
'jBqnW?Dk9Epzpg4',
'9223372036854775807',
'1',
'205',
'26',
'13',
'',
'Avatar Life is the only good life!')

Related

MySQL insert fails

I am trying to create and insert into 2 tables on sqlfiddle.
CREATE TABLE IF NOT EXISTS `Submissions` (
`sub_id` int(6) unsigned NOT NULL,
`hacker_id` int(3) unsigned NOT NULL,
`score` int(3) NOT NULL,
`sub_date` Date NOT NULL,
PRIMARY KEY (`sub_id`,`hacker_id`)
) DEFAULT CHARSET=utf8;
INSERT INTO `Submissions` (`sub_id`, `hacker_id`, `score`, `sub_date`) VALUES
('18833', '962', '12', '2019-12-07'),
('35892', '962', '45', '2019-12-07');
CREATE TABLE IF NOT EXISTS `Hacker` (
`hacker_id` int(10) NOT NULL,
`name` varchar(20) NOT NULL,
PRIMARY KEY(`hacker_id`, `name`)
)
INSERT INTO `Hacker` (`hacker_id`, `name`) VALUES
('123','Bob');
The insert into Submissions works fine. I do not understand what is wrong with my Insert into Hacker which fails.
Fiddle is here: http://sqlfiddle.com/#!9/d4d786 but refreshing drops the second insert, I'm guessing because it fails to compile/build/whatever the term is in SQL.
You are missing a ; after your second CREATE TABLE statement. It should look like this:
CREATE TABLE IF NOT EXISTS `Submissions` (
`sub_id` int(6) unsigned NOT NULL,
`hacker_id` int(3) unsigned NOT NULL,
`score` int(3) NOT NULL,
`sub_date` Date NOT NULL,
PRIMARY KEY (`sub_id`,`hacker_id`)
) DEFAULT CHARSET=utf8;
INSERT INTO `Submissions` (`sub_id`, `hacker_id`, `score`, `sub_date`) VALUES
('18833', '962', '12', '2019-12-07'),
('35892', '962', '45', '2019-12-07');
CREATE TABLE IF NOT EXISTS `Hacker` (
`hacker_id` int(10) NOT NULL,
`name` varchar(20) NOT NULL,
PRIMARY KEY(`hacker_id`, `name`)
);
INSERT INTO `Hacker` (`hacker_id`, `name`) VALUES
('123','Bob');

error while importing .sql to phpMyAdmin db

I want to import an SQL file to my phpMyAdmin database, the file contains tables about a restaurant application and a table about the admin login, but I have 2 unexpected errors, I really don't see what is exactly wrong with that?. here is the error message:
2 errors were found during analysis.
An opening bracket followed by a set of values was expected. (near "CREATE" at position 109)
Unexpected token. (near "CREATE" at position 109)
SQL query:
INSERT INTO `adminlogin` (`id`, `Username`, `Password`, `right`) VALUES (1, 'admin#gmail.com', '123', 1), CREATE TABLE IF NOT EXISTS `tbl_food` ( `id` int(11) NOT NULL AUTO_INCREMENT, `food_type` varchar(50) NOT NULL, `food_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CREATE TABLE IF NOT EXISTS `tbl_food` (
`id` int(11) NOT NULL AUTO_INCREMENT,
' at line 6
and here is the two tables that show errors. Any insight on that? thank you
CREATE TABLE IF NOT EXISTS `adminlogin` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`Username` varchar(100) NOT NULL,
`Password` varchar(50) NOT NULL,
`right` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
--
-- Dumping data for table `adminlogin`
--
INSERT INTO `adminlogin` (`id`, `Username`, `Password`, `right`) VALUES
(1, 'admin#gmail.com', '123', 1),
-- --------------------------------------------------------
--
-- Table structure for table `tbl_food`
--
CREATE TABLE IF NOT EXISTS `tbl_food` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`food_type` varchar(50) NOT NULL,
`food_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
You have a comma at the end of INSERT statement, instead of semicolon.

selecting multiple rows issue in mysql

I am beginner in sql.
I have two tables users and installments
CREATE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(20) NOT NULL,
`password` varchar(10) NOT NULL,
`father_name` varchar(20) NOT NULL,
`phone` varchar(20) NOT NULL,
`cnic` varchar(20) NOT NULL,
`email` varchar(100) NOT NULL,
`address` varchar(100) NOT NULL,
`introducer` varchar(100) NOT NULL,
`date` date DEFAULT NULL,
`reg_number` varchar(100) DEFAULT NULL,
`installment` int(100) NOT NULL,
`user_level` int(11) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `cnic` (`cnic`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;
INSERT INTO `users` (`id`, `user_name`, `password`, `father_name`, `phone`, `cnic`, `email`, `address`, `introducer`, `date`, `reg_number`, `installment`, `user_level`) VALUES
(2, 'qaser', 'Qaser1', 'zamarrud', '0312546879', '37406-3140185-1', 'tariq_kareem#yahoo.com', 'street # 6', 'rizwan', '2014-08-20', 'E-002', 3000, 0);
and
CREATE `installments` (
`installment_id` int(11) NOT NULL AUTO_INCREMENT,
`month` date DEFAULT NULL,
`prv_arrear` int(100) NOT NULL,
`amount` int(100) NOT NULL,
`total` int(100) NOT NULL,
`receive` int(100) NOT NULL,
`arrear` int(100) NOT NULL,
`fk_users_id` int(11) NOT NULL,
PRIMARY KEY (`installment_id`),
KEY `fk_users_id` (`fk_users_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
INSERT INTO `installments` (`installment_id`, `month`, `prv_arrear`, `amount`, `total`, `receive`, `arrear`) VALUES
(2, '2014-08-20', 2000, 2500, 4500, 3000, 1500);
when I run the following query I get the first table's record correctly but the second table's record showing NULL values
SELECT * FROM users
LEFT JOIN installments
ON users.id=installments.installment_id
WHERE users.cnic='37406-3140185-1';
Is there anything missing in the above query or is there another way to get the record from both tables simultaneously
id user_name password father_name phone cnic email address introducer date reg_number installment user_level installment_id month prv_arrear amount total receive arrear fk_users_id
2 qaser Qaser1 zamarrud 0312546879 37406-3140185-1 tariq_kareem#yahoo.com street # 6 rizwan 2014-08-20 s-001 3000 0 NULL NULL NULL NULL NULL NULL NULL NULL
I am also using the following query to inserting the record for getting primary key value and insert into foreign key
INSERT INTO `installments`(`id`, `month`, `prv_arrear`, `amount`, `total`, `receive`, `arrear`, fk_users_id)
SELECT NULL,now(),1000,2500,3500,3000,500, id
FROM users
WHERE cnic = '37406-3140190-1'
please help me thanks in advance and sorry if there is something wrong in my question because I am new in sql.
I suspect the right join condition is on fk_users_id. So this might do what you want:
SELECT *
FROM users u LEFT JOIN
installments i
ON u.id = i.fk_users_id
WHERE u.cnic = '37406-3140185-1';

You have an error in your SQL syntax when adding query to the mysql database

I am trying to add an addon to my game here, and i need to add this query to the mysql, query is below:
CREATE TABLE `streets` (
`id` int(11) NOT NULL auto_increment,
`min_level` int(11) NOT NULL,
`text` longtext NOT NULL,
`query` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MYISAM ;
INSERT INTO `settings` (`conf_id`, `conf_name`, `conf_value`) VALUES ('NULL', 'steps_daily', '100')
ALTER TABLE `users` ADD `steps` INT( 11 ) NOT NULL ;
When i try to enter the query into sql i get this error:
Error
SQL query:
INSERT INTO `settings` ( `conf_id` , `conf_name` , `conf_value` )
VALUES (
'NULL', 'steps_daily', '100'
)
ALTER TABLE `users` ADD `steps` INT( 11 ) NOT NULL ;
MySQL said: Documentation
#1064 - 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 'ALTER TABLE `users` ADD `steps` INT( 11 ) NOT NULL' at line 3
You forgot a ; after your INSERT INTO query.
CREATE TABLE `streets` (
`id` int(11) NOT NULL auto_increment,
`min_level` int(11) NOT NULL,
`text` longtext NOT NULL,
`query` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MYISAM ;
INSERT INTO `settings` (`conf_id`, `conf_name`, `conf_value`) VALUES
(NULL, 'steps_daily', '100');
ALTER TABLE `users` ADD `steps` INT( 11 ) NOT NULL ;
P.S.: NULL should not be in quotes. You want the value NULL, not the literall string ,'NULL'.
Do not use quotes for NULL and then try.
INSERT INTO `settings` ( `conf_id` , `conf_name` , `conf_value` )
VALUES (NULL, 'steps_daily', '100');

What causes duplicate PKs in MySQL?

I encountered this quite a few times so far, but still don't understand it (my MySQL internals skills are equal to none).
I know it's probably a PEBKAC but trying to replicate the behavior manually ends up with an error (autoincrement).
CREATE TABLE `foo_bar` (
`id` int(12) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(12) unsigned DEFAULT NULL,
`order_id` int(12) unsigned DEFAULT NULL,
`email_address` varchar(50) DEFAULT NULL,
`mobile_number` varchar(20) DEFAULT NULL,
`message` longtext NOT NULL,
`message_received` int(12) unsigned DEFAULT NULL,
`failed_to_send` tinyint(1) unsigned DEFAULT NULL,
`fraudulent_activity` tinyint(1) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=ARCHIVE DEFAULT CHARSET=utf8;
When your program inserts a row in the database, it should provide NULL as the value for auto-incremented field:
CREATE TABLE `customers` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 128 ) NOT NULL
) ENGINE = MYISAM ;
INSERT INTO `customers` ( `id` , `name` )
VALUES ( NULL , 'Customer 1' ), ( NULL , 'Customer 2' );
If you try to insert a specific value in id field, MySQL will give an error:
SQL query:
INSERT INTO `customers` ( `id` , `name` )
VALUES ( '1', 'Customer 3' );
MySQL said:
#1062 - Duplicate entry '1' for key 'PRIMARY'
Although the answer to "what caused this" didn't come up, REPAIR TABLE fixes the problem.
Answering this so I can close the question.