Solutions to PHP undefined variable errors: 1. Initialize the variable for assignment; 2. Add the @ symbol to suppress the error, code such as "$sid = @$_POST['sid'];".
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
What should I do if I get an undefined variable error in php?
PHP Solving undefined variable errors
Sometimes this error
Notice: Undefined index: sid in D:\Apache Group\Apache2\htdocs\php_mobile\mobile\chao\sinnsei_publish.php on line 10
will appear in PHP. The reason is that it is not defined, because PHP is Weakly typed languages, unlike JAVA, do not necessarily need to be initialized, so this problem is actually not a big problem
However, it does not look good when it appears on the page,
Method 1: Initialization Assigning values to variables
Method 2: Add @ to suppress errors
$sid = @$_POST['sid'];
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What to do if php undefined variable error occurs. For more information, please follow other related articles on the PHP Chinese website!