任何人都可以告訴我爲什麼我得到這個腳本的以下未定義變量($ url)錯誤。 錯誤是我的if語句if ($url)
。我是一個新手。由於腳本 'testnew/edit_your_sites.php' 發生在28行
錯誤: 未定義的變量:URL
<div class="text">
<?php
$page_title = 'Edit Your Account';
include ('includes/header.html');
include ('includes/functions.php');
include ('includes/config.inc.php');
if (isset($_GET['id']) && is_numeric($_GET['id'])){
$id = $_GET['id'];
} elseif (isset($_POST['id']) && is_numeric($_POST['id'])) {
$id = $_POST['id'];
} else {
echo '<p class="error">This page has been accessed in error.</p>';
include ('includes/footer.html');
exit();
}
if (isset($_SESSION['UserID'])){
require (MYSQL);
$scrubbed = array_map('spam_scrubber', $_POST);
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
if (empty($scrubbed['url'])){
echo '<p class="error">Please enter a url</p>';
} else {
$url = mysqli_real_escape_string($dbc, $scrubbed['url']);
}
}
if ($url){
$p = "SELECT UserID FROM sites WHERE UserID=$id";
$q = mysqli_query($dbc, $p);
if (mysqli_num_rows($q) == 1){
$i = "INSERT INTO sites (UserID, url, entry) VALUES('{$_SESSION['UserID']}', '$url', NOW())";
$r = mysqli_query($dbc, $i);
if (mysqli_affected_rows($dbc) == 1){
echo '<p>Your website was added succesfully.</p>';
} else {
echo '<p class="error">Due to a system error your website could not be added.</p>';
}
} else {
echo '<p class="error">Please try again';
}
}
?>
<form action="edit_your_sites.php" method="post">
<?php $sql = "SELECT * FROM sitetypes";
$f = mysqli_query($dbc, $sql) or trigger_error("Query: $sql\n<br />Mysqli Error: " . mysqli_error($dbc));
echo '<select name="SiteType" selected="selected">';
while($row2 = mysqli_fetch_array($f, MYSQLI_ASSOC)){
if ($row2['SiteType'] == 'selected'){
echo "<option Selected='selected' value=" . $row2["SiteTypeID"] . ">" . $row2['SiteType'] . "</option>";
} else {
echo "<option value=" . $row2["SiteTypeID"] . ">" . $row2['SiteType'] . "</option>";
}
}
echo '</select>';
?>
<p>Url:<input type="text" name="url" size="30" maxlength="60" value="<?php if(isset($scrubbed['url'])) echo $scrubbed['url']; ?>" /></p>
<?php
echo '</fieldset>
<p><input type="submit" name="submit" value="Edit Account!" /><input type="reset" name="reset" value="Clear Form" />
<input type="hidden" name="id" value="' . $id . '" />
</form>';
} else {
$url = BASE_URL . 'index.php';
header("Location: $url");
}
?>
有可能在這個腳本,如果你看到一些 更多的錯誤任何它將不勝感激,如果你 讓我知道他們。 感謝你的幫助,你們是真的有很大的幫助
[參考? - 這是什麼錯誤PHP意味着]可能重複(http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean -in-php) – Anonymous
這已經被問過很多次了,很明顯。你的變量'$ url'只是基於條件聲明的,所以當這個條件不成立時,它會拋出這個錯誤。改變'if($ url){'到'if(isset($ url)){' –
它的一個通知...只是把它關掉......沒有東西可以破壞這個代碼.. –