0

i'm trying to insert data to my database table name dokter and the populate dropdown list from poliklinik. but when i'm trying to insert it,the notification keep showing "undifined vaiable : kodep"

here the form code

<select class="form1" name="Kodecrot">
            <?php
            $query = mysql_query("select * from poliklinik");
            if(mysql_num_rows($query) != 0) {
                while($tampil = mysql_fetch_array($query)){
                    echo "<option value=".$tampil['Namapoli'].">".$tampil['Namapoli']."</option>";
                }
            }
            ?>
            </select>

here the process code

<?php
include'../koneksi.php';
$KodeDokter = $_POST['KodeDokter'];
$NmDokter = $_POST['NmDokter'];
$AlmDokter = $_POST['AlmDokter'];
$Telp = $_POST['Telp'];
$KodePoli = $_POST['Kodecrot'];
$KodeJadwal = $_POST['KodeJadwal'];
$med = mysql_query("select * from poliklinik where Namapoli = '$KodePoli'");
while($data = mysql_fetch_array($med)){
    $name = $data['Namapoli'];
    $kodep = $data['Kodepoli'];
}
$jad = mysql_query("select * from jadwalpraktek where Hari = '$KodeJadwal'");
while($data1 = mysql_fetch_array($jad)){
    $jadwal = $data1['Hari'];
    $jaks = $data1['KodeJadwal'];
}
mysql_query("insert into dokter(KodeDokter, NmDokter, AlmDokter, Telp, Kodepoli, KodeJadwal)values('$KodeDokter','$NmDokter','$AlmDokter','$Telp','$kodep','$jaks')");
?>
  • 1
    this query `select * from poliklinik where Namapoli = '$KodePoli'` not returing anything – devpro Feb 23 '16 at 09:42
  • print_r($_POST); r u sure u r getting this: $_POST['Kodecrot'] – devpro Feb 23 '16 at 09:45
  • mysql_* is deprecated.. – devpro Feb 23 '16 at 09:46
  • Your code is vulnerable for [SQL injection](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php), and the mysql_ extension is deprecated and is removed in PHP 7. Consider switching to PDO or mysqli. – syck Feb 23 '16 at 09:54
  • may $med query will not return any row, or if you want display the value($kodep) even the query has not return any value, just declare that variable to NULL or anything. That is declare before the while loop – Gopalakrishnan Feb 23 '16 at 12:40
  • and by the way the primary key of poliklinik is Kodepoli – Muhammad Rizal Firmansyah Feb 23 '16 at 13:28

0 Answers0