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', 'someone@someone.com', 'something', 'someone', 'somewhere', 'someplace');

INSERT INTO `users` (`user`, `password`, `online`, `banned`, `slogan`) VALUES
('$username', '$password', '0', '0', '$slogan');
";

Link to comment
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', 'someone@someone.com', 'something', 'someone', 'somewhere', 'someplace');

INSERT INTO users (user, password, online, banned, slogan) VALUES
('$username', '$password', '0', '0', '$slogan');
";

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.