Your Ad Here

 Navigation
Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Books
Sample Chapters
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links




 Sponsors
 Links
finance products
gambling sites
golfing products
 Downloads
dzphp editor
EasyPHP
mysql_phpgenerator
php-studio-trial
phpdesigner_7_2_5
phpMyAdmin-3.4.3.2
/phptriad2-2-1
phpxedit_321
rapidphp 2011
WampServer2.1d-x64
WampServer2.1e-x32
xampp-win32-1.7.4-VC6-installer
xampplite-win32-1.7.3
 Misc
Webmaster Resources
Only PHP
ScriptSearch.com
Scripts.com - Get the best scripts NOW!
AndreaPHP Programming

Valid XHTML 1.0 Transitional


Valid CSS!


Adding data to a Database


Adding data to a Database



In this first of our three part guide to manipulating data in a MySQL database we will add data to a MySQL database . First create our sample database.

Now create our sample table like this.

Now we have our table , what we will do is create a form which allows a user to add some text to the database in this we will make it a link. Here is the code for our form , this is pretty straightforward .

<form action="addingtoadb1.php" method ="POST">
<input type = "text" name = "add" maxlength="50"><br>
<input type = "submit" value = "add link"><br>
</form>

Now we move onto our php script , replace the ("hostname" , "username" , "password") with your own details .

<?php
//make our connection details
$connection = mysql_connect("hostname" , "username" , "password")
or die ("Cannot make the connection");
//connect to sampledb with our connection details
$db = mysql_selectdb("sampledb" , $connection)
or die ("Cannot connect to the database");
//if the text field wasnt blank enter data
if($add)
{
//insert the text box data into the sample table
$sql_query = "INSERT into sample VALUES ('','$add')";
$result = mysql_query($sql_query);
//display the entered link
echo "You entered the following info " . $add;
}
//if it was blank display a message
else
{
echo ("you didnt enter any data");
}
?>

 

This will add the text / link to the database , in our next part we will display the links in the database

Part 2 : Displaying the links



Books
 Sponsors


 Random Code
mysql version(database)
php and java example(php and java)
updating clock(image)
 Random Article
  Network
Programming resources
Tutorials directory
Hosting resources
ASP site
Domain names
Progged
Maxi directory
bigarticle : free articles
A Code
Code N Tutorials
Get PHP
Programmers help




beginners PHP Copyright © 2004 onwards by beginnersPHP.