Guest User

Untitled

a guest
Nov 5th, 2017
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <html>
  2. <body>
  3. <h2><center>INPUT DATA KE MYSQL</center>
  4. </h2>
  5. <form method="post">
  6. Nama : <input type="text"name="nama"><br>
  7. Alamat: <input type="text"name="asal"><br>
  8. Kelas:<input type="text"name="kelas"><br>
  9. <input type="submit" value="Kirim Data"style="color: white;font-weight:bold;background-color: #ff0000;text-transform: inherit;"name="ok">
  10. </form>
  11. <?php
  12. const br = '<br />';
  13. if(isset($_POST["ok"])){
  14. $x=new mysqli("localhost","root","","test");
  15. $l=$x->prepare("insert into data values(?,?,?)");
  16. $a=$_POST['nama'];
  17. $b=$_POST['asal'];
  18. $c=$_POST['kelas'];
  19.  
  20. $l->bind_param("sis",$a,$b,$c);
  21. $l->execute();
  22. $p=$l->affacted_rows;
  23. echo $p;
  24. if($p==1){
  25. echo"<font color=\"blue\"><b>Berhasil</b> </font> Data telah masuk" . br;
  26. }else{echo"<font color=\"red\"><b>Gagal</b> </font>Data tidak masuk" . br;}
  27. }
  28. ?>
  29. <?php
  30. $dbhost = 'localhost';
  31. $dbuser = 'root';
  32. $dbpass = '';
  33.  
  34. $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  35.  
  36. if(! $conn ) {
  37. die('Could not connect: ' . mysql_error());
  38. }
  39.  
  40. $sql = 'SELECT * FROM data';
  41. mysql_select_db('test');
  42. echo "<center><table>";
  43. echo "<tr>";
  44. echo "<th>Nama</th>";
  45. echo "<th>Alamat</th>";
  46. echo "<th>Kelas</th>";
  47. echo "</tr>";
  48.  
  49. $retval = mysql_query( $sql, $conn );
  50.  
  51. if(! $retval ) {
  52. die('Could not get data: ' . mysql_error());
  53. }
  54.  
  55. while($row = mysql_fetch_array($retval, MYSQL_NUM)) {
  56. echo "EMP ID :{$row[0]} <br> ".
  57. "EMP NAME : {$row[1]} <br> ".
  58. "EMP SALARY : {$row[2]} <br> ".
  59. "--------------------------------<br>";
  60. echo "<tr>";
  61. echo "<td>" . $row[0] . "</td>";
  62. echo "<td>" . $row[1] . "</td>";
  63. echo "<td>" . $row[2] . "</td>";
  64. echo "</tr>";
  65. }
  66. echo "</table>";
  67.  
  68. echo "Fetched data successfully\n</center>";
  69.  
  70. mysql_close($conn);
  71. ?>
  72. </body>
  73. </html>
Add Comment
Please, Sign In to add comment