Questions about functions

Source: Internet
Author: User
Newbie asks function question functiondel_news ($ nid) {$ selnews_str = & quot; selectn_class, n_image, n_pname, n_pathfromnewswheren_id = & quot;. $ nid; newbie asks function question
Function del_news ($ nid)
{
$ Selnews_str = "select n_class, n_image, n_pname, n_path from news where n_id =". $ nid;
$ Selnews_result = mysql_query ($ selnews_str, $ con );
$ Selnews_row = mysql_fetch_array ($ selnews_result );
$ Class = $ selnews_row ["n_class"];

If ($ selnews_row)
{
Echo ("content available ");
}
Else
{
Echo ("no content ");
}

Echo ($ nid );
}

If ($ _ GET ["nid"]! = Null | $ _ GET ["nid"]! = "")
{
Del_news ($ _ GET ["nid"]);
}

The above is the code. if the code in del_news is put out, it will show that there is content. if it is called in the function, there will be no content. the parameter is correct. Why?

------ Solution --------------------
PHP code
Function del_news ($ nid) {}$ selnews_str = "select n_class, n_image, n_pname, n_path from news where n_id = ". $ nid; $ selnews_result = mysql_query ($ selnews_str, $ con); $ selnews_row = mysql_fetch_array ($ selnews_result); $ class = $ selnews_row ["n_class"]; if ($ selnews_row) {echo ("content available") ;}else {echo ("no content") ;}echo ($ nid); if ($ _ GET ["nid"]! = Null | $ _ GET ["nid"]! = "") {Del_news ($ _ GET ["nid"]);}
------ Solution --------------------
What is the error message?

Guess:
It may be a function scope issue. Your database connection handle is global. Operations on data in the function are considered to be not connected to the database.
------ Solution --------------------
$ Selnews_result = mysql_query ($ selnews_str, $ con );
$ Conn is a local variable.
Global is not declared.
This may be the cause.
Add the database connection handle to the function.

------ Solution --------------------
$ Selnews_result = mysql_query ($ selnews_str );
------ Solution --------------------
Execution order! How do you call the function!
------ Solution --------------------
You can solve this problem. There are also moderators.

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.