Contoh Program upload di hosting

nama file : inputtgs.php

<DOCTYPE html>
<html>
<head>
<title> Input Data Mahasiswa ke Database dengan PHP dan MySQL </title>
<style type=”text/css”>
b { color : lime }
</style>
</head>
<body>
<center>
<h1>Form Input Data</h1>

<?php
if (!empty($_GET[‘message’]) && $_GET[‘message’] == ‘success’) {
echo ‘<h3>Berhasil menambah data!</h3>’;
}
?>

<form name=”input_data” action=”inserttgs1.php” method=”post”>
<table border=”1″ cellpadding=”5″ cellspacing=”0″ style=”background-color:white;”>

<tr>
<td> NIM </td>
<td>:</td>
<td><input type=”text” name=”txtnim” maxlength=”20″ /></td>
</tr>
<tr>
<td> Nama </td>
<td>:</td>
<td><input type=”text” name=”txtnama” maxlength=”20″ /></td>
</tr>
<tr>
<td> Alamat </td>
<td>:</td>
<td><input type=”text” name=”txtalamat” maxlength=”20″ /></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input type=”email” name=”txtemail” /></td>
</tr>
<tr>
<td>Agama</td>
<td>:</td>
<td><input type=”text” name=”txtagama” /></td>
</tr>

<tr>
<td>Nomor HP</td>
<td>:</td>
<td><input type=”text” name=”txthp” maxlength=”14″ /></td>
</tr>
<tr>
<td align=”right” colspan=”3″><input type=”submit” name=”submit” value=”Simpan” /></td>
</tr>

</table>
</form>
</center>
<!– a href=”tampiltgs.php”>Lihat Data</a –>
</body>
</html>

 


 

Nama File : koneksitgs.php

<?php
$host = ‘localhost’;
$user = ‘id8249955_setyo’;
$pass =’setys2009′;
$dbname =’id8249955_universitas’;
$konek = mysqli_connect($host,$user,$pass,$dbname)
?>

 


nama file : inserttgs1.php

<?php

include(‘koneksitgs.php’);

$query=”insert into mhs VALUES (‘$_POST[txtnim]’,’$_POST[txtnama]’,’$_POST[txtalamat]’,’$_POST[txtemail]’,’$_POST[txtagama]’,’$_POST[txthp]’)”;

$simpan=mysqli_query($konek,$query);

if(!$simpan ){
echo “<script>alert(‘Gagal di tambahkan!’);history.go(-2);</script>”;
} else{
echo “<script>alert(‘Data berhasil di tambahkan!’);history.go(-2);</script>”;
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *