Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- <h2><center>INPUT DATA KE MYSQL</center>
- </h2>
- <form method="post">
- Nama : <input type="text"name="nama"><br>
- Alamat: <input type="text"name="asal"><br>
- Kelas:<input type="text"name="kelas"><br>
- <input type="submit" value="Kirim Data"style="color: white;font-weight:bold;background-color: #ff0000;text-transform: inherit;"name="ok">
- </form>
- <?php
- const br = '<br />';
- if(isset($_POST["ok"])){
- $x=new mysqli("localhost","root","","test");
- $l=$x->prepare("insert into data values(?,?,?)");
- $a=$_POST['nama'];
- $b=$_POST['asal'];
- $c=$_POST['kelas'];
- $l->bind_param("sis",$a,$b,$c);
- $l->execute();
- $p=$l->affacted_rows;
- echo $p;
- if($p==1){
- echo"<font color=\"blue\"><b>Berhasil</b> </font> Data telah masuk" . br;
- }else{echo"<font color=\"red\"><b>Gagal</b> </font>Data tidak masuk" . br;}
- }
- ?>
- <?php
- $dbhost = 'localhost';
- $dbuser = 'root';
- $dbpass = '';
- $conn = mysql_connect($dbhost, $dbuser, $dbpass);
- if(! $conn ) {
- die('Could not connect: ' . mysql_error());
- }
- $sql = 'SELECT * FROM data';
- mysql_select_db('test');
- echo "<center><table>";
- echo "<tr>";
- echo "<th>Nama</th>";
- echo "<th>Alamat</th>";
- echo "<th>Kelas</th>";
- echo "</tr>";
- $retval = mysql_query( $sql, $conn );
- if(! $retval ) {
- die('Could not get data: ' . mysql_error());
- }
- while($row = mysql_fetch_array($retval, MYSQL_NUM)) {
- echo "EMP ID :{$row[0]} <br> ".
- "EMP NAME : {$row[1]} <br> ".
- "EMP SALARY : {$row[2]} <br> ".
- "--------------------------------<br>";
- echo "<tr>";
- echo "<td>" . $row[0] . "</td>";
- echo "<td>" . $row[1] . "</td>";
- echo "<td>" . $row[2] . "</td>";
- echo "</tr>";
- }
- echo "</table>";
- echo "Fetched data successfully\n</center>";
- mysql_close($conn);
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment