June 5, 201016 yr comment_1035142 hi...sesapa yang biasa buat php, harap dapat membantu menyelesaikan error yang saya ada ni... Notice: Undefined index: add in D:\xampplite\htdocs\Login\peperiksaan\add-delete-update\add.php on line 4 Notice: Undefined index: msg in D:\xampplite\htdocs\Login\peperiksaan\add-delete-update\add.php on line 47 Saya tak tau cam mana nak define index : add tu...dalam page ni..sepatutnya dia akan display data dari database dalam textfield (bentuk borang) dalam page yg sama saya boleh mengemaskini data yang ada tu... Code saya ialah dalam file : update.php <?php include_once ("config.php"); if($_GET['update']) { //$PengawasID = mysql_real_escape_string($_POST['PengawasID']); $Nama = mysql_real_escape_string($_POST['Nama']); $KP = mysql_real_escape_string($_POST['KP']); $Jawatan = mysql_real_escape_string($_POST['Jawatan']); $Gred = mysql_real_escape_string($_POST['Gred']); $Tlantik = mysql_real_escape_string($_POST['Tlantik']); $Tsah = mysql_real_escape_string($_POST['Tsah']); $alamat = mysql_real_escape_string($_POST['alamat']); $poskod = mysql_real_escape_string($_POST['poskod']); $bandar = mysql_real_escape_string($_POST['bandar']); $notel = mysql_real_escape_string($_POST['notel']); $nofax = mysql_real_escape_string($_POST['nofax']); $nohp1 = mysql_real_escape_string($_POST['nohp1']); $query = mysql_query("UPDATE pengawas SET `Nama`= '$Name', `kp`= '$KP',`Jawatan`='$jawatan', `Gred`='$gred', `Tlantik`='$lantik1', `Tsah`= '$sah1',`alamat`= '$alamat', `poskod`= '$poskod', `notel`= '$notel', `nofax`= '$notelp', `nohp1`= '$hp'")or die('Error : ' . mysql_error()); header("Location: update.php?PengawasID=$PengawasID&msg=done"); exit; } ?> <!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=iso-8859-1" /> <title>DBexam</title> <style type="text/css"> <!-- .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; } .style2 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 16px; color: #333333; } --> </style> </head> <body> <h2 align="center" class="style2">Kemaskini Maklumat Pengawas </h2> <p> <?php if ($_GET['msg']) { echo "<p style=\"color:#FF0000\"><strong>Your content has been updated!</strong></p>"; } $show = "SELECT * FROM pengawas WHERE PengawasID='$_GET[PengawasID]'"; $result = mysql_query($show); while ($show = mysql_fetch_array ($result)) { //$PengawasID = $show['PengawasID']; $Name = $show['Nama']; $kp = $show['KP']; $jawatan = $show['Jawatan']; $gred = $show['Gred']; $lantik1 = $show['Tlantik']; $sah1 = $show['Tsah']; $alamat =$show['alamat']; $poskod = $show['poskod']; $bandar = $show['bandar']; $notel = $show['notel']; $notelp = $show['nofax']; $hp = $show['nohp1']; } ?> <form action="update.php?update=yes" method="post"> <table width="99%" border="0" cellspacing="1" cellpadding="1"> <tr> <th width="34%" class="text" scope="row"><div align="left" class="style1">Nama:</div></th> <td width="66%"> <input name="name" type="text" id="name" value="<?php echo $Nama; ?>"/> </td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">No.Kad Pengenalan :</div></th> <td><input name="kp" type="text" value="<?php echo $KP; ?>" /> <label></label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">Jawatan : </div></th> <td><label> <input name="jawatan" type="text" id="jawatan" value="<?php echo $Jawatan;?>" /> </label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">Gred Jawatan </div></th> <td><label> <input name="gred" type="text" value="<?php echo $Gred;?>" /> </label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">Tarikh dilantik ke jawatan sekarang : </div></th> <td><label> <input name="lantik1" type="text" value="<?php echo $Tlantik;?>" /> </label> <label></label> <label></label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">Tarikh disahkan ke jawatan sekarang :</div></th> <td><label> <input name="sah1" type="text" value="<?php echo $Tsah;?>" /> </label> <label></label> <label></label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">Alamat tempat bertugas : </div></th> <td><label> <input name="alamat" type="text" value="<?php echo $alamat;?>" /> Poskod <input name="poskod" type="text" value="<?php echo $poskod;?>" /> Bandar : <input name="bandar" type="text" value="<?php echo $$bandar;?>" /> </label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">No Telefon Pejabat : </div></th> <td><label> <input name="notel" type="text" value="<?php echo $notel;?>" /> </label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">No Faks Pejabat : </div></th> <td><label> <input name="notelp" type="text" value="<?php echo $nofax;?>" /> </label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">No Telefon Bimbit : </div></th> <td><label> <input name="textfield16" value="<?php echo $nohp1;?>" /> </label></td> </tr> <tr> <th scope="row"> </th> <td><input type="submit" name="Submit" value="Update" /> <input type="hidden" value="<?php echo $PengawasID; ?>" name="PengawasID"> </td> </tr> <tr> <th scope="row"> </th> <td> </td> </tr> <tr> <th scope="row"> </th> <td> </td> </tr> <tr> <th scope="row"> </th> <td> </td> </tr> <tr> <th scope="row"> </th> <td> </td> </tr> </table> </form> <p> </p> </body> </html> Report
June 6, 201016 yr Author comment_1035155 [quote name='sue_irna' date='06 June 2010 - 07:26 AM' timestamp='1275780414' post='1035142'] hi...sesapa yang biasa buat php, harap dapat membantu menyelesaikan error yang saya ada ni... Notice: Undefined index: add in D:\xampplite\htdocs\Login\peperiksaan\add-delete-update\add.php on line 4 Notice: Undefined index: msg in D:\xampplite\htdocs\Login\peperiksaan\add-delete-update\add.php on line 47 Saya tak tau cam mana nak define index : add tu...dalam page ni..sepatutnya dia akan display data dari database dalam textfield (bentuk borang) dalam page yg sama saya boleh mengemaskini data yang ada tu... Code saya ialah dalam file : update.php <?php include_once ("config.php"); if($_GET['update']) { //$PengawasID = mysql_real_escape_string($_POST['PengawasID']); $Nama = mysql_real_escape_string($_POST['Nama']); $KP = mysql_real_escape_string($_POST['KP']); $Jawatan = mysql_real_escape_string($_POST['Jawatan']); $Gred = mysql_real_escape_string($_POST['Gred']); $Tlantik = mysql_real_escape_string($_POST['Tlantik']); $Tsah = mysql_real_escape_string($_POST['Tsah']); $alamat = mysql_real_escape_string($_POST['alamat']); $poskod = mysql_real_escape_string($_POST['poskod']); $bandar = mysql_real_escape_string($_POST['bandar']); $notel = mysql_real_escape_string($_POST['notel']); $nofax = mysql_real_escape_string($_POST['nofax']); $nohp1 = mysql_real_escape_string($_POST['nohp1']); $query = mysql_query("UPDATE pengawas SET `Nama`= '$Name', `kp`= '$KP',`Jawatan`='$jawatan', `Gred`='$gred', `Tlantik`='$lantik1', `Tsah`= '$sah1',`alamat`= '$alamat', `poskod`= '$poskod', `notel`= '$notel', `nofax`= '$notelp', `nohp1`= '$hp'")or die('Error : ' . mysql_error()); header("Location: update.php?PengawasID=$PengawasID&msg=done"); exit; } ?> <!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=iso-8859-1" /> <title>DBexam</title> <style type="text/css"> <!-- .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; } .style2 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 16px; color: #333333; } --> </style> </head> <body> <h2 align="center" class="style2">Kemaskini Maklumat Pengawas </h2> <p> <?php if ($_GET['msg']) { echo "<p style=\"color:#FF0000\"><strong>Your content has been updated!</strong></p>"; } $show = "SELECT * FROM pengawas WHERE PengawasID='$_GET[PengawasID]'"; $result = mysql_query($show); while ($show = mysql_fetch_array ($result)) { //$PengawasID = $show['PengawasID']; $Name = $show['Nama']; $kp = $show['KP']; $jawatan = $show['Jawatan']; $gred = $show['Gred']; $lantik1 = $show['Tlantik']; $sah1 = $show['Tsah']; $alamat =$show['alamat']; $poskod = $show['poskod']; $bandar = $show['bandar']; $notel = $show['notel']; $notelp = $show['nofax']; $hp = $show['nohp1']; } ?> <form action="update.php?update=yes" method="post"> <table width="99%" border="0" cellspacing="1" cellpadding="1"> <tr> <th width="34%" class="text" scope="row"><div align="left" class="style1">Nama:</div></th> <td width="66%"> <input name="name" type="text" id="name" value="<?php echo $Nama; ?>"/> </td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">No.Kad Pengenalan :</div></th> <td><input name="kp" type="text" value="<?php echo $KP; ?>" /> <label></label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">Jawatan : </div></th> <td><label> <input name="jawatan" type="text" id="jawatan" value="<?php echo $Jawatan;?>" /> </label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">Gred Jawatan </div></th> <td><label> <input name="gred" type="text" value="<?php echo $Gred;?>" /> </label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">Tarikh dilantik ke jawatan sekarang : </div></th> <td><label> <input name="lantik1" type="text" value="<?php echo $Tlantik;?>" /> </label> <label></label> <label></label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">Tarikh disahkan ke jawatan sekarang :</div></th> <td><label> <input name="sah1" type="text" value="<?php echo $Tsah;?>" /> </label> <label></label> <label></label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">Alamat tempat bertugas : </div></th> <td><label> <input name="alamat" type="text" value="<?php echo $alamat;?>" /> Poskod <input name="poskod" type="text" value="<?php echo $poskod;?>" /> Bandar : <input name="bandar" type="text" value="<?php echo $$bandar;?>" /> </label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">No Telefon Pejabat : </div></th> <td><label> <input name="notel" type="text" value="<?php echo $notel;?>" /> </label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">No Faks Pejabat : </div></th> <td><label> <input name="notelp" type="text" value="<?php echo $nofax;?>" /> </label></td> </tr> <tr> <th class="text" scope="row"><div align="left" class="style1">No Telefon Bimbit : </div></th> <td><label> <input name="textfield16" value="<?php echo $nohp1;?>" /> </label></td> </tr> <tr> <th scope="row"> </th> <td><input type="submit" name="Submit" value="Update" /> <input type="hidden" value="<?php echo $PengawasID; ?>" name="PengawasID"> </td> </tr> <tr> <th scope="row"> </th> <td> </td> </tr> <tr> <th scope="row"> </th> <td> </td> </tr> <tr> <th scope="row"> </th> <td> </td> </tr> <tr> <th scope="row"> </th> <td> </td> </tr> </table> </form> <p> </p> </body> </html> [/quote] Report
June 8, 201016 yr comment_1035571 wsalam.. sy nak minta sue pastekan source code untuk fail add.php sb error skng ni dlm add.php, bkn update.php jd sy nk lihat dulu fail add.php untuk tgk ape kaitannya dgn updaqte.php. Terima Kasih. Report
June 25, 201015 yr comment_1038797 Error ni biasanya jadi sbb variable ko x di setkan betul2. Cuba buat mcm ni. Kalau ada code yg mcm kat bawah tu, [code]if($_GET['update']){ // statement }[/code] tukar kepada [code]if(isset($_GET['update'])){ // statement }[/code] agak2 jadi ada x error tu.. atau [code]if(!isset($_GET['update'])){ // if not isset, ko letak la dummy data kat sini } [/code] Ni just idea. Kalo kat fail add.php tu ganti la dgn variale yg betul.. Tapi kalo dah setel, maybe bleh share kat sini ape yg ko buat.. tq Edited June 25, 201015 yr by dans kam Report
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.