tcorbeil Posted March 29, 2007 Share Posted March 29, 2007 I am able to create a table in mySQL with: mysql_query("CREATE TABLE $Subpage( submitdate DATE NOT NULL, PRIMARY KEY(submitdate), Page TEXT, weblink TEXT, rss TEXT, name VARCHAR(50), email VARCHAR(50))")or die("Create table Error: ".mysql_error()); but when I enter data into it using: $query = "INSERT INTO $filename VALUES ('$submitdate','$Page','$weblink','$rss', '$name', '$email')"; it seems the table only accepts 1 entry.. so the insert into works once, then doesn't work at all.. any ideas? T. Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/ Share on other sites More sharing options...
spamoom Posted March 29, 2007 Share Posted March 29, 2007 first of all, i would reccomend adding {} to your variables $query = "INSERT INTO $filename VALUES ('{$submitdate}','{$Page}','{$weblink}','{$rss}', '{$name}', '{$email}')"; Also, I would say you should add a column with an auto increment to avoid conflicts and other problems SpaM! Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217482 Share on other sites More sharing options...
MadTechie Posted March 29, 2007 Share Posted March 29, 2007 your only updating $filename $query = "INSERT INTO $filename VALUES ('$submitdate','$Page','$weblink','$rss', '$name', '$email')"; try $query = "INSERT INTO 'submitdate','Page','weblink','rss', 'name', 'email' VALUES ('$submitdate','$Page','$weblink','$rss', '$name', '$email')"; Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217484 Share on other sites More sharing options...
spamoom Posted March 29, 2007 Share Posted March 29, 2007 errr... I thought the $filename was the table... $query = "INSERT INTO 'submitdate','Page','weblink','rss', 'name', 'email' VALUES ('$submitdate','$Page','$weblink','$rss', '$name', '$email')"; That wont work cause you arn't specifying a table Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217486 Share on other sites More sharing options...
tcorbeil Posted March 29, 2007 Author Share Posted March 29, 2007 Thanks spamoom. I use the exact script to load into a table I created in PHPadmin.. when i try to upload into that table, it works no problem.. i only doesn't work on tables that have been created by my code in php.. There must be something different between the table I created manually and that of the table that is created by code.. I just can't figure it out.. I wish I could see the code that was used by PHPadmin to create the table I created manually... Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217487 Share on other sites More sharing options...
per1os Posted March 29, 2007 Share Posted March 29, 2007 I would like to contradict spam and state the the {} inside the quotes tend to be less efficient. The way you had it is perfectly fine. As for the auto_increment value, that is true, try using this for your table structure: mysql_query("CREATE TABLE $Subpage( submitid int(11) NOT NULL auto_increment, submitdate DATE NOT NULL, Page TEXT, weblink TEXT, rss TEXT, name VARCHAR(50), email VARCHAR(50), PRIMARY KEY(submitid))")or die("Create table Error: ".mysql_error()); And change your insert to this: $query = "INSERT INTO $Subpage (`submitdate`, `page`, `weblink`,`rss`,`name`,`email`) VALUES ('$submitdate','$Page','$weblink','$rss', '$name', '$email')"; It is generally a good idea to define the columns so you know that the data is going in right. Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217490 Share on other sites More sharing options...
MadTechie Posted March 29, 2007 Share Posted March 29, 2007 ROFL i messed up frost110 example was what i ment.. Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217491 Share on other sites More sharing options...
spamoom Posted March 29, 2007 Share Posted March 29, 2007 Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217493 Share on other sites More sharing options...
rcorlew Posted March 29, 2007 Share Posted March 29, 2007 You should alwasys set up an auto incrementing id that is tintnt, always, it will make selecting rows faster and avoid all the headaches of typing later. for example: select * FROM tablename WHERE id = '$id' rather than select * from tablename WHERE blogtext = '$blogtext' Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217494 Share on other sites More sharing options...
per1os Posted March 29, 2007 Share Posted March 29, 2007 I do not know about tinyint, as that only goes so far and depending on the size of the database. I generally use Int(11) because that allows for plenty of records and I never had a problem with speed or having to change the int column due to size. But to each their own =) Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217497 Share on other sites More sharing options...
tcorbeil Posted March 29, 2007 Author Share Posted March 29, 2007 Thanks for all your help fellas! It is working like a charm! What would I do without you's! T. Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217501 Share on other sites More sharing options...
spamoom Posted March 29, 2007 Share Posted March 29, 2007 Make sure you mark the topic as "Topic solved"... Tis the button on the bottom left of the page Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217503 Share on other sites More sharing options...
Barand Posted March 29, 2007 Share Posted March 29, 2007 You should alwasys set up an auto incrementing id that is tintnt, always, it will make selecting rows faster and avoid all the headaches of typing later. Fine, if you never need more than 127 records, but when you're dealing with tables containing millions of records then tinyint isn't going to cut it. Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217685 Share on other sites More sharing options...
rcorlew Posted March 30, 2007 Share Posted March 30, 2007 I have always used tinyint simply for that reason, I generally on have 50-60 records, however I do have some with 30,000 records running int. I suppose I should have been more specific. But I am glad to see it is working. Quote Link to comment https://forums.phpfreaks.com/topic/44791-php-create-table/#findComment-217918 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.