Data Input File With PHP and MYSQL

In the process of learning PHP we must master in making application CRUD (Create, Read, Update, Delete). In the discussion of this article, I tried to further pointed out how to create a simple data input applications that are easy to understand for novice programmers.

As an initial step in learning PHP MySql Data Input for making application we will make a MySQL database, the following script to create the database:
<pre class='brush:js'>
CREATE TABLE 'data_employe' (
'nip' INT( 5 ) NOT NULL ,
'name_employe' VARCHAR( 50 ) NOT NULL ,
'address_employe' TEXT NOT NULL ,
'no_tlp' VARCHAR( 20 ) NOT NULL ,
PRIMARY KEY ('nip')
) ENGINE = MYISAM
</pre> 
When finished creating the database that contains the table data_employe now we create scripts to connect to a database that has been created.

conn.php

<pre class='brush:js'>
<?php 
$konek = mysql_connect("localhost","root","") or die ("Conn Gagal");
mysql_select_db("crud",$konek) or die ("Database Belum Dibuat");
?>
</pre> 


index.php
<pre class='brush:js'>
<html>
<head>
<title>Tutorial PHP MySql</title>
</head>
<body>
<a href="input_data.php">Add Data</a>
</body>
</html>
</pre> 
input_data.php




Tutorial  PHP MySql





ID : Name Employe : Address : Phone :

process_input.php
<?php
include("conn.php");
$nip = $_POST[‘id’];
$name = $_POST['name'];
$address = $_POST['address'];
$tlp = $_POST['tlp'];

$query = "insert into data_employe values('$nip','$name','$address','$tlp')";
$process = mysql_query($query);
echo "<script>alert(‘Data successfully processed ')location.replace('view_data.php')";
?>
view_data.php
 <pre class='brush:js'> 
 <?php
include("conn.php");
?>
<html>
<head>
<ttitle> Tutorial  PHP Mysql </title>
</head>
<body>
<table border=1px;>
<tr>
<th>ID </th>
<th>Name Employe </th>
<th>Address </th>
<th>Phone </th>
</tr>
<?php
$result = mysql_query("select * from data_employe");
while($data=mysql_fetch_array($result)){
?>
<tr>
<td> <?php echo $data['nip']; ?> </td>
<td> <?php echo $data['name_employe']; ?> </td>
<td> <?php echo $data['address_employe']; ?> </td>
<td> <?php echo $data['no_tlp']; ?> </td>
</tr>
<?php } ?>
</table>
< a href="add_data.php">Add Data </a>
</body>
</html>
</pre>



This script is a simple example of making the application of Input Data.
Previous
Next Post »