Nov 21, 2009

Create Table - Mysql Code - Help

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > PHP Programming

Create Table - Mysql Code - Help

alex1985
I need your feedback about setting the database issues. Please, review them and correct some entries in the code if they got some mistakes.

This is the code itself:

SQL
CREATE TABLE `news` (
`id` int(250) NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`text` text NOT NULL,
`author` varchar(255) NOT NULL default '',
`valid` varchar(255) NOT NULL default '',
`date` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM ;

Comment/Reply (w/o sign-up)

Erdemir
QUOTE(alex1985 @ Jun 11 2008, 05:34 PM) *
SQL
CREATE TABLE `news` (
`id` int(250) NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`text` text NOT NULL,
`author` varchar(255) NOT NULL default '',
`valid` varchar(255) NOT NULL default '',
`date` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM ;


Length of title is 255. This is too small length. Maybe title can exceed 255. I know maximum length of varchar is 255. So we shouldn't use varchar. Instead we can use TEXT or LONGTEXT.

Selecting text for the coulomb `text` is a good choice wink.gif

You shouldn't save date into strings so don't use varchar. Instead you can use int(16) and call it and save it by time() function. Analyze other scripts and you will see, using int for date and saving it by time() function is the best way to control the date.
//By the way time() function gives you the seconds from the 1/1/1970. How to use: <? echo( date("d.m.Y G:i:s ",$row['date']) ); ?>
But if you are already using time() function, again use int instead varchar, because if you are using varchar and if you want to sort by date the rows will be sorted as strings in the date coulomb but if you are using int when you sort by date the rows will be sorted as integer so sorted as date wink.gif

I know it is not important but the length of id is to large, 250 means the length is 250. If I were you 15 would be enough.

My suggestion is:
SQL
CREATE TABLE `news` (
`id` int(15) NOT NULL auto_increment,
`title` text NOT NULL default '',
`text` text NOT NULL,
`author` text NOT NULL default '',
`valid` text NOT NULL default '',
`date` int(16) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM ;

 

 

 


Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : create, table, mysql, code,

  1. Php Code For Login Form With Validation In Php
    (7)
  2. Mysql Error
    (3)
    ok i need some more help from the wonderful coders here at Trap. I'm almost done with my CMS
    script, but i'm having a problem with the installer.php file, when it trys to inseret the user
    data into the database i keep getting the following error: CODE mySQL Error: 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 `members` (`id`, `name`, `username`, `password`, `email`,
    `title`) ' at line 1 the code that is being excuted by the php file is this: C....
  3. Php Source Code Unveiled In Browser?
    is that possible? (7)
    I am quite new to PHP and this concern came to my mind after playing around a bit with it... When
    PHP is not correctly configured on the web server the source code of a php file we try to access
    through a browser will be shown instead of the result of the code itself. This will normally not
    happen when PHP is working properly, but I was just wondering if it could still be possible to see
    that code if a user wanted to or if something on the server failed. This would for example expose
    sensitive information like mysql passwords and so on... Is anything like that possib....
  4. Html Form!
    Using MySQL?! (4)
    Hey, I need your help again! I need some good working tutorial how I can update my SQL through HTML
    form. I did use some tutorials online found with the help of google; but they do not work properly;
    I mean there are still small mistakes. I need to have a good tutorial to follow. It should be
    based on security and more things. It has to be done in proper way.......
  5. Malicious Code Injection
    (3)
    Hi everyone! This is my first post, so be kind! Basically, I'm trying to get a free host
    together so am writing some posts. Here's a little summin' summin' about malicious code
    injection with PHP applications. Basically, this security exploit is one of the oldest tricks in
    the books and all comes down to the fact that PHP allows execution of both local and remote scripts
    with the SAME function... dur. Anyway, this is how it works. Image you've just employed a young
    go getter, straight outta uni, who has found becoming a Jack of all trades a sinch. Y....
  6. Best Php And Mysql Editor For Noobs
    anyone any php or mysql editor that is good for noob (11)
    hi there guys, from my previous posting, i am a noob in php and mysql programming. I want to know
    if there are any php and mysql editors which are best for me as a noob. i appreciate your kindness
    ....
  7. Php And Mysql Programming
    anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your help
    guys...I want to make a simple program that will some values and then store them on a database and
    then retrieve them...uhmm let me give an example out put of what i need. This is the example say..:
    Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those are the
    data needed for input values...my question now is how can I make a database whi....
  8. Best Sites For Learning Php-mysql
    (4)
    Hi I was reminded of this earlier by a post in a topic, meant to post it but forgot and the topic on
    php books reminded me. Well anyway there is tyhschools for learning php (unless someone else knows
    a better 1) but I wan't to know what is the best site for using php with mysql (using
    phpmyadmin) also whats the difference between postgresql and mysql? though I must admit the
    postgresql version of phpmyadmin whatever it's called looks better (visually)!....
  9. Tools Needed!
    PHP & MySQL (9)
    Hello, everyone! I need some tools for those two things to test PHP scripts coming together with
    database on my laptop, instead checking them on a web-server which takes time.....
  10. Php Code Needed Iii
    (10)
    Hello, everyone. I need your help again! Who might create the PHP code, the picture is above
    this text. Basically, I want when the user fill in all the information in this form, it
    automatically was sent to my email. And, then, the dialog box appears or on the same window, it was
    said that your request has been sent. Moreover, if the user did not fill the entire information,
    the dialog box appears stating that you did not fill some field. Thanks, for help. You always do
    that.....
  11. Php Code?
    Mathematical Applications (12)
    Hello, everyone. The help is needed again. How can I make calculator in PHP language? That will act
    like that a user just type in the fields known values, then click the button, and it's going to
    be solved automatically. In other words, have can I write a formula in PHP, how to plug it inside
    that language. For example, the formula to find a peremeter of square is: P=4a. So, a user
    just can write the known value which is peremeter itself and it will find the side of a square; and
    vice versa. If you can write many things how to do such formulas, such as comp....
  12. Php Code Needed
    Working Together? (5)
    Hello, everyone. I need your help again. This forum is quite good for it. Well, I need create a
    registration form for my web-site using PHP and SQL. The information it should contain: 1) User
    Name 2) First Name 3) Last Name 4) Password 5) e-mail Address 6) Security Image: that images helps
    to protect a random registration, for instance, 56+2=where user have to type an answer in order to
    finish registration. That's all for today. Anymore things, I will post another post over here.
    ....
  13. Mysql Won't Update
    (5)
    Ok, so I'm making some arcade administration software so I don't have to add games the hard
    way, well anyway, one of the features I have is that on the homepage is a featured author and as
    such I just have it so it updates one line in the mySQL. Well, the page with the form passes on the
    varibles fine and the updating page recieves them because I echoed everything, then I build the
    query and I even echo the query and it comes out exactly how I want it to, but for some reason, the
    database itself won't update even though all the varibles are there. Here's....
  14. Html Code Tester. Online Script
    (15)
    Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
    this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
    Current script: CODE //Save this as something like htmltest.php function CheckForm() {
    $html_unsafe=$_POST ; //Gives us our user input $html_safe=str_replace(" //Starts security measures
    $html_safe=str_replace("?>"," ",$html_safe); //User input now secure server side //Still security
    issues client side echo $html_safe; //echos our statement } //End function //Main script....
  15. Display The Current Date/time
    With a simple PHP code (4)
    Use this code to display the current date and time. CODE   $date = date('l dS \of F Y
    h:i:s A');   echo "$date"; ?> "l" would display the current day of the week such as
    Sunday. d displays the day of the month... such as 1 and S adds the appropriate suffix(st). /of
    simply displays the word "of". F displays the current month with no abbreviations while Y displays
    the four digit year(2007). "h" displays the current hour with leading zeros if necessary(Ex. 06 for
    6 o'clock). "i" displays the minute of the hour with leading zeros if necessary. ....
  16. Wap Source Code Viewer
    Mobile/wap source code viewer page (4)
    This is a source code viewer that will workl on wap/mobile sites but you can easily convert it to
    work on web im sure ;-) CODE header("Content-Type: text/vnd.wap.wml"); echo '
    ';   print " "; if ($url == "") {      echo " Enter url: »View source code ";   }
    if ($url == "$url") {    $udata=@file_get_contents("$url"); $udata = str_replace("$","$$",$udata);
    $udata = str_replace("&","&",$udata); $udata = str_replace("'","'",$udata); $udata =
    str_replace(" $udata = str_replace(">",">",$udata); $udata = str_replace("\"....
  17. Phpmyadmin And Php And Mysql
    tutorial (1)
    hi i think phpmyadmin is nice script (3rdparti) to learn php and mysql , you can add database and
    then make tabel with rows and columns then you can customise (search , show rows , show columns ,
    add rows , delete rows) tabel in phpmyadmin when you are customise phpmyadmin , this script show you
    php code . you can use this code for browse in database . for example : showing tabel : CODE
    SELECT * FROM `tabelname` LIMIT 0 , 30 searching : CODE SELECT `columns` FROM `tabel` LIMIT
    0 , 30 you can use with while loop showing Ascending: CODE SELECT * FROM....
  18. Creating Profiles In Php/mysql ?
    (7)
    i've started to learn php..im familiar to basics of php and mysql now.Now for example i want
    that some user can register to my website , and after that he can Login and log out , and he can see
    his profile.is there any tutorial about this ? or any helping url .. or any helping answer please
    /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
  19. Requesting Auto Generating Id Tag In Php Code
    Php Coding (3)
    Hello...I'm designing a website in PHP where ppl can submit their links for "cool sites".
    Anyway, when somebody submit's a link to a website for example "http://www.google.com" it
    creates an id such as "index.php?id=1134411593". I dont want the links to be converted into
    id's. I want it to remain as "http://www.google.com". I have the following coding on
    ( echo " ). I'm a novice. Please Help!!!! Thanks... Plus I
    also want to add the date on when the link was submitted. Please follow our forum rule by making....
  20. Adapting Html Code Embed To Work On Phpnuke
    Help With This Html Code Pls (7)
    QUOTE how can get this html code to work on my phpnuke site? what tags would i
    have to enable in the $Allowable HTML part of my config.php file?? Edited topic title. Moved to
    Programming. ....
  21. Subquery In Mysql
    (8)
    Is there anyway to make subqueries work in MySQL? I'm pretty certain someone out there knows
    how. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Can anyone help?
    CODE Select * from ITEMS where ID="Select Max(ID) from ORDERS"; This works for MSAccess and
    SQL Server but why not in MySQL? I'll be writing some reports and I've shifted database
    from MSAccess to MySQL. Help! Thanks.....
  22. Can You Add Images Into A Mysql Database?
    Using Php? (23)
    I'm learning php in class right now, but I'm still not that good at it, what I'm
    wondering is when I write the php so that it can connect with a database, can I at the same time
    have it that it is able to display back images that I choose. Like, I want a search feature, where
    you can search for a keyword, and it will bring back a list of all the possible entries with that
    keyword, but each of these entries will have a photo associated with it. Now, do I put these image
    files directly into the database, or do I write the code to link them from my files to th....
  23. Increment A Mysql Column
    how to increment a MySQL column one unit (8)
    Hi, I have a column in a MySQL table which contains a counter of the views of the object described
    by this table. I would like to increment this value by one everytime the object is viewed. Obviously
    came into my mind the possibility of retrieving the value of this field, store it in a variable
    increment this value by one and perform an UPDATE query again with this new value. My question is if
    there is a MySQL option to update the field with its actual value plus an unit increment. I hope you
    understand the issue.....
  24. Php News Script
    how to make news script that uses MySQL writen in PHP (20)
    How to make a News script with PHP + MySQL So..in this tutorial i will explain how to create PHP
    news script. first we have to create the table in My SQL.. with the code below you will do this (
    you have to enter it into SQL field ..in PHPmyADMIN) CODE CREATE TABLE news ( id int(10)
    unsigned NOT NULL auto_increment, postdate timestamp(14) NOT NULL, title varchar(50) NOT NULL
    default '', content text NOT NULL, PRIMARY KEY (id), KEY postdate (postdate), FULLTEXT KEY
    content (content) ) >>>> script files 1 file will show the news ,1 file will....
  25. Get Filename Of Referring Url
    php code to get filename of referring URL (9)
    Hey /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> I want to know how
    to get the filename of the referring URL. Look at the following example: Page A which has a URL of
    http://blah.trap17.com/blah/blah1.php redirects the user to Page B which has a URL of
    http://blah.trap17.com/blah/blah2.php . Is there a PHP code that I can put on blah2.php that will
    output blah1.php? I tried _SERVER ; (please note the code may not exactly be correct as I do not
    remember the code /laugh.gif' border='0' style='vertical-align:middle' alt='laugh.gif' />....
  26. Php Clock
    source Code (8)
    Hi Every one i find this code its very easy simple php clock i think you can use it /blink.gif'
    border='0' style='vertical-align:middle' alt='blink.gif' /> CODE // Binary Clock // script
    copyright© 2002 Andreas Tscharnuter // questions? contact: psychodad@psychodad.at ||
    http://www.psychodad.at/clock/ // free to use, copy and modify but leave comments untouched;) //
    just include this file where your binary clock should appear // version 1.2   03 September 2003 //
    below you can change different settings // and remember to drink m000re milk! $size =  "40";  ....
  27. Problem On Mysql "order By"
    (6)
    Can someone please help...? I have a problem with using "ORDER BY" in mysql... CODE SELECT *
    FROM `foo` WHERE b='abc' ORDER BY 'number' ASC i want to sort the table out by
    the value in "number" which is a number.. but it came out to be sort by like this way...
    1->10->2->20 it only sort out the front digit.... but what i want is it will sort by how great the
    number is like this... 1->2->3........->10....->20 sorry my english isn't good enough...to
    describe my problem properly... hope you can understand and help me on this.....thx....
  28. Mysql Password
    (4)
    Hey guys quick question about trap 17s mysql version. How do i change the password to the database?
    I cant seem to find online help for this version anywhere. Any help is very apperciated!....
  29. Mysql Question:
    (7)
    what do I need to input to create a new user and pass. I've tried before, but it kept giving me
    an error like I wasn't allows to creat users. Please note that this is on my computer. So, I was
    also wondering how to 'log in' to root user so that i can make a new user. Thanks in
    advance.....
  30. How do you test your php code
    (97)
    We know that php is a server side scripting language. So we will need a server with the php parser
    to parse/test our code. How are you doing that. Do you upload it to a server for testing or did you
    instal php and the server (apache) on your computer (localhost)....

    1. Looking for create, table, mysql, code,

Searching Video's for create, table, mysql, code,
See Also,
advertisement


Create Table - Mysql Code - Help

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com