次の transportreg_edit_n.php を実行すると、「未定義のオフセット: 1」、「未定義のオフセット: 2」などのエラーが発生します。
エラーポイントが強調表示されている場所...
「以前に未定義の変数行がありました」というエラーが表示された後、 $row="" として初期化しました。それから私はこれを手に入れました..これを取り除くにはどうすればよいですか?
isset(.....) プロパティを正しく使用しているかどうかはわかりません。その時点のエラーチェックがまだ行われていないためです:)もしそうなら、私の初心者の間違いに耐えてください:)事前にtnxをたくさん.
<!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>Edit Page</title>
<style type="text/css">
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
text-align: left;
}
body {
background: url(Image/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>
<link href="CSS/transportreg_editStyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<?php
$dbhost="localhost";
$dbuser="root";
$dbpass="rootout";
$dbdb="test";
$connect = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$connect)
{
echo "Failed To Connect To MySql".mysql_error();
echo "<br /><br /><a href='transportreg.php'>Go Back </a>";
}
$db = mysql_select_db($dbdb,$connect);
if (!$db)
{
echo "Failed To Connect To The Database".mysql_error();
echo "<br /><br /><a href='transportreg.php'>Go Back </a>";
}
$row = ""; //added this because of undefined variable row error
if(isset($_GET['edit']))
{
$id = $_GET['edit'];
$sql = "SELECT * FROM transportpublic WHERE transportpublicid='$id' ";
$res = mysql_query($sql)or die($sql."<br/><br/>".mysql_error());
$row = mysql_fetch_array($res,MYSQL_BOTH);
}
if(isset($_POST['edittxttravelType_public'],$_POST['edittxtCostPerKm_public'],$_POST['edittxtAddress_public'],$_POST['edittxtPhoneNumber1_public'],$_POST['edittxtweblink_public'],$_POST['edittxtDescription_public']))
{
$id = $_POST['edittxtid_public'];
$new_txttravelType_public = $_POST['edittxttravelType_public'];
$new_txtCostPerKm_public = $_POST['edittxtCostPerKm_public'];
$new_txtAddress_public = $_POST['edittxtAddress_public'];
$new_txtPhoneNumber1_public = $_POST['edittxtPhoneNumber1_public'];
$new_txtweblink_public = $_POST['edittxtweblink_public'];
$new_txtDescription_public = $_POST['edittxtDescription_public'];
$sql = "UPDATE transportpublic SET transportType='$new_txttravelType_public' AND costPerKm='$new_txtCostPerKm_public' AND address='$new_txtAddress_public' AND teleNo='$new_txtPhoneNumber1_public' AND webLink='$new_txtweblink_public' AND description='$new_txtDescription_public' WHERE transportpublicid ='$id' ";
$res = mysql_query($sql) or die("Error Occured Update Unseccessful! ".mysql_error());
echo "<br /><a href='transportreg_showdata.php'>View Current Data</a>";
}
?>
<body>
<form id="form1" name="form1" method="post" action="transportreg_edit_n.php">
<table width="597" border="0" align="center" cellpadding="0">
<tr>
<th colspan="2" bgcolor="#000000" class="mainTitle" scope="row">Edit Form</th>
</tr>
<tr bgcolor="#c1e9ea">
<td width="324" scope="row"><blockquote>
<p><span class="classlabels">Transportation Type/Name :</span></p>
</blockquote></td>
<td width="270">
<label for="edittxttravelType_public"></label>
//here $row[1] causes the error "Undefined offset: 1"
<input name="edittxttravelType_public" type="text" value="<?php echo $row[1]; ?>" id="edittxttravelType_public2" size="45" maxlength="60" />
//here $row[0] causes an error "Undefined offset: 0"
<input name="edittxtid_public" type="hidden" value="<?php echo **$row[0]**; ?>" id="edittxttravelType_public" size="45" maxlength="60" />
</td>
</tr>
<tr bgcolor="#dbf4f6">
<td scope="row"><blockquote>
<p>Cost per kilometer :</p>
</blockquote></td>
<td>
<label for="edittxtCostPerKm_public"></label>
//here $row[2] causes an error "Undefined offset: 2"
<input name="edittxtCostPerKm_public" value="<?php echo $row[2]; ?>" type="text" id="edittxtCostPerKm_public" size="45" maxlength="60" /></td>
</tr>
<tr>
<td bgcolor="#c1e9ea" scope="row"><blockquote>Address :</blockquote></td>
<td bgcolor="#c1e9ea">
<label for="edittxtAddress_public"></label>
//here $row[3] causes an error "Undefined offset: 3"
<textarea name="edittxtAddress_public" id="edittxtAddress_public" cols="32" rows="3"><?php echo $row[3]; ?> </textarea></td>
</tr>
<tr bgcolor="#dbf4f6">
<td bgcolor="#dbf4f6" scope="row"><blockquote>Telephone Number :</blockquote></td>
<td>
<label for="edittxtPhoneNumber1_public"></label>
//here $row[4] causes an error "Undefined offset: 4"
<input name="edittxtPhoneNumber1_public" type="text" value="<?php echo $row[4]; ?>" id="edittxtPhoneNumber1_public" size="45" maxlength="15" /></td>
</tr>
<tr bgcolor="#c1e9ea">
<td bgcolor="#c1e9ea" scope="row"><blockquote>Official WebSite Link :</blockquote></td>
<td>
<label for="edittxtweblink_public"></label>
//here $row[5] causes an error "Undefined offset: 5"
<input name="edittxtweblink_public" type="text" value="<?php echo $row[5]; ?>" id="edittxtweblink_public" size="45" maxlength="300" />
</td>
</tr>
<tr bgcolor="#dbf4f6">
<td scope="row"><blockquote>Brief Description :</blockquote></td>
<td><label for="edittxtDescription_public"></label>
//here $row[6] causes an error "Undefined offset: 6"
<textarea name="edittxtDescription_public" id="edittxtDescription_public" cols="32" rows="10"><?php echo $row[6]; ?></textarea></td>
</tr>
<tr bgcolor="#dbf4f6">
<td colspan="2" bgcolor="#c1e9ea" scope="row"><blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<p>
<input name="btnupdatet_public" type="submit" class="submit" id="btnupdatet_public" value="Update" />
</p>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote></td>
</tr>
<tr bgcolor="#dbf4f6">
<td colspan="2" bgcolor="#c1e9ea" scope="row"><table width="601" border='0' bordercolor='#000000' class="tb">
<tr>
<td width="340" height="20"><a href='transportreg_showdata.php'>View Updated Public Transportation Data</a>
</td>
<td width="272"><a href='transportreg.php'>Go Back To Registration Page</a>
</td>
</table></td>
</tr>
</table>
<p> </p>
<p> </p>
</form>
<?php
mysql_close($connect);
?>
</body>
</html>