rofl90 Posted March 8, 2008 Share Posted March 8, 2008 Ok so I have this query to create a user via 3 inputs username, password, and slogan, I won't show all the code to keep it simple if I can, but heres the query, when I click add user, (submitting the form) it just looks like it refreshes, heres the query: $query = "CREATE TABLE IF NOT EXISTS `$username` ( `name` text NOT NULL, `title` text NOT NULL, `about` text NOT NULL, `phone` text NOT NULL, `email` text NOT NULL, `skype` text NOT NULL, `aim` text NOT NULL, `world` text NOT NULL, `house` text NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; INSERT INTO `$username` (`name`, `title`, `about`, `phone`, `email`, `skype`, `aim`, `world`, `house`) VALUES ('Some name', 'Some title', 'About blablablablaablbalabala', '555.555.5555', '[email protected]', 'something', 'someone', 'somewhere', 'someplace'); INSERT INTO `users` (`user`, `password`, `online`, `banned`, `slogan`) VALUES ('$username', '$password', '0', '0', '$slogan'); "; Link to comment https://forums.phpfreaks.com/topic/94994-is-this-valid-query-via-php/ Share on other sites More sharing options...
spikeon Posted March 8, 2008 Share Posted March 8, 2008 i don't know, but when you run the query, add a "or die(mysql_error());" to the end, and it'll tell you Link to comment https://forums.phpfreaks.com/topic/94994-is-this-valid-query-via-php/#findComment-486620 Share on other sites More sharing options...
rofl90 Posted March 8, 2008 Author Share Posted March 8, 2008 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 Willaaay (name, title, about, phone, email, skype, aim, world, house' at line 14: $query = "CREATE TABLE IF NOT EXISTS $username ( name text NOT NULL, title text NOT NULL, about text NOT NULL, phone text NOT NULL, email text NOT NULL, skype text NOT NULL, aim text NOT NULL, world text NOT NULL, house text NOT NULL) ENGINE=MyISAM INSERT INTO $username (name, title, about, phone, email, skype, aim, world, house) VALUES ('Some name', 'Some title', 'About blablablablaablbalabala', '555.555.5555', '[email protected]', 'something', 'someone', 'somewhere', 'someplace'); INSERT INTO users (user, password, online, banned, slogan) VALUES ('$username', '$password', '0', '0', '$slogan'); "; Link to comment https://forums.phpfreaks.com/topic/94994-is-this-valid-query-via-php/#findComment-486629 Share on other sites More sharing options...
Barand Posted March 8, 2008 Share Posted March 8, 2008 You can't have multiple queries in a mysql_query(). You need three separate calls to mysql_query() BTW, I'd add a primary key to your table. Link to comment https://forums.phpfreaks.com/topic/94994-is-this-valid-query-via-php/#findComment-486632 Share on other sites More sharing options...
awpti Posted March 8, 2008 Share Posted March 8, 2008 Why in the bloody hell are you creating a table for each user? I boggle at the logic. Please explain. Link to comment https://forums.phpfreaks.com/topic/94994-is-this-valid-query-via-php/#findComment-486648 Share on other sites More sharing options...
rofl90 Posted March 8, 2008 Author Share Posted March 8, 2008 I only have 2 users so it makes it a bit easier, but idk Link to comment https://forums.phpfreaks.com/topic/94994-is-this-valid-query-via-php/#findComment-486671 Share on other sites More sharing options...
ohdang888 Posted March 8, 2008 Share Posted March 8, 2008 ya. stop that now. learn the right way, or i promise you you will be kicking yourself later. Link to comment https://forums.phpfreaks.com/topic/94994-is-this-valid-query-via-php/#findComment-486673 Share on other sites More sharing options...
awpti Posted March 8, 2008 Share Posted March 8, 2008 That definitely doesn't make it easier. CREATE TABLE Users ( `id` int not null primary key auto_increment, `username` varchar(32), `password` char(40), ); CREATE TABLE User_Profiles ( `id` int not null primary key auto_increment, `user_id` int, ..... ); Try that. SELECT * FROM `Users` LEFT JOIN `User_Profiles` ON `User_Profiles`.`user_id` = `Users`.`id` WHERE `Users`.`id` = #; Link to comment https://forums.phpfreaks.com/topic/94994-is-this-valid-query-via-php/#findComment-486674 Share on other sites More sharing options...
ohdang888 Posted March 8, 2008 Share Posted March 8, 2008 That definitely doesn't make it easier. CREATE TABLE Users ( `id` int not null primary key auto_increment, `username` varchar(32), `password` char(40), ); CREATE TABLE User_Profiles ( `id` int not null primary key auto_increment, `user_id` int, ..... ); make the auto_incrememt `id` in user_profiles as the user id. Thats why i do, and its works fine. Link to comment https://forums.phpfreaks.com/topic/94994-is-this-valid-query-via-php/#findComment-486676 Share on other sites More sharing options...
rofl90 Posted March 8, 2008 Author Share Posted March 8, 2008 My system works right now, and i can add and delete users succesfully so itmt i'm good, but when I do a restructure maybe I will od it 'the right way'. Thanks for the help it all worked out also, and I will be making some donations, I've recieved so much great help over the past week within mere minutes!! Thankyou so much all! Link to comment https://forums.phpfreaks.com/topic/94994-is-this-valid-query-via-php/#findComment-486720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.