No data can be received after the password is changed

Source: Internet
Author: User
After the password is changed, no data is received. The final output result is an account or the password cannot be blank.

There is no problem when adding data, but there is a problem when changing the password.
When var_dump () is used for printing, the user name can be printed without submitting a form.




$ Id = (int) $ input-> get ('id ');
// If the user name is edited, retrieve the user name
If ($ id> 0 ){
$ SQL = "SELECT * FROM adminuser WHERE id = '{$ id}' limit 1 ";
$ EditUser = $ db-> get ($ SQL );
If (! $ EditUser ){
Echo "account does not exist"; exit;
}
}
// Add and modify functions here
$ Do = $ input-> get ('Do ');
If ($ do = 'save '){
$ Username = $ id> 0? $ EsitUser ['username']: trim ($ input-> post ('Username '));
$ Passwd = trim ($ input-> post ('passwd '));
// Cannot be blank
If (empty ($ username) | empty ($ passwd )){
Echo "account or password cannot be blank"; exit;
}
// The user name cannot be repeated.
$ SQL = "SELECT * FROM adminuser WHERE username = '{$ username}' limit 1 ";
$ Row = $ db-> get ($ SQL );
If (! $ Row ){
// Execute the insert action
$ SQL = sprintf ("INSERT INTO adminuser (username, passwd) value ('% s',' % s')", $ username, $ passwd );
$ Db-> query ($ SQL );
Header ("location: adminuser. php ");
Exit;
} Elseif ($ id> 0 ){
$ SQL = sprintf ("UPDATE adminuser set passwd = '{$ passwd} 'Where id =' {$ id }'");
$ Db-> query ($ SQL );
Header ("location: adminuser. php ");
} Else {
Echo "the user name already exists"; exit;
}
}





Reply to discussion (solution)

$ Id?
You did not retrieve the corresponding id when inserting a new user.
So where does the id used for modification come from?

$ Id?
You did not retrieve the corresponding id when inserting a new user.
So where does the id used for modification come from?


$ Id is the name of the client's cookie. it is obtained by calling $ __get in the input class.
$ Id indicates whether a user has logged on. you can obtain the id of the current login as long as you log on.

When a user is added, the user only jumps back to the previous management page.

Action = "..... ";, And the id of the current login user will be obtained during the modification and submitted together

At least in the code snippet you posted, you did not see your assignment process.

$ SQL = sprintf ("INSERT INTO adminuser (username, passwd) value ('% s',' % s')", $ username, $ passwd );
$ Db-> query ($ SQL );
Header ("location: adminuser. php ");
Exit;
Then it ends, and no id is obtained.

You call $ __get in the input class to obtain
And action = "..... ";, And the id of the current login user will be obtained during the modification and submitted together
Obviously, your form is in get mode.
Therefore, any url parameter on the action will be invalid due to url restructuring at the time of submission.
That is, you have not submitted the id at all.

// The user name cannot be repeated.
$ SQL = "SELECT * FROM adminuser WHERE username = '{$ username}' limit 1 ";
$ Row = $ db-> get ($ SQL );

It is determined whether the user name is repeated when data is inserted. if condition judgment is incorrect.

At least in the code snippet you posted, you did not see your assignment process.

$ SQL = sprintf ("INSERT INTO adminuser (username, passwd) value ('% s',' % s')", $ username, $ passwd );
$ Db-> query ($ SQL );
Header ("location: adminuser. php ");
Exit;
Then it ends, and no id is obtained.

You call $ __get in the input class to obtain
And action = "..... ";, And the id of the current login user will be obtained during the modification and submitted together
Obviously, your form is in get mode.
Therefore, any url parameter on the action will be invalid due to url restructuring at the time of submission.
That is, you have not submitted the id at all.


Sorry, I didn't make it clear.
The form submission process is like this. The post method is used for submission, but when you click submit, it is in action = "? Do = save & "Added these elements
Then, the get method is used to obtain the value above the URL to determine whether there is any point to submit and then execute the add data, and It is used to identify data changes.
I was a little confused when I was Debugging. I knew that it was caused by the failure to submit and receive the id value. I then combined my analysis with the analysis of the great god.
If you have any unclear expressions, please forgive me. I just learned about it for about two months. I also have a lot of knowledge points that are not very clear. I also hope you will forgive me.

// The user name cannot be repeated.
$ SQL = "SELECT * FROM adminuser WHERE username = '{$ username}' limit 1 ";
$ Row = $ db-> get ($ SQL );

It is determined whether the user name is repeated when data is inserted. if condition judgment is incorrect.



$ SQL = "SELECT * FROM adminuser WHERE username = '{$ username}' limit 1 ";
$ Row = $ db-> get ($ SQL );
If (! $ Row ){
// Execute the insert action
$ SQL = sprintf ("INSERT INTO adminuser (username, passwd) value ('% s',' % s')", $ username, $ passwd );
$ Db-> query ($ SQL );
Header ("location: adminuser. php ");
Exit;
} Else {
Echo "the user name already exists"; exit;
}
This code, I think, first queries the database, then retrieves a row from the result set returned by the database, and uses if to determine whether it is true. if it is true, it indicates that there is a data with such a name in the database. a duplicate prompt is displayed. Otherwise, a data record is added.
There are also various problems in writing, and I hope that God can point out and give some guidance.

The problem is solved. when passing data in the from form, only the value is passed in the past, but the value name is not declared in the action, problems that occur when the form data is not received

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.