0
私のページには、私は2つの形式のテキストボックスを持っています。- 未定義のインデックス - PHPで
最初に5つのテキストボックスと2つの送信ボタン(保存&更新)があります。
私は1つのテキストボックスと2つの送信ボタン(削除&検索)があります。
問題は、Updateボタンをクリックしようとするとエラーが発生します(未定義インデックス:C:\ Apache \ htdocs \ standby \ new_testing.phpのsimpanの37行目の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>";
}
?>
ありがとう:
page.php?padam=...
以下はその問題を解決します!できます.. –