
Buat file php lalu simpan di htdoc
testing.php
<?php mysql_connect('localhost','root',''); mysql_select_db('kode'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="" method="post"> <table class="form" width="500" border="0" align="center"> <tr> <td colspan="3" align="center"><h2><strong> Kode OTOMATIS</strong></h2></td> </tr> <tr> <td>Kode Penumpang</td> <td>:</td> <td><input name="kp" type="text" size="5" maxlength="5" id="kp" value="<?php $h=mysql_query("select *from kode"); if (mysql_num_rows($h)>0){ $k=mysql_query("SELECT CONCAT( 'P' ,LPAD(( RIGHT( MAX(kode),4)+1),4,'0')) as kod FROM kode"); $dk=mysql_fetch_array($k); echo $dk[0]; } else { echo "P0001"; } ?>" readonly="readonly" /></td> </tr> <tr> <td>Nama Penumpang</td> <td>:</td> <td><input name="nama" type="text" size="20" maxlength="20" id="kp" /></td> </tr> <tr> <td></td> <td></td> <td><input name="simpan" type="submit" /></td> </tr> </table> </form> <?php if (isset($_POST['simpan'])){ mysql_query("insert into kode values ('$_POST[kp]','$_POST[nama]')"); echo "<meta http-equiv='refresh' content='0 url=testing.php' />"; } ?> </body> </html>Maka hasilnya

No comments:
Post a Comment