Jump to content

Is this valid query via php?


rofl90

Recommended Posts

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

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');
";

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` = #;

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.

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.