私は自分のプロジェクトの編集ユーザープロファイルを作成しています。私はこのエラーに遭遇しました。 " Notice:未定義のインデックス:C:\ xampp \ htdocs \ HelloWorld \ EditProfile.phpの18行目のユーザID: "。私はエラーの原因を見つけるのに1時間を費やしましたが、私はそれを見つけるように見えません。未定義のインデックス:ユーザーID
EditProfile.php事前に
<?php
// connect to SQL
$con = mysql_connect("localhost", "root", "2345fypj");
if (!$con) {
echo("<P>Unable to connect to the database server at this time.</P>");
exit();
}
// connect to database
$dbcon = @mysql_select_db("user_profile", $con);
if (!$dbcon) {
echo("<P>Unable to locate DB table at this time.</P>");
exit();
}
#data preparation for the query
$id = intval($_POST["userid"]);
foreach ($_POST as $key => $value) $_POST[$key] = mysql_real_escape_string($value);
$sql = "UPDATE user_profile SET
name='$_POST[name]',
age='$_POST[age]',
WHERE userid=$id";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
mysql_close($con);
header ("location: http://www.domain.com/url_to_go_to_after_update");
?>
おかげsave_edit.php
<?php
// connect to SQL
$dbcnx = mysql_connect("localhost", "root", "2345fypj");
if (!$dbcnx)
{
echo("<P>Unable to connect to the database server at this time.</P>");
exit();
}
// connect to database
$dbcon = mysql_select_db("my_db", $dbcnx);
if (!$dbcon) {
echo("<P>Unable to locate DB table at this time.</P>");
exit();
}
//data preparation for the query
$id = intval($_GET['userid']);
// selects title and description fields from database
$sql = "SELECT * FROM user_profile WHERE userid=$id";
$result = mysql_query($sql) or die(mysql_error());
# retrieved by using $row['col_name']
$row = mysql_fetch_array($result);
?>
<h3>Edit</h3>
<form action="save_edit.php" enctype="multipart/form-data" method="post" name="myForm" />
<table>
<tr>
<td><b>Name</b></td>
<td><input type="text" size="70" maxlength="100" name="title" value="<?php echo $row['name'] ?>"></td>
</tr>
<tr>
<td><b>Age</b></td>
<td><input type="text" size="70" maxlength="100" name="title" value="<?php echo $row['age'] ?>"></td>
</tr>
</table>
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input name="enter" type="submit" value="Edit">
</form>
<?php
mysql_close($dbcnx);
?>
:私はここに私のコードだphp -'Edit' function for forum posts and suchここで、このガイドを追いました。
このページの右の部分でも同様の質問をお読みください。 PS:盲目的なコピー貼り付けで、コードが何か良い結果を出さないと理解していない – zerkms
"18行目のEditProfile.php"、18行目の内容は何ですか? –
@icktoofayそれは "あなたが18行目にあるものを考える、エラーがある"というより多くのものでした:) –