Can anyone tell me why I am getting the following undefined variable ($url) error for this script.
The error is where my if statement if ($url)
. I am a newbie. thanks
An error occurred in script 'testnew/edit_your_sites.php' on line 28: Undefined variable: 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");
}
?>
there may be some more errors in this script if you see any it would be appreciated if you let me know about them. thanks for all your help, you guys are really a great help