Mohon bantuan agan" sexalian saya kelusitan menyimpan nip ke dalam database,
saya ememanggil nip dari tabel 1 untuk disimpan kedalam tabel lainnya,,,

<?
require "../linkdb.php";
$link=open_connection();
?>
<!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>Input Data Driver</title>

<script language="JavaScript">
function validasi(){
  var myform = document.form1;
  if (myform['nip'].value==""){
    alert("Maaf, Data belum lengkap");
	myform['nip'].focus();
	return false;
  }
  if (myform['nama_driver'].value==""){
    alert("Maaf, Data belum lengkap");
	myform['nama_driver'].focus();
	return false;
  }
  if (myform['no_sim'].value=="0"){
    alert("Maaf, Data belum lengkap");
	myform['no_sim'].focus();
	return false;
  }
    if (myform['jenis_sim'].value=="0"){
    alert("Maaf, Data belum lengkap");
	myform['jenis_sim'].focus();
	return false;
  }
    if (myform['no_hp'].value=="0"){
    alert("Maaf, Data belum lengkap");
	myform['no_hp'].focus();
	return false;
  }
return true;
}
function cek_nama_driver (kejadian)
{
kejadian = (kejadian) ? kejadian : window.event;
var charCode = (kejadian.which) ? kejadian.which : kejadian.keyCode;
	if (charCode ==13)
		{
		document.form1.no_sim.focus();
		return false;
		}
	return true;
}
function cek_no_sim(kejadian)
{
kejadian = (kejadian) ? kejadian : window.event;
var charCode = (kejadian.which) ? kejadian.which : kejadian.keyCode;
	if (charCode ==13)
		{
		document.form1.jenis_sim.focus();
		return false;
		}
	return true;
}
function cek_jenis_sim (kejadian)
{
kejadian = (kejadian) ? kejadian : window.event;
var charCode = (kejadian.which) ? kejadian.which : kejadian.keyCode;
	if (charCode ==13)
		{
		document.form1.no_hp.focus();
		return false;
		}
	return true;
}
function cek_no_hp (kejadian)
{
kejadian = (kejadian) ? kejadian : window.event;
var charCode = (kejadian.which) ? kejadian.which : kejadian.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	{
	return false;
	}
	if (charCode ==13)
		{
		document.form1.simpan.focus();
		return false;
		}
	return true;
}
</script>

<style type="text/css">
<!--
.style1 {font-weight: bold}
.style2 {font-weight: bold}
-->
</style>
</head>
<body onLoad="document.form1.nip.focus()">
<div align="center">

  <strong>INPUT DATA DRIVER<br />
  PT. ASIA NEGGA PRATAMA</strong><br />
</div>
<hr width="900" size="2"  color="#07CEC8"  /><strong></strong>
          <br />
<form id="form1" name="form1" method="post" action="input_driver.php" onSubmit="return validasi()">
          <table width="500" height="199" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td width="133"><span class="style2"><strong>NIP</strong></span></td>
              <td width="367">
            
              
              
                <?php 
                //untuk bagian ini nip tidak mau ikut tersimpan dalam database
mysql_connect("localhost","root","root"); 
mysql_select_db("offline"); 
$result = mysql_query("select * from staff"); 
$jsArray = "var stfName = new Array();\n"; 
echo '<select name="stfId" onchange="changeValue(this.value)">'; 
echo '<option>-------</option>'; 
while ($row = mysql_fetch_array($result)) { 
echo '<option value="' . $row['nip'] . '">' . $row['nip'] . '</option>'; 
$jsArray .= "stfName['" . $row['nip'] . "'] = {name:'" . addslashes($row['nama_staff']) . "'};\n"; 
} 
echo '</select>'; 
?> 
                <label></label></td>
            </tr>
            <tr>
              <td><span class="style2"><strong>Nama Driver</strong></span></td>
              <td><input name="nama_driver" type="text" class="inputbok" id="nama_driver" onKeyPress="return cek_nama_driver(event)" size="33" maxlength="30" />
			  <script type="text/javascript"> 
<?php echo $jsArray; ?> 
function changeValue(id){ 
document.getElementById('nama_driver').value = stfName[id].name; 
}; 
</script>			  </td>
            </tr>
            <tr>
              <td><span class="style2"><strong>No. SIM</strong></span></td>
              <td><label>
                <input name="no_sim" type="text" id="no_sim" size="33" maxlength="30" onKeyPress="return cek_no_sim(event)" />
              </label></td>
            </tr>
            <tr>
              <td><strong>Jenis SIM</strong></td>
              <td><label>
                <select name="jenis_sim" id="jenis_sim" onKeyPress="return cek_jenis_sim(event)">
                  <option value="B1">B1</option>
                  <option value="B2">B2</option>
                </select>
              </label></td>
            </tr>
            <tr>
              <td><strong>No. HP</strong></td>
              <td><label>
                <input name="no_hp" type="text" class="inputbok" id="no_hp" onKeyPress="return cek_no_hp(event)" size="33"/>
              </label></td>
            </tr>
            <tr>
              <td><span class="style2"></span></td>
              <td><input name="simpan" type="submit" id="simpan" value="Simpan" class="inputbok" />
                  <input name="batal" type="reset" id="batal" value="Batal" class="inputbok" /></td>
            </tr>
          </table>
<br />
          <?
if(isset($_POST['simpan'])){
	$id_driver		=$_POST['id_driver'];
	$nama_driver	=$_POST['nama_driver'];
	$nip			=$_POST['nip'];
	$no_sim     	=$_POST['no_sim'];
	$jenis_sim		=$_POST['jenis_sim'];
	$no_hp       	=$_POST['no_hp'];
	
	$query=mysql_query("insert into driver values('$id_driver','$nama_driver','$nip','$no_sim','$jenis_sim','$no_hp')",$link) or die("<div class='pesan2'style='width:550px;padding:5px;'>Data Driver dengan ID $id_driver sudah ada dalam database.</div>"); 
	if($query) {
?>
</form>
          <fieldset class="inputbok" style="width:500px;">
<legend style="color:#0099CC;"><strong>Data Driver Berhasil Disimpan</strong></legend>
<table width="500" height="142" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="133">NIP</td>
    <td width="12"><div align="center">:</div></td>
    <td width="355"><? $row['nip']; ?></td>
  </tr>
  <tr>
    <td>Nama Driver</td>
    <td><div align="center">:</div></td>
    <td><? echo $nama_driver; ?></td>
  </tr>
  <tr>
    <td>No. SIM</td>
    <td><div align="center">:</div></td>
    <td><? echo $no_sim; ?></td>
  </tr>
  <tr>
    <td>Jenis SIM</td>
    <td><div align="center">:</div></td>
    <td><? if($jenis_sim="B1"){ echo "B1"; }elseif($jeis_sim="B2"){ echo "B2"; }
 ?></td>
  </tr>
  <tr>
    <td>No. HP</td>
    <td><div align="center">:</div></td>
    <td><? echo $no_hp;
 ?></td>
  </tr>
</table>
</fieldset>
<? }}?>
</p></p>
      </div></td>
    </tr>
    <tr>
      <td bgcolor="#07CEC8"><div align="center" class="style1"></div></td>
    </tr>
</table>
</body>
</html>
Silahkan login untuk menjawab!
0
Loading...
Ellyx Christian · Mar 15, 2013 · 0 Suka · 0 Tidak Suka
kesulitannya seperti apa? apakah ada pesan error? saya tidak bisa coba kodenya karena tidak tahu struktur tablenya.