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.