Honesty Rocks! truth rules.

Mysql Error

HOME      >>       Programming


ok i need some more help from the wonderful coders here at Trap. I'm almost done with my CMS script, but i'm having a problem with the installer.php file, when it trys to inseret the user data into the database i keep getting the following error:

mySQL Error: 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 `members` (`id`, `name`, `username`, `password`, `email`, `title`) ' at line 1

the code that is being excuted by the php file is this:

$SQL = get_sql(); foreach( $SQL as $q ) { if ( preg_match("/CREATE TABLE (\S+) \(/", $q, $match) ) { if ($match[1]) { $the_query = "DROP TABLE if exists ".$match[1]; if (! mysql_query($the_query, $connect_id) ) { install_error("mySQL Error: ".mysql_error()); } } } if ( ! mysql_query($q, $connect_id) ) { install_error("mySQL Error: ".mysql_error()."<br /><b>Query:</b>".$q); } } // Insert the admin... $passy = $VARS['adminpassword']; $username = $VARS['username']; $email2 = $VARS['email']; $adminname2 = $VARS['adminname']; $query .= "INSERT INTO `members` (`id`, `name`, `username`, `password`, `email`, `title`) VALUES ('1', '$adminname2', '$username', '$passy', '$email2', 'Administrator');"; $query .= "INSERT INTO `members` (`id`, `name`, `username`, `password`, `email`, `title`) VALUES ('2', 'John Smith', 'username', 'password', 'email@domain.net', 'Tech Support');"; if ( ! mysql_query($query, $connect_id) ) { install_error("mySQL Error: ".mysql_error()); }

for some reason i cant see the error in there, knowing me it's probley something simple and easy to fix and i'm just over looking it. so if i could get some help that would be great.



I didn't use CMS before but as my php and sql knowledge,


Can you write the structure of the table members. Maybe the fields `id`, `name`, `username`, `password`, `email`, `title` are not exist.


And also can you write the line 1 from the beginning to the character ';' .


Then maybe I can tell a definite solution.


run the queries individually using phpmyadmin to see if they work outside of the script.I am suspicious about the single quotes and semi-colons at the end of the Insert lines???


i did that to start out with, what i did was i went in to my phpmyadmin add the table and the fields manualy then i add the user william with all the right info and when it added it it showed me a box that had the queire in it and i clicked on get php code and i copyed and paseted that into my script. so i dont know what was wrong with it, but i was able to fix it by moving the second part:

INSERT INTO `members` (`id`, `name`, `username`, `password`, `email`, `title`) VALUES ('2', 'John Smith', 'username', 'password', 'email@domain.net', 'Tech Support');

into the get_sql fuction in the script and it worked fine. so i'm not sure why it would not take it the way i had it. but oh well at least i got it fix.