Let's take a look at the situation!

Source: Internet
Author: User
Let's take a look at the situation! This is a program for creating a personal warehouse. it's okay to test it separately.
It is intended to run directly when the user's personal center is loaded,
The program runs successfully, but the program in the if statement is executed every time the interface is refreshed.

Function _ order_given (){
$ Uid = $ this-> checked_login ();
$ Sql1 = "select uid from order_given where uid = '$ uid '";
$ Usergiven = $ this-> App-> find ($ sql1 );
// Determine whether the current user ID exists in the personal warehouse table
$ Row = mysql_num_rows ($ usergiven );
If ($ row = 0) // The User ID does not exist in the table to create the personal repository data
{
$ Sqlg1 = "insert into order_given (goods_sn, pifa_price, is_on_sale, is_jifen) select goods_sn, pifa_price, is_on_sale, is_jifen from gz_goods ";
$ Sqlg2 = "UPDATE order_given SET uid = '$ uid' WHERE uid = '0 '";
$ This-> App-> query ($ sqlg1 );
$ This-> App-> query ($ sqlg2 );

}
}


Reply to discussion (solution)

Give yourself a sofa and wait for the great gods to pass!

Since there is no problem with testing separately, it is a problem with the joint environment.
Why don't you go to other places to find the reason, just hold on to this function?

Add
Echo $ sql1; exit; // sometimes the content to be viewed is not a string. use print_r ($ xxx );
Run the command to check whether the SQL is correct. it may be that the check user does not get the correct uid.
You can use this method to check the differences between the printed content and the expected content.

This statement:
Int mysql_num_rows (resource $ result)
The parameter in the brackets is the resource handle.
$ Usergiven = $ this-> App-> find ($ sql1); does this statement return the resource type?
It is best to publish the complete class, app in the class, and find program.

If you refresh and insert one more record.
The problem should be here
$ Sql1 = "select uid from order_given where uid = '$ uid '";
$ Usergiven = $ this-> App-> find ($ sql1 );
// Determine whether the current user ID exists in the personal warehouse table
$ Row = mysql_num_rows ($ usergiven );
If ($ row = 0) // The User ID does not exist in the table to create the personal repository data

Print $ uid, $ sql1, and $ row.

Thank you for solving the problem.

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.