Hi… welcome in my page…
Now. I want to giving you about PHP and discuss of “program
input from php to mysql” or “input database from PHP”. You will know ??? let’s
reading this article..
In inputing data from PHP to MYSQL (database) you must have
3 (three) component like as :
- Database
- Form for inputing
- Connenction
- Syntax for inputing to mysql (database)
1. DATABASE
Database is program for saving data. The data can be name,
date, address, sex and other…
I ever discuss it… if you not know please visit to
http://have-fun-and-enjoy.blogspot.com/2012/07/create-database-and-table-in-mysql.html
2. FORM FOR INPUTING
You must having it for inputing…
You can copy this coding and paste in your notepad
<html>
<head>
<title></title>
</head>
<body>
<form method = "POST" action =
"input.php">
<table border = "0" cellpadding = 1 cellspacing
= 1 align = center>
<tr>
<td>nama</td><td><input type = text
name = "nama"></td>
</tr>
<tr>
<td>sex</td><td><input type = radio
name = "sex" value = "Man">Man
<input type = radio name = "sex" value =
"Woman">Woman</td>
</tr>
<tr>
<td>date</td>
<td>
<select name = "date">
<option value = "01">01</option>
<option value = "02">02</option>
<option value = "03">03</option>
<option value = "04">04</option>
<option value = "05">05</option>
<option value = "06">06</option>
</select>
<select name = "moon">
<option value = "01">jan</option>
<option value = "02">feb</option>
<option value = "03">mar</option>
<option value = "04">apr</option>
<option value = "05">mai</option>
<option value = "06">jun</option>
</select>
<select name = "year">
<option value = "1990">90</option>
<option value = "1991">91</option>
<option value = "1992">92</option>
<option value = "1993">93</option>
<option value = "1994">94</option>
<option value = "1995">95</option>
</select>
</td>
</tr>
<tr>
<td>alamat</td><td><textarea cols = 17
rows 3 name = "live"></textarea></td>
</tr>
<tr>
<td></td><td align = center ><input
type = submit value = "SAVE"></td>
</table>
</form>
</body>
</html>
</body>
</html>
If its give name “insert.html”
3. CONNECTION
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db =
"adsanse";
$a =
mysql_connect($host, $user, $pass);
$b =
mysql_select_db($db, $a);
if ($b)
{
echo "succes to connect";
}
else
{
echo "failed to connect";
}
?>
If its give name “connection.html”
4. SYNTAX FOR INPUTING TO MYSQL(DATABASE)
<?php
include "
connection .php";
$nm =
$_POST['nama'];
$jk =
$_POST['sex'];
$dt =
$_POST['year'].'-'.$_POST['monn'].'-'.$_POST['date'];
$alamat = $_POST['live'];
$a = "insert into adsanse(name, sex, born, address)
values ('$nm', '$jk', '$dt', '$alamat')";
$b = mysql_query($a);
if ($b)
{
echo "succes to input";
}
else
{
echo "failed to input";
}
?>
If its give name “input.php”
NOTE :
If you using copy + paste >> please change all quote (" ") because if not.. want error
If you using copy + paste >> please change all quote (" ") because if not.. want error
for working you must trun on apache and mysql in "xampp".
write "localhost/insert.html" in your search engine for try the program.
put your saving in folder "htdoc" of xampp.
for saw your was input, open mysql... and write "select * from adsanse; >> enter"
Ok just it...
if you will questions, please leave a comment...
Thanks for reader...
see you later
No comments:
Post a Comment