DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   Validating data in a field to a existing data stored in the database (http://www.daniweb.com/forums/thread81266.html)

dudegio Jun 18th, 2007 6:55 am
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.....

Fungus1487 Jun 18th, 2007 8:39 am
Re: Validating data in a field to a existing data stored in the database
 
after pressing submit validate fields i.e.

if ($textboxvalue == "") {

Fungus1487 Jun 18th, 2007 8:44 am
Re: Validating data in a field to a existing data stored in the database
 
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 Jun 18th, 2007 8:44 am
Re: Validating data in a field to a existing data stored in the database
 
no idea why my first comment is there ?

dudegio Jun 18th, 2007 10:35 pm
Re: Validating data in a field to a existing data stored in the database
 
$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 Jun 19th, 2007 1:49 am
Re: Validating data in a field to a existing data stored in the database
 
Thank you very much for help..... I have made solutions based on the your suggested query.


All times are GMT -4. The time now is 8:24 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC