Variable undefined and a warning, looking for a long time also can not find out! Ask the great God for help, thank you!
This post was last edited by xuzuning on 2014-03-06 10:16:20
/******* in the 20th row of the while loop inside the variable $arr said undefined, do not reduce the warning, it is self-deception, I want to be how to improve the program *******/
Session_Start ();
echo $_session[' username '];
if ($_post && $_post[' Submit ')} {
$username =$_post["username"];
$email = $_post["email"];
$title = $_post["title"];
$content = $_post["Content"];
$createtime = Date ("y-m-d h:i:s");
$link = mysql_connect ("127.0.1.1", "Root", "") or Die ("Cannot connect to the server! The database server may not be turned on, or the user name password is wrong! ". Mysql_error ());
mysql_query ("Use Db_leave");
mysql_select_db ("Db_leave", $link);
mysql_query ("Set names ' UTF8 '");
$sql = "INSERT into L_text (id,username,email,title,content,createtime) VALUES (' ', ' $username ', ' $email ', ' $title ', ' $ Content ', ' $createtime ') ";
$result = mysql_query ($sql);
$r = mysql_query ("SELECT * from L_text");
}
?>
while ($arr = Mysql_fetch_array ($r)) {
?>
Name: |
|
Mailbox: |
|
Title: |
|
Message time: |
|
Message content: |
|
}
?>
------Solution--------------------
In C, variables must first be declared and reused (because the compiler needs to allocate memory)
PHP variables are not stored directly in the memory address, but are stored in the variable table. Therefore, you can use undeclared variables
Notice warning only indicates that there may be a problem, but not necessarily a problem
Why are database queries outside the branch?
Because you used database operations both inside and outside the conditional branch
If it is placed only within the conditional branch, it may be a problem