Penyisipan Data 2

Ariyasa · Sep 22, 2012
bli putu, saya sudah buat suatu proses penyisipan nie..
msalahnya.. kadang2 mau kadang2 gk mau.. hancur lebur dah..
mohon koreksinya bli putu..apanya ya saya salah..
suksma bli putu atas bantuannya..
<?
	$conn = mysql_connect("localhost","root","root");
	$db = mysql_select_db("db_sisipan",$conn);

if(isset($sisip)){
	$selek = mysql_query("SELECT * FROM tb_sisipan WHERE id >= '$urutan'");
	while($my = mysql_fetch_array($selek)){
		mysql_query("UPDATE tb_sisipan SET urut = urut+1 WHERE id = $my[id] ");
	}
	mysql_query("INSERT INTO tb_sisipan(nama, urut) VALUES('$nama','$urutan')");
}
?>
<form id="form1" name="form1" method="post" action="">
  NAMA 
  <label for="nama"></label>
  <input type="text" name="nama" id="nama" />
  <br />
  URUT
  <input type="text" name="urutan" id="urutan" />
  <input type="submit" name="sisip" id="sisip" value="SISIPKAN !" />
</form>
<table width="361" border="0" cellpadding="2" cellspacing="2">
  <tr align="center" bgcolor="#CCCCCC">
    <td width="50">NO</td>
    <td width="176">NAMA</td>
    <td width="113">URUTAN</td>
  </tr>
<?
$q = mysql_query("SELECT * FROM tb_sisipan ORDER BY urut ASC");
while ($d = mysql_fetch_array($q)){
?>  
  <tr>
    <td align="center"><? echo "$d[id]"; ?></td>
    <td><? echo "$d[nama]"; ?></td>
    <td align="center"><? echo "$d[urut]"; ?></td>
  </tr>
<? } ?>
</table>
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Sep 30, 2012 · 0 Suka · 0 Tidak Suka
Tolong pelejari tutorial http://www.myphptutorials.com/tutorials/34/cara-memproses-html-form-yang-benar
if(isset($_POST)){
	$selek = mysql_query("SELECT * FROM tb_sisipan WHERE id >= '".$_POST['urutan']."'");
	while($my = mysql_fetch_array($selek)){
		mysql_query("UPDATE tb_sisipan SET urut = urut+1 WHERE id = $my[id] ");
	}
	mysql_query("INSERT INTO tb_sisipan(nama, urut) VALUES('".$_POST['nama']."','".$_POST['urutan']."')");
}