954,206 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Validating data in a field to a existing data stored in the database

Hello guys!

I am editing a program regarding billing system done in Php and MySQL and generated using the Code Charge Studio. I have problem in validating a newly entered data. What i want is to check if the billing statement number is existing or not and will not saved after validation. Saving will be done after it has pass all the validation and when save button is click. If it is existing, there will be a message displaying that it will not accept the newly entered data for the fact that it is stored in the database. If the billing statement number is available, it will go next page and later will be saved.

Also please help me on how to erase the data stored in a variable to prevent inserting to database when refresh and Back button is pressed. please help.


Thanks.....

dudegio
Junior Poster in Training
66 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

after pressing submit validate fields i.e.

if ($textboxvalue == "") {

Fungus1487
Posting Pro in Training
459 posts since Apr 2007
Reputation Points: 66
Solved Threads: 56
 

after pressing submit validate fields i.e.

if ($textboxvalue == "") {
  // go back and error
}

then perform an sql request (im guessing you using a database)

"SELECT * FROM databasename WHERE statementnumber = " . $statementnumber . ";";

then check if a result is returned.
if one is then you know you have a result in the database with this number and you can refer the user to whichever page required.

also you will not need to empty any variables as you will always perform this check and if there is a value and they press back it will falg a record is already in the database. Hope this helps

Fungus1487
Posting Pro in Training
459 posts since Apr 2007
Reputation Points: 66
Solved Threads: 56
 

no idea why my first comment is there ?

Fungus1487
Posting Pro in Training
459 posts since Apr 2007
Reputation Points: 66
Solved Threads: 56
 

$fldbsnum = get_param("bsnum");
echo "bsnumber: $fldbsnum";
$queryvalidate = mysql_query("select (bs_number) from billingstatementhistory where bs_number = $fldbsnum");
echo "result: $queryvalidate";

if (mysql_query($queryvalidate) == true) {
echo "The billingstatement exists";
}
else
{
echo"pass";
}

Hello! here is my test code in validating for the existing bsnum. it does not evaluate the first condition even the newly entered bsnum is existing. pls help me........

The output is:

bsnumber: 000001
result: Resource id #13
pass

dudegio
Junior Poster in Training
66 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

Thank you very much for help..... I have made solutions based on the your suggested query.

dudegio
Junior Poster in Training
66 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You