我在下面有以下 php 代码,一旦提交表单,它就会不断抛出一个未定义的变量。我不确定我做错了什么,谁能告诉我是什么导致了错误?
错误行:
注意:未定义的变量:/home/roberkl103/domains/ * */public_html/dev/edit_account.php 中的 error_message 在第 64 行
<?php
include "game_header.php";
$user = new User($_SESSION['id']);
$_GET['type'] = isset($_GET['type']) && ctype_alpha($_GET['type']) ? trim($_GET['type']) : '0';
switch ($_GET['type']) {
case 'header' : ui_header(); break;
case 'options' : ui_options(); break;
default: ui_header();
}
function ui_header() {
global $user, $game;
$whichsection = "Edit Account";
$header = "
<div class='dsh_mid_content_lft'>
<div class='dsh_content_txt'>
".$whichsection."
</div>
<div style='margin-top: 5px;'> </div>
<p align='center'>
<a class='button unactive' href='/edit_account/options.php'>Profile Options</a>
<a class='button unactive' href='/edit_account/password.php'>New Password</a>
<a class='button unactive' href='/edit_account/colouredname.php'>Coloured Name</a>
<a class='button unactive' href='/edit_account/profileflags.php'>Profile Flags</a>
<a class='button unactive' href='/edit_account/gameoptions.php'>Game Options</a>
</p>
<br />
";
echo $header;
}
function ui_options() {
global $user, $game;
if (isset($_POST['profileoptions'])) {
$username = mysql_real_escape_string(htmlspecialchars($_POST['username']));
$email = mysql_real_escape_string(htmlspecialchars($_POST['email']));
$gender = mysql_real_escape_string($_POST['gender']);
$quote = mysql_real_escape_string(htmlspecialchars($_POST['quote']));
$signature = mysql_real_escape_string(htmlspecialchars($_POST['signature']));
$name_query = mysql_query("SELECT COUNT(*) AS `c` FROM `mx_users` WHERE `username` = '{$username}' and `id` != '{$user->id}'");
$name_fetch = mysql_fetch_assoc($name_query);
// Name already exists
if ($name_fetch['c'] > 0) {
$error_message = "The username you chose is already in use by someone else.";
}
// New name is too short
if (strlen($username) < 3) {
$error_message = "Your name is too short. Atleast 3 characters.";
}
// New name is too long
if (strlen($username) > 16) {
$error_message = "Your name is too long. Max 16 characters.";
}
// New email is invalid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error_message = "The e-mail address you entered was invalid.";
}
if ($error_message != "") {
echo $error_message;
} else {
$update = mysql_query("UPDATE `mx_users` SET `username` = '$username', `email` = '$email', `gender` = '$gender', `quote` = `$quote', `signature` = '$signature'");
$success_message = "Your preferences have been saved.";
}
}
ui_header();
$options_content = "
<form method='post' action='/edit_account/options.php'>
<table width='100%' border='0' cellpadding='5'>
<tr>
<td><b>Name</b>:</td>
<td>
<input type='text' name='username' value='".$user->username."' maxlength='16' size='20' />
<em>Will not change your login name.</em>
</td>
</tr>
<tr>
<td><b>Email</b>:</td>
<td>
<input type='text' name='email' value='".$user->email."' size='40' />
</td>
</tr>
<tr>
<td><b>Avatar</b>:</td>
<td>
<input type='text' name='avatar' value='".$user->avatar."' size='40' />
</td>
</tr>
<tr>
<td><b>Quote:</b></td>
<td>
<input type='text' name='quote' value='".htmlspecialchars($user->quote)."' size='40' />
</td>
</tr>
<tr>
<td><b>Gender</b>:</td>
<td>
<select name='gender'>
<option value='1'>Male</option>
<option value='2'>Female</option>
</select>
</td>
</tr>
<tr>
<td><b>Signature</b>:</td>
<td>
<textarea type='text' name='signature' cols='50' rows='6'>
".$user->signature."
</textarea>
</td>
</tr>
<tr>
<td> </td>
<td>
<input type='submit' name='profileoptions' />
</td>
</tr>
</table>
</form>
";
echo $options_content;
}
?>