Jump to content

Please could some check create/Insert code before I cry


Scooby-Doo

Recommended Posts

Hi Everyone

I am new around here so be gentle, as I think on this project I will be around for quite sometime

 

Im new to php sql and been reading Larry Ullman PHP, now my problem is I just downloaded a snippet of code and I cannot see the fault with creating/inserting a table into my DB

 

$query =
CREATE TABLE category ( cat_id int(2) NOT NULL auto_increment, category varchar(25) NOT NULL default '', PRIMARY KEY (cat_id) ) TYPE=MyISAM; 
INSERT INTO category VALUES (1, 'Fruits'); INSERT INTO category VALUES (2, 'Colors'); INSERT INTO category VALUES (3, 'Games'); INSERT INTO category VALUES (4, 'Vehicles');
CREATE TABLE subcategory ( cat_id int(2) NOT NULL default '0', subcategory varchar(25) NOT NULL default '' ) TYPE=MyISAM; 
INSERT INTO subcategory VALUES (1, 'Mango'); INSERT INTO subcategory VALUES (1, 'Banana'); INSERT INTO subcategory VALUES (1, 'Orange'); INSERT INTO subcategory VALUES (1, 'Apple'); INSERT INTO subcategory VALUES (2, 'Red'); INSERT INTO subcategory VALUES (2, 'Blue'); INSERT INTO subcategory VALUES (2, 'Green'); INSERT INTO subcategory VALUES (2, 'Yellow'); INSERT INTO subcategory VALUES (3, 'Cricket'); INSERT INTO subcategory VALUES (3, 'Football'); INSERT INTO subcategory VALUES (3, 'Baseball'); INSERT INTO subcategory VALUES (3, 'Tennis'); INSERT INTO subcategory VALUES (4, 'Cars'); INSERT INTO subcategory VALUES (4, 'Trucks'); INSERT INTO subcategory VALUES (4, 'Blkes'); INSERT INTO subcategory VALUES (4, 'Train'); 

 

I have tried everything and they all seem to put errors up, I know there is a schoolboy, learning curve error somewhere but where?

 

Thanks for any help in advance

 

Link to comment
Share on other sites

You cannot execute multiple query statements in one mysql_query statement. Are you sure you weren't supposed to copy/paste that directly into your favorite database management tool instead of running it through a php script?

 

In order to run multiple query statements through a php script, you will need to run them individually.

Link to comment
Share on other sites

And what are those errors?

 

I have just tried

$query = CREATE TABLE category ( cat_id INT(2) NOT NULL AUTO_INCREMENT, category VARCHAR(25) NOT NULL default '', PRIMARY KEY (cat_id)) TYPE=MyISAM; 

and still got this error

 

unexpected T_STRING in C:\xampp\htdocs\

 

Link to comment
Share on other sites

I dont know if this is right or wrong..I went into myphpadmin sql and dumped each one individually, at first it gave me an error about MyIsam...removed that and everything is ok...Is Myisam important or is it an old version of xammp that causing the problem

 

Thanks

Link to comment
Share on other sites

Well I don't mean the whole page, I meant the relevant section, but I said the wrong thing :)

 

I'm wondering what the errors are.

I figured as much -- but I've seen 80kb attachements recently.

 

As mentioned above, that string isn't quoted at 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.