我得到以下錯誤on line 8: Undefined index: privacy_policy
這是$privacy_policy = mysqli_real_escape_string($mysqli, $_POST['privacy_policy']);
我想知道如何解決這個問題?PHP錯誤問題
這裏是線8
$privacy_policy = mysqli_real_escape_string($mysqli, $_POST['privacy_policy']);
這裏是PHP。
if (isset($_POST['submitted'])) {
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT users.*
FROM users
WHERE user_id=3");
$privacy_policy = mysqli_real_escape_string($mysqli, $_POST['privacy_policy']);
if (mysqli_num_rows($dbc) == 0) {
$mysqli = mysqli_connect("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"INSERT INTO users (user_id, privacy_policy)
VALUES ('$user_id', '$privacy_policy')");
}
if ($dbc == TRUE) {
$dbc = mysqli_query($mysqli,"UPDATE users
SET privacy_policy = '$privacy_policy'
WHERE user_id = '$user_id'");
echo '<p class="changes-saved">Your changes have been saved!</p>';
}
if (!$dbc) {
print mysqli_error($mysqli);
return;
}
}
這裏是HTML。
<form method="post" action="index.php">
<fieldset>
<ul>
<li><input type="checkbox" name="privacy_policy" id="privacy_policy" value="yes" <?php if (isset($_POST['privacy_policy'])) { echo 'checked="checked"'; } else if($privacy_policy == "yes") { echo 'checked="checked"'; } ?> /></li>
<li><input type="submit" name="submit" value="Save Changes" class="save-button" />
<input type="hidden" name="submitted" value="true" />
<input type="submit" name="submit" value="Preview Changes" class="preview-changes-button" /></li>
</ul>
</fieldset>
</form>
除非你有一個非常奇怪的PHP安裝,8號線不應該是隱私政策。我爲什麼這麼說?因爲需要在文件中有一個'<?'或'<?php',這可能在它自己的行上。 – Powerlord 2010-04-08 14:24:32
你能指出第8行嗎?我沒有看到你提供的代碼中的任何地方引用了「real_name」。 – thetaiko 2010-04-08 14:24:41