Welcome, Guest

Please login or register

TUTORIALS SUBMENU

PHOTOSHOP    FLASH    ILLUSTRATOR    BLENDER    CINEMA 4D    WEB-CODING    [SUBMIT]

Related Links

MySQL Database Integration

pages (2): 1 [2]


Inserting data
Inserting data is much more simple than selecting it, because you don’t need to use as many variables.  In fact, you just need to use one line of code (pretty much) and for this we use the mySQL command:

INSERT INTO TableName(Column1,Column2,Column3) VALUES(‘data1’,’data2’,’data3’)

This may look advanced but its actually extremely simple!   TableName obviously represents the name of the table you want to fill with the new data. Column1, Column2 and Column3 are just there as examples, and you can  you replace them with the name of the columns in your table at leisure.  Remember that if you don’t include a column, mySQL just leaves that cell blank on the new entry.   The values part of the above command includes the data. “data1” goes into “Column1”, “data2” into “Column2”, etc.

So let’s put this into PHP. We are just going to insert one string of data into our one column, bringing us up to a total of 5 rows.

<?
mysql_connect(“localhost”,”joeblog”,”opensesame”) or die(mysql_error());
mysql_select_db(“joes_database”);
$ourdata = “the data we are going to put into the database”;
mysql_query(“INSERT INTO JoeBlog (Joe) VALUES(‘$ourdata’)”) or die(mysql_error());

echo ‘If mysql_error() didn’t spit anything at you and you are reading this message then the insert worked fine!’;
?>

Now we get on to the easy commands...

Deleting and Editing data
There really isn’t much explaining to do on the subject of these two - they are just the same as INSERT, except with a different command:

UPDATE TableName SET ColumnName = Value WHERE Row = id

E.g. UPDATE JoeBlog SET Joe = ‘the data we are going to put into the database but its now edited’ WHERE id = 5

Our table doesn’t have an ID field but we’re going to pretend it does (you can, in fact, use any field you like). ID fields just give each row a unique ID number, which are quite often automatically incremented.  They sometimes make database structures a little easier for humans to comprehend, and ensures that the data in only ONE column is updated by the UPDATE command.

I’ll tie the example in with the DELETE command’s example. Delete has the format:

DELETE FROM TableName WHERE id = Value

E.g. DELETE FROM JoeBlog WHERE id = 5

The two examples above effectively edit the values we entered into our database earlier, and then delete it. Here's the combined PHP code for these operations:

<?
mysql_connect(“localhost”,”joeblog”,”opensesame”) or die(mysql_error());
mysql_select_db(“joes_database”);

mysql_query(“UPDATE JoeBlog SET Joe = ‘the data we are going to put into the database but its now edited’ WHERE id = 5”) or die(mysql_error());

echo ‘If you are reading this then the data has been successfully edited. Remember that our id field is imaginary at the moment but when you make your own table you will include the id field.’;

mysql_query(“DELETE FROM JoeBlog WHERE id = 5”) or die(mysql_error));
echo ‘If you are reading this then the data has been successfully deleted.’;
?>

Well, that's it for my introduction to mySQL/PHP.  This tutorial was not aimed to inform you on how to set up mySQL tables (that may come at a later stage), but simply explain how to use them.  Given the ease of setting up databases, though, a tutorial on the absolute basics would be like teaching your granny to suck eggs.

If you have any questions regarding this tutorial (written exclusively for BioRUST) then please contact me on the forums by clicking on my name below and following the links to either Private Message or Email (you may have to register).  Bye for now!

- Tutorial written by Scrowler

Pages (2): <Prev 1 [2]
Automatic Translations: Translate Into French Translate Into German Translate Into Italian Translate Into Spanish Translate Into Portuguese

Last 5 User Comments


There are no comments for this tutorial yet.
You can place a comment by clicking here.
Amazing Font Pack!

Featured Tutorialsmore

Turbulent Water
Turbulent Water
- Adobe Photoshop -
Diamond Plate Metal
Diamond Plate Metal
- Adobe Photoshop -
LCD Interfaces
LCD Interfaces
- Adobe Photoshop -
Fixing the PNG Col...
Fixing the PNG Col...
- Adobe Photoshop -
Membership

Username:
Password:  
Remember Me

Lost Password? || Register

Related Links



Special Options
Printer Friendly Version
Forum Threads

 Deactivate Account
Author: jerinian
Posted: Oct 02nd, 11:16am
Activity: 1 replies, 887 views
 changes....
Author: supertackyman
Posted: Sep 12th, 2:56am
Activity: 2 replies, 1052 views
Back again and with free webhosting :)
Author: ngz
Posted: Aug 14th, 3:50pm
Activity: 0 replies, 1054 views
Cartoon Crab 6 Legs Walk Run created in Blender
Author: patricia3d
Posted: Jun 19th, 12:58pm
Activity: 0 replies, 1935 views
HTML Form Post Array to PHP
Author: Space Cowboy
Posted: May 25th, 2:18pm
Activity: 0 replies, 1832 views
My blog where i create Digi Scrapbook
Author: claudya07
Posted: May 11th, 2:33pm
Activity: 0 replies, 14441 views
Blood Dripping from Letters
Author: patricia3d
Posted: Apr 05th, 3:37am
Activity: 0 replies, 2751 views
A New Designer has joined the ranks
Author: skates1
Posted: Mar 28th, 2:19pm
Activity: 2 replies, 2772 views
The hole in Photoshop
Author: Mars
Posted: Feb 13th, 9:28pm
Activity: 2 replies, 3439 views
Colour Swatch
Author: ebz7350
Posted: Jan 15th, 11:18am
Activity: 0 replies, 2356 views
 BioRUST Forums - Reply to Topic
Author: inonShozy
Posted: Jan 11th, 11:32am
Activity: 8 replies, 2499 views
 Version 2 of my portfolio site.
Author: andrewnleon
Posted: Jan 08th, 6:18am
Activity: 6 replies, 2798 views
Forum Threads

--- Site Resources ---
Total Tutorials:212
Total Downloads:    441
Total Fonts:    4673