PHP - menambahkan data setelah input data di php

Pertemuan 21 Kampus semester 4

index.php

<!Doctype html>
<html>
<head>
<title>Menambah Data Jika data sudah diinput diphp</title>
</head>
<body>
<form method="POST" action="ProsesADD.php">
<table border="1">
<tr>
<td>ID  </td>
<td><input type ="text" name="id" placeholder="Masukan ID"></td>
</tr><tr>
<td>Nama  </td>
<td><input type ="text" name="user" placeholder="Masukan nama "></td>
</tr>
<tr>
<td>Alamat  </td>
<td><input type ="text" name="alamat" placeholder="Masukan Alamat"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="save" value="SAVE"></td>
</tr>
</table>
</form>
</body>
</html>

ProsesADD.php

<?php
session_start();
mysql_connect("localhost","root","");
mysql_select_db("dbdata");
$id = $_POST['id'];
$user = $_POST['user'];
$alamat = $_POST['alamat'];


$cek = mysql_query("select * from tb_siswa where id = '$id'");
$hasil = mysql_num_rows($cek);
if($hasil>0)
{
echo "Data sudah ada";
}else{
echo "Data berhasil ditambahkan";
mysql_query("insert into tb_siswa values('$id','$user','$alamat')");

}

?>




PHP - menambahkan data setelah input data di php PHP - menambahkan data setelah input data di php Reviewed by Leo on 11:49 Rating: 5

No comments