0
在我的頁面中,我有兩種形式的文本框。- undefined index - in php
第一個我有5個文本框和2個提交按鈕(保存&更新)。
第二個我有1個文本框和2個提交按鈕(刪除&搜索)。
問題是,無論何時我嘗試點擊更新按鈕,都會發生錯誤(未定義的索引:第37行中的C:\ Apache \ htdocs \ standby \ new_testing.php中的simpan),但它仍然執行該函數。看來我在這一行有一個問題(if($ _GET ['padam'] =='Delete'))。誰能幫我這個。這是我的代碼:
<!-- form for inserting and updating data into database-->
<form action="new_testing.php" method="GET">
<input type="varchar" size="15" name="textbox"><br>
<input type="varchar" size="15" name="textbox2"><br>
<input type="varchar" size="15" name="textbox3"><br>
<input type="varchar" size="15" name="textbox4"><br>
<input type="number" size="15" name="textbox5"><br><br>
<input type="submit" name="simpan" value="Save"> <input type="submit" name="alter" value="Update">
</form>
<?php
if (isset($_GET['textbox']) and isset($_GET['textbox2']) and isset($_GET['textbox3']) and isset($_GET['textbox4'])
and isset($_GET['textbox5']))
{
$box1 = $_GET['textbox'];
$box2 = $_GET['textbox2'];
$box3 = $_GET['textbox3'];
$box4 = $_GET['textbox4'];
$box5 = $_GET['textbox5'];
$db=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
$mydb=mysql_select_db("inventory");
if ($_GET['simpan'] == 'Save')
{
$simpan = $_GET['simpan'];
$sql="insert into alatan values('".$box1."','".$box2."','".$box3."','".$box4."','".$box5."') ";
$result=mysql_query($sql) or die (mysql_error());
}
elseif ($_GET['alter'] == 'Update')
{
$alter = $_GET['alter'];
$sql="update alatan set Fakulti=('".$box2."'), NamaAlat=('".$box3."'), Lokasi=('".$box4."'), TahunDibeli=('".$box5."') where NoSiri=('".$box1."')";
$result=mysql_query($sql) or die (mysql_error());
}
}
?>
<!-- form for deleting and seacrhing data from database-->
<form action="new_testing.php" method="GET">
<input type="varchar" size="15" name="drop"><br>
<input type="submit" name="padam" value="Delete"> <input type="submit" name="cari" value="Search">
</form>
<?php
if (isset($_GET['drop']))
{
$del = $_GET['drop'];
$db=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
$mydb=mysql_select_db("inventory");
if ($_GET['padam'] == 'Delete')
{
$padam = $_GET['padam'];
$sql="delete from alatan where NoSiri=('".$del."')";
$result=mysql_query($sql) or die (mysql_error());
}
elseif ($_GET['cari'] == 'Search')
{
$cari = $_GET['cari'];
$sql= "select * from alatan where NoSiri=('". $del ."')";
$result=mysql_query($sql) or die (mysql_error());
while($row=mysql_fetch_array($result)){
$box1 =$row['NoSiri'];
$box2 =$row['Fakulti'];
$box3 =$row['NamaAlat'];
$box4 =$row['Lokasi'];
$box5 =$row['TahunDibeli'];
}
}
}
?>
<!-- table for displaying table "alatan-->
<table border="1">
<tr>
<th>No Siri</th>
<th>Fakulti</th>
<th>Nama Alat</th>
<th>Lokasi</th>
<th>Tahun Dibeli</th>
</tr>
<?php
$db=mysql_connect ("localhost", "root", "") or die ('I cannot connect to the database because: ' . mysql_error());
$mydb=mysql_select_db("inventory");
$sql="select * from alatan";
$result=mysql_query($sql);
$NoSiri = array();
$Fakulti = array();
$NamaAlat = array();
$Lokasi = array();
$Tahun = array();
while($row=mysql_fetch_array($result)){
$NoSiri =$row['NoSiri'];
$Fakulti =$row['Fakulti'];
$NamaAlat =$row['NamaAlat'];
$Lokasi =$row['Lokasi'];
$Tahun =$row['TahunDibeli'];
echo "<tr>
<td> $NoSiri </td>
<td>$Fakulti </td>
<td>$NamaAlat</td>
<td>$Lokasi</td>
<td>$Tahun</td>
</tr>";
}
?>
謝謝!有用.. – 2012-03-19 04:08:05