954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PHP Wizard & MySQL Insert Error

I have a php wizard for an application that does the MySQL insert but it comes back with an error message, and I can't seem to figure out what. Any help is greatly appreciated.

Insert Statement

CREATE TABLE `{dbprefix}permissions` (
  `ID` bigint(20) unsigned zerofill NOT NULL AUTO_INCREMENT,
  `permKey` varchar(30) NOT NULL,
  `permName` varchar(30) NOT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `permKey` (`permKey`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

INSERT INTO `{dbprefix}permissions` VALUES(00000000000000000001, 'delete_groups', 'Delete Groups');


MySQL Error Message:

MySQL: 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 `chm_permissions` VALUES(00000000000000000002, 'create_groups', 'Cre' at line 2
joshmac
Junior Poster in Training
72 posts since Apr 2008
Reputation Points: 16
Solved Threads: 4
 

INSERT INTO `chm_permissions` VALUES(00000000000000000002, 'create_groups', 'Cre...

You haven't included that line for us to check.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Have you tried inserting without the key ? It is auto increment, no need to specify it.

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

@pritaeas, I've tried it with and without it.

@ardav, sorry. Here is line 2

INSERT INTO `{dbprefix}permissions` VALUES(00000000000000000002, 'create_groups', 'Create Groups');
joshmac
Junior Poster in Training
72 posts since Apr 2008
Reputation Points: 16
Solved Threads: 4
 

Pretty sure you need single quotes wrapped around all of your INSERT Values.

stoopkid
Junior Poster in Training
88 posts since Sep 2011
Reputation Points: 17
Solved Threads: 14
 

@stoopkid, yes tried that but get the same error.

joshmac
Junior Poster in Training
72 posts since Apr 2008
Reputation Points: 16
Solved Threads: 4
 

I can't see anything majorly wrong with this, other than the first value - why do you need all the leading 0s? The 0s are meaningless in an INT type field. Use NULL if it is an autoincrement? *I think*

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

@ardav, I shouldn't need to manually. From what I understand from the docs, MySQL should pad it automatically with "unsigned zerofill" but taking out the zeros doesn't work as well. But maybe I will try just using int and see if it will work with "unsigned zerofill".

joshmac
Junior Poster in Training
72 posts since Apr 2008
Reputation Points: 16
Solved Threads: 4
 

Use NULL for the incremeter is what I meant:

INSERT INTO `{dbprefix}permissions` VALUES(NULL, 'delete_groups', 'Delete Groups');
diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Ah, I see. That seems like it should work. I will try that out and return with my finding.

joshmac
Junior Poster in Training
72 posts since Apr 2008
Reputation Points: 16
Solved Threads: 4
 

@ardav, unfortunately that doesn't work either. I also tried changing bigint to int and that doesn't work either.

joshmac
Junior Poster in Training
72 posts since Apr 2008
Reputation Points: 16
Solved Threads: 4
 
INSERT INTO `{dbprefix}permissions` (`permKey`, `permName`) VALUES ('delete_groups', 'Delete Groups');
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

ugh, so frustrating. That didn't work either. I might have to thing of an alternative solution of doing this.

joshmac
Junior Poster in Training
72 posts since Apr 2008
Reputation Points: 16
Solved Threads: 4
 

OK think I spotted it - your variable is not a variable:

INSERT INTO `{dbprefix}permissions` (`permKey`, `permName`) VALUES ('delete_groups', 'Delete Groups');


should be

INSERT INTO `{$dbprefix}permissions` (`permKey`, `permName`) VALUES ('delete_groups', 'Delete Groups');
diafol
Rhod Gilbert Fan (ardav)
Moderator
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

@ardav, I wish that was the issue but {dbprefix} is not a variable. It is a shortcode that is read by the php wizard to replace the prefix with whatever the user enters on the installation screen. This works and the prefix is being created. All other inserts work, it is the inserts with long strings that don't work. and even when I try inserting without the ID as you and @pritaeas have mentioned. It still doesn't work.

I think it is one of those times where I need to just step back for a while and come back to it with fresh eyes. I am missing something, but I just can't put my finger on it.

joshmac
Junior Poster in Training
72 posts since Apr 2008
Reputation Points: 16
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: