Jul 6, 2008

Getting Started With Mysql - creating tables and insert data into them.

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials

free web hosting

Getting Started With Mysql - creating tables and insert data into them.

flashy
Hi in this tutorial you will learn how to create tables and insert items into them.

First steps are to create the database - go into your cpanel and mysql databases, from there make an account and a database and then attach them together with all priviliges, call the database test and the account admin, with the pw as pass - or any other password.
We need to connect to the database so first in your php file (probably named index.php) - this is how to do it.

CODE
mysql_connect("localhost", "admin", "pass") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

The first line was to connect to the host as LOCALHOST as it is usual the databases locally, the username would be what the username would be (most servers require you to place your CPANEL username as a prefix - like PREFIX_USER, trap17 requires you to do so), and then your password.

The second line was to connect to the database that you created earlier, again you willneed to place in the prefix if you did so for the username.

Now we can start to make a table! We will make a guestbook in this tutorial.

CODE
// connect to the database
mysql_connect("localhost", "admin", "pass") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

//create a table
mysql_query("CREATE TABLE guestbook(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(30),
comment VARCHAR(500))") or die(mysql_error());

The two lines starting from 'id' to '(id)' are the row id's - you'll see what i mean when you go into phpMyAdmin.
VARCHAR means variable characters - so any variable (abc!"£123) can be placed into it, you can use INT for numbers.
the VARCHAR '(30)' means how many characters are stored into this variable.

Now lets go insert some data into the tables
CODE
// connect to the database
mysql_connect("localhost", "admin", "pass") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

// insert into tables
mysql_query("INSERT INTO guestbook(name, comment) VALUES('Jim', 'Hi nice site!')") or die(mysql_error());
mysql_query("INSERT INTO guestbook(name, comment) VALUES('Bob', 'Lovely weather')") or die(mysql_error());

That created two lines of data into 'guestbook', 2 names - Jim and bob, and 2 comments - 'Hi nice site' and 'Lovely weather'

Now lets retrieve the variables in the database - but we must store them as an array and read them as an array
CODE
// connect to the database
mysql_connect("localhost", "admin", "pass") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

$get = mysql_query("SELECT * FROM guestbook") or die(mysql_error());

while($array = mysql_fetch_array($get)){
echo "Name: ".$array['name']."<br />";
echo "Comment:<br />".$array['comment']."<br /><br />";
}

The * after SELECT means ALL - in other words SELECT ALL FROM guestbook.

I hoped i helped getting started!

 

 

 


Reply

shadowx
Nice little tutorial smile.gif It would be good if you continued the series to modify table contents and structure with DELETE, UPDATE, SORT etc...

I always found creating tables using PHP versus PMA really difficult to remember the syntax but in truth there isnt much to it!

Reply

Absolute Zer0
Wow, very well written, I already feel like learning MySQL more!... After I learn PHP... laugh.gif

Reply



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*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. mysql - 88.11 hr back.
  2. mysql create 3d - 119.34 hr back.
  3. insert data multiple tables mysql php form - 226.72 hr back.
  4. how insert excel data into php file. code - 274.35 hr back.
  5. how to save insert data into mysql on submit button - 374.44 hr back.
  6. how to insert values into mysql database using windows forms - 398.21 hr back.
  7. php mysql insert edit delete using classes - 400.56 hr back.
Similar Topics

Keywords : started, mysql, creating, tables, insert, data,

  1. How To: Html Tables.
    I find these really useful. (8)
  2. How To Get Started Fishing: At The Lake
    mainly applies to UK, see the "what you will need" too! (0)
    So you now know what you need to start fishing from my other tutorial, once you have it all it's
    time to head to the lake! As i said pick up the bait on the way, maggots from the tackle shop,
    corn and spam from tescos and bread too if you want (you can eat it too of course!). At the
    lake you can ask those already fishing for their tips but some anglers are liable to lie to keep the
    best spots to themselves. So when you get look for the "swims" These are areas along the bank where
    the bushes have been cleared and sometimes paving slabs have been laid to let ....
  3. How To Get Started Fishing: What You Will Need (uk)
    This applies mainly to the UK but other countries too. What you will n (2)
    Hi folks, with the beginning of spring its time to crack out the coarse fishing rods and land a few
    fish, i was supposed to be fishing today but the weather took a turn for the worse so instead let me
    try to convince a few of you to go fishing and take your kids too! I dont need to explain what
    fishing is, everyone knows that but let me clear up a few misconceptions: 1) Do you eat the fish?
    Or do you kill the fish? Or otherwise remove them from the lake? A) No! There is a nasty habit
    of some eastern Europeans to remove and eat the fish from lakes and that might....
  4. Creating Navigation For Html Websites
    Have a common navigation menu for the whole website! (12)
    Pre-requisite: HTML, inline frame tags 1 Attachment(.zip) included. Updates : 29-12-07: Doctype
    added in example files (Advised by jlhaslip) Designing a whole website takes a lot of planning
    and organization. Designing a proper navigation system is a basic step in building your website. If
    you are developing webpages in html you would have observed that as you go on creating pages it
    becomes difficult to maintain the links to the pages. This article will guide you in developing a
    common navigation menu for your website. It describes three ways, so if you don'....
  5. Creating A Resume
    10 Tips For Making A Resume (1)
    I've been working on my Resume for months now. Here is a summary of what I've learned: 1.
    Avoid referring to yourself via 1st person or 3rd person terms. Rather than saying "I started this
    job in" just say "Began job in"... Employers expect Resumes to be professional and avoid reference
    to oneself; and instead speaking in an impersonal tone that presents
    achievements/skills/experience/education without personalization. Avoid words like "I", "my", "he",
    "she", etc. Leave out personal pronouns and only use the action words/verbs. This also includes
    your Ob....
  6. How To Group Multiple Sets Of Data In Microsoft Excel 2007
    (0)
    How to Group Multiple Sets of Data in Microsoft Excel 2007 Sometimes you may open several
    workbooks and work with a number of the same workbooks at a time. You can open this group of files
    with Microsoft Excel 2007 simultaneously. But you have to define them as part of a workspace, and
    save them in a single Excel 2007 file. To do this, follow below steps: 1- Click On the View tab and
    then in the Window group click Save Workspace. The Save Workspace dialog box appears. 2- In the File
    name field, type your work name and then Click Save. 3- At the top-left of window, C....
  7. Programming In Glut (lesson 4)
    Creating 3D objects (0)
    Lesson 4 of 6. I hope you are enjoying them /laugh.gif" style="vertical-align:middle"
    emoid=":lol:" border="0" alt="laugh.gif" /> . QUOTE Hello, in this tutorial we will be creating
    a 3D pyramid. We are building this tutorial from Lesson 3, but I took out the 2D objects and placed
    a 3D pyramid in there instead. The 3rd axis for drawing can be a litle confusing, but after you get
    the hand of it you'll do fine. Now when you are setting a 3D vertex just remember that the
    camera is on the positive end of the z axis. So things that have a more positive z axis va....
  8. Programming In Glut (lesson 1)
    Creating a windwo (0)
    This is the first of six lessons I am transferring from Astahost for programming in GLUT, and after
    the six I hope to make more, I hope you enjoy. QUOTE Hello, I'm starting a series on how to
    program in OpenGL using the OpenGL Utility Toolkit, a.k.a. GLUT. I chose GLUT because it is quick
    and easy to write, and very easy to learn. In this tutorial I am going to teach you how to create a
    basic window which we will build off of in later tutorials. Throughout the tutorial I will leave
    notes to let you know what each command does, and how you can modify it to fit....
  9. Php Form Data And Conditional Statements
    My third tutorial (2)
    Intro To PHP Tutorial 3 - Form Data and Conditional Statements Released 4/12/07 By Chris Feilbach
    aka GhostRider Contact Info: E-mail: assembler7@gmail.com AIM: emptybinder78 Yahoo:
    drunkonmarshmellows Website: http://www.ghostrider.trap17.com PART I - FORM DATA One of the
    things that makes PHP so popular is its ability to handle form data. You can do whatever you want
    with it, you can email it to yourself, store it in a database, display it on a page, you can do
    literally ANYTHING with it. There are two ways to send data to your server, GET and POST. Both
    are ....
  10. Adding Data To A Database And Displaying It Later
    Using Forms, PHP and MySQL (1)
    Requirements: PHP Support MySQL Database access I am going to use a news program as an example.
    Ok, first you are going to need to connect to the database. Do so by using the code below. I have
    added some comments where you will need to edit to fit your server's specifications. Create a
    new file with notepad and call it config.php QUOTE //Change root to your database
    account's username $dbusername = "root"; //Add your account's password in between the
    quotations $password = " "; //Add the name of the database you are using in betw....
  11. Simple User System
    php, mysql driven (19)
    Hey! Maybe you've seen my other tutorials...or my signature.. Anyways I'm going to show
    you how to make a system so users of your site could register accounts and you could have protected
    - user only - pages on your site /smile.gif" style="vertical-align:middle" emoid=":)" border="0"
    alt="smile.gif" /> Ok, so we start by creating a config.php file. CODE <?php
        $dbhost   = 'database host';     $dbname   = 'database name';
        $dbusername   = 'database username';     $dbuserpass = 'database pas....
  12. Simple Shoutbox
    PHP, MySQL driven.. (34)
    Ok, so I'm going to show you how to create a very basic shoutbox which is driven with PHP and a
    MySQL database. So, lets start - open a database management program like PHPMyAdmin and run these
    queries. SQL CREATE TABLE `shoutbox` ( `id` INT( 11 ) NOT NULL AUTO_INCREMENT
    , `name` VARCHAR( 255 ) NOT NULL , `mail` VARCHAR( 255 ) NOT NULL , `time`
    VARCHAR( 255 ) NOT NULL , `message` TEXT NOT NULL , `ip` VARCHAR( 255 ) NOT NULL ,
    PRIMARY KEY ( `id` ) ) TYPE = MYISAM ; CREATE TABLE `shoutbox_a....
  13. Cpanel Mysql Database Management
    Part 2.1 Of My 7 Part Cpanel Tutorial (6)
    This tutorial is an extension to my 7 tutorial series about the Cpanel. The 7 different Cpanel
    tutorials can be found below. Part 1: E-mail Management Part 2: Useful Site Management Tools
    Part 3: Useful Site Management Tools2.1 Part 4: Analysis/Log Files Part 5: Advanced Tools Part
    6: PreInstalled Scripts, Extras, and Cpanel Options Part 7: Fantastico Detailed Cpanel
    Tutorial Part 2.1: MySQL Management In this tutorial, i will explain how to add, edit, delete
    and over-all manage the MySQL Feature in the Cpanel. Creating a MySQL Database 1) ....
  14. Starting Or Stopping Apache And Mysql Server Via Batch File
    (0)
    Hi guys, this is a litte tutorial about how we start and stop the Apache and MySQL in Windows NT
    (2000, XP, 2003) via a batch file script. As we know in Windows NT based system Apache and MySQL
    installed as Windows Services. So we can stop and start it using NET command. For more information
    about DOS command, type HELP at command prompt. I assuming that your MySQL service name is "mysql"
    and your Apache (Apache 2.0.x) service name is "apache2". If you want to chek it click Start > Run >
    services.msc > OK. Windows IS NOT Case Sensitive. Let's get started!. 1. ....
  15. Check Referrer To Prevent Linking Yours From Other Sites
    Check referrer with Php and Mysql (8)
    Check Referrer Using Php To Prevent People Linking To Your Downloads From Other Sites Ever
    find that found some people are listing items, images and tuts and linking directly to the download
    url (those that are like my photoshop tutorial.php?id=0), which is a .php to count the number of
    downloads. To prevent this, you can add a piece of code to the download pages that checks which page
    referred them to the download page: if it's my domain, it downloads the file normally, if
    it's not, it will redirect to my home page instead. Important : Not all browser....
  16. Tutorial: Creating Custom Icons For Devices
    Give that device a great icon every time you plug it in! (0)
    Ok for this tutorial I will use the PSP as an example of the device, this should work for every
    device. (THIS WILL NOT HARM ANYTHING AT ALL!) First off, open notepad and type in:
    ICON=ICONE.ICO Save that as AUTORUN.inf Now, find a picture you like.. make sure its dimensions
    are 16X16 pixels. Put it in the main folder of the device, for example, my psp is located at
    F:\, i would type in F:\ to the adress bar and put the picture in that folder, as it is
    the folder your computer automatically reads, anyways, put your picture in there and name it: ICO....
  17. How To Create Tables
    (1)
    At the end of this tutorial you should know how to: 1.How to create a database on your sever
    2.How to create tables on a mysql database For a script 3.How to confirm your script so that
    it works with your database TUTORIAL PART 1 How
    do we create a database using the cpanel on a server? Well i'll explain it the best way i can.In
    your cpanel go to yor mysql options.Once in you will easeily see than option to create a database
    and an option to create a user. Frist go to the create database option and t....
  18. Quiz With Php, But Without Mysql
    (3)
    Ok let`s start! Once I wrote it for school: At first we need questions (php) CODE
    $form_block = " <p>Quiz</p> <form method=\"POST\"
    action=\"$_SERVER[PHP_SELF]\">
    <p><strong>What's The Capital City Of England?</strong><br>
    <input type=\"text\" name=\"q1\"
    value=\"$q1\" size=30></p> <p><strong>How Many
    Letters Are There In The Alphabet?</strong>&....
  19. Installing Php + Mysql + Apache + Phpmyadmin On Windows Part 2
    Continue the last section which is installing phpMyadmin (0)
    QUOTE phpMyAdmin lets you control you MySQL database from a web browser. Steps: 1. If you
    haven't done so already, download the phpMyAdmin Database Manager - You can download the
    software from the phpMyAdmin website. Be sure to download the phpMyAdmin-2.6.2-pl1.zip file. Save
    the file on your Windows Desktop. ... ... ... Go to for more info. Post Copied. Member
    Banned ....
  20. Creating A Timer Program
    Using Visual Basic 2005 (8)
    This tutorial will explain how to create a basic timer using Visual Basic Express 2005. If you
    don't have it, it's free and you can dowload it from Microsoft's website. All you need
    is a few minutes to sit down and read this and a version of Visual Basic. OK, so what will this
    timer actually do? Well, you are able to enter a number of minutes and a message, and then click a
    button. Once the timer is up, your message pops up and you are reminded! So, basically it's
    a little reminder system. I use it to remind me when TV programmes start, when I have to....
  21. Creating A Simple Image Viewer
    Using Visual Basic 2005 Express Edition (3)
    I downloaded Microsoft's Visual Studio Express suite a few months ago, but only recently got
    around to installing it. I have been practising with Visual Basic and making some rather basic
    programs and utilities, but they contain most of the basic concepts. This tutorial will explain how
    to create a basic image viewer, and I will try to explain each step from beginning to end as clear
    as I can. To start you will need: Microsoft Visual Studio About 10-20 minutes free time OK,
    first open up the Visual Basic part of the Studio. I am using the 2005 Express version, so....
  22. Searching With Php And Mysql
    The easy way :P (2)
    Searching with PHP and MySQL is pretty easy when you think about it, especially if you're doing
    it the simple way (without boolean or whatever) /tongue.gif' border='0'
    style='vertical-align:middle' alt='tongue.gif' /> It consists of a few forms, a query and an
    output. As I said, simple! CODE <form name=\"form1\"
    id=\"form1\" method=\"post\" action=\"<?
    $php_self ?>\"> <table width=\"100%\"
    border=\"0\" cellspacing=\&#....
  23. Install Php 5 To Work With Mysql
    (0)
    hi, all php 5 is new to all people a long time( actually, I forget how long...). it introduced a
    more object-oriented design to developer. like, access type(public, private, protected), abstract
    type(classes that can't create objects), interface support, and more . althrought it is
    widerly available, someone still can't get it running with mysql. every time the php is starting
    up. a message prompted stated that some xtensions can not be found, and therefore, not loaded. so, I
    have written this to help other and newbie get it start quickly. note: thi....
  24. Getting Started With Amfphp And Rias
    first steps in creating RIAs (0)
    AMFPHP in a short way is a library of php files that let u manage in JUST ONE FILE what u would do
    in many files like for example queries to mysql. So u can have tons of queries to mysql and all of
    them in just ONE FILE! so what is a RIA? a RIA is a Rich Internet Application commonly given
    to flash applications, not the animations or presentations we see daily on the internet but very
    useful and cool programs made in flash. the fisrt step u need to take is to download the AMFPHP
    library directly from its site at www.amfphp.org, in some free hosted sites the latest....
  25. Delete Files And Directories Using Php
    following up from creating and writing (7)
    How To Delete Files and Directories follow up from creating them Hello all and
    welcome to my second tutorial involving file management. In my previous tutorial , I explained how
    to create, write and read files. In this tutorial I'll explain how to remove the files and
    directories you took so long to create. I did not explain last time how to create directories as I
    did not know, now I do, you can use the mkdir() function. Now with this tutorial.... Removing
    Files Removing files can easily be done with the unlink() function: CODE <? un....
  26. Php Dynamic Signatures
    Using the GD Module and MySQL (9)
    PHP Dynamic Signatures using the GD Module After much scowering on the internet to find a
    suitable tutorial on this subject, I came up empty-handed. So I was forced to learn it on my own
    through trial & error. And since I had discovered a lack of tutorials on this subject, I dediced to
    write one! Working Example: Abstract : Using the GD Module of PHP allows a
    developer to build custom Images with Dynamic Content. Such content could be the Requesting Users
    IP Address, Web-Browser Type, Operating System, even the number of times the user has see....
  27. Creating Your Own Icon
    (23)
    It is easy to create your own icon, just pick a bitmap (.bmp) file and change its extension to .ico.
    To do so, open the Windows Explorer, click on the View menu (or Tools in WinMe), click Folder
    Options, click View tab, remove the check on the "Hide file extensions for known files types"
    option, and then click OK. Select a bitmap file, press F2 key, and then change its extension to
    .ico. Have fun learning:)....
  28. Complete Login And Registration System
    doesn't use mysql! (9)
    kLogin 0.1 QUOTE(readme.txt) Readme file to kLogin 0.1 To use the internet explorer fix:
    download the latest IE7 ZIP file
    (http://sourceforge.net/project/showfiles.php?group_id=109983&package_id=119707) Extract the ie7
    zip file to the root directory of your web server. Example, if you are using a unix/linux server,
    it's on "public_html/" or "home/public_html" Open kLogin.php file with your editor and edit the
    $info_text or $info_txt variable. Then, extract the kLogin.php file in to the root
    directory of your web server also. Just run kShoutBo....
  29. A Guide To Css And Creating A Stylesheet
    (15)
    Table of Contents: I. Introduction II. Starting your stylesheet --A. Starting syntax with
    font-family --B. Defining classes --C. Using classes III. The STYLE tag IV. Comments in CSS V. The
    "a" tag VI. A quick list of common attributes VII. Notes --A. Universal classes --B. Grouping --C.
    Multiple instances VIII. Finding other attributes IX. Closing I. Introduction Firstly, to begin
    using a stylesheet, you must have one. Open up your text editor and save as (something).css. I know
    NotePad doesn't need quotes for a stylesheet, but I'm not sure about other progr....
  30. Complete Login System
    With PHP + MYSQL (55)
    Its an complete login sistem made and tested by me and I think itwill be very usefull for people who
    are tryn to learn PHP. First, let's make register.php: CODE <?
    include("conn.php"); // create a file with all the database connections
    if($do_register){ // if the submit button were clicked if((!$name)
    || (!$email) || (!$age) || (!$login) ||
    (!$password) || (!$password2)){ print "You can't let
    any fields in blank....

    1. Looking for started, mysql, creating, tables, insert, data,

Searching Video's for started, mysql, creating, tables, insert, data,
Similar
How To: Html
Tables. - I
find these
really
useful.
How To Get
Started
Fishing: At
The Lake -
mainly
applies to
UK, see the
"what
you will
need"
too!
How To Get
Started
Fishing:
What You
Will Need
(uk) - This
applies
mainly to
the UK but
other
countries
too. What
you will n
Creating
Navigation
For Html
Websites -
Have a
common
navigation
menu for the
whole
website!
Creating A
Resume - 10
Tips For
Making A
Resume
How To Group
Multiple
Sets Of Data
In Microsoft
Excel 2007
Programming
In Glut
(lesson 4) -
Creating 3D
objects
Programming
In Glut
(lesson 1) -
Creating a
windwo
Php Form
Data And
Conditional
Statements -
My third
tutorial
Adding Data
To A
Database And
Displaying
It Later -
Using Forms,
PHP and
MySQL
Simple User
System -
php, mysql
driven
Simple
Shoutbox -
PHP, MySQL
driven..
Cpanel Mysql
Database
Management -
Part 2.1 Of
My 7 Part
Cpanel
Tutorial
Starting Or
Stopping
Apache And
Mysql Server
Via Batch
File
Check
Referrer To
Prevent
Linking
Yours From
Other Sites
- Check
referrer
with Php and
Mysql
Tutorial:
Creating
Custom Icons
For Devices
- Give that
device a
great icon
every time
you plug it
in!
How To
Create
Tables
Quiz With
Php, But
Without
Mysql
Installing
Php + Mysql
+ Apache +
Phpmyadmin
On Windows
Part 2 -
Continue the
last section
which is
installing
phpMyadmin
Creating A
Timer
Program -
Using Visual
Basic 2005
Creating A
Simple Image
Viewer -
Using Visual
Basic 2005
Express
Edition
Searching
With Php And
Mysql - The
easy way :P
Install Php
5 To Work
With Mysql
Getting
Started With
Amfphp And
Rias - first
steps in
creating
RIAs
Delete Files
And
Directories
Using Php -
following up
from
creating and
writing
Php Dynamic
Signatures -
Using the GD
Module and
MySQL
Creating
Your Own
Icon
Complete
Login And
Registration
System -
doesn't
use
mysql!
A Guide To
Css And
Creating A
Stylesheet
Complete
Login System
- With PHP +
MYSQL
advertisement



Getting Started With Mysql - creating tables and insert data into them.



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE