Php receives the id in the address bar. how can this problem be solved?

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.