Php receives idPHPcode & lt ;? Php $ id = $ _ GET ['id'] + 0; if ($ id = 0) {echo & quot; Parameter error & quot; exit ;} $ conn = mysql_connect ('loaclhost', 'root', 'php receiving address bar id
PHP code
The file is named test. php, the editing environment is editplus, and press ctrl + B.
HTML code
Notice: Undefined index: id in D: \ server \ apache \ www \ test. php on line 2 Parameter error
So I entered
HTML code
http://localhost/test.php[color=#FF0000]?id=2[/color]
However, more errors are displayed this time.
HTML code
Warning: mysql_connect () [function. mysql-connect]: php_network_getaddresses: getaddrinfo failed: Unknown host. In D: \ server \ apache \ www \ test. php on line 7 Warning: mysql_connect () [function. mysql-connect]: [2002] php_network_getaddresses: getaddrinfo failed: Unknown host. (Trying to connect via tcp: // loaclhost: 3306) in D: \ server \ apache \ www \ test. php on line 7 Warning: mysql_connect () [function. mysql-connect]: php_network_getaddresses: getaddrinfo failed: Unknown host. In D: \ server \ apache \ www \ test. php on line 7 Warning: mysql_query () expects parameter 2 to be resource, boolean given in D: \ server \ apache \ www \ test. php on line 9 Warning: mysql_query () expects parameter 2 to be resource, boolean given in D: \ server \ apache \ www \ test. php on line 11 Warning: mysql_fetch_assoc () expects parameter 1 to be resource, null given in D: \ server \ apache \ www \ test. php on line 12 has been installed successfully?
I have been searching for the reason for a long time. I am not looking for any help. I am very grateful to anyone who can help me analyze the cause !!!!!
------ Solution --------------------
Mysql_connect (), database connection error
PHP code
$ Conn = mysql_connect ('loaclhost', 'root', '000000') or die ("can not connect Mysql Server"); mysql_select_db ("database name", $ conn ); // your database name is use msg? $ SQL = "select * from denglu where id = $ id"; $ var = mysql_query ($ SQL );
------ Solution --------------------
If (isset ($ _ REQUEST ['id']) {
$ Id = $ _ REQUEST ['id'];
If ($ id = 0 ){
Exit ("The parameter is wrong! ");
}
}
Echo $ id;
@ $ Conn = mysql_connect ('localoss', 'root', '000000') or die ("Connection Failure:". mysql_errno ());
Mysql_select_db ('MSG ', $ conn );
Mysql_query ("set names ''utf8 ");
$ SQL = "select * from denglu where id = $ id ";
$ Result = mysql_query ($ SQL );
While ($ rs = mysql_fetch_assoc ($ result )){
Var_dump ($ rs );
}
Enter url: localhost/index. php? Id = 2 to get the id
------ Solution --------------------
$ Id = isset ($ _ GET ["id"])? $ _ GET ["id"]: 0;