Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form submits after the error 1

Status
Not open for further replies.

DaSe

Programmer
Feb 14, 2008
149
GB
Hi guys,
After a simple 'if' condition the form returns an error as expected when user's input is incorrect - the problem is the user's wrong input is being also inserted into the database. The insertion should be after 'else' condition. Thanks for any comments.
 
Without seeing code, there's no way to know for sure what is wrong.

I could venture a suggestion, assuming this is all done in PHP, your else statement would need to encompass all the code that inserts the information into the database.

Code:
if(condition)
{
report error
}
else{
insert to DB
}

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
HI Vacunita,
Yes it's php and the condition is excactly as you wrote in the code. So insertion should only take place after 'else'. But when first 'if' reports the error the insertion from 'else' statement takes place somehow.
 
Again, without seeing any code, there's no way for me to tell what may be wrong.

In other words post the relevant parts of the offending code here. Remember to use [ignore]
Code:
[/ignore] tags to surround your code.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Hi Phil ,looks like the problem turned out to be with separation the ('if' and 'mysql_num_rows') function before the table insertion query which was supposed to be placed after 'else' condition.Thank you for the help for now.
 
Glad you sorted it out. Not sure what the mysql_num_rows has to do with it but if it works now that's good.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hi , the conditional 'if' with mysql_num_rows was parsed together with table insertion query.
------------------
if (mysql_num_rows(query1)>0) { // here it goes error output;
$tableInsertion = "INSERT INTO......// etc. ; } else { //code after submission... }

-------------------------
looks like it should be this way :

if (mysql_num_rows(query1)>0) { // here it goes error output; } else {
$tableInsertion = "INSERT INTO......// etc. //code after submission... }

 
Just like your suggestion above. Thanx for now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top