PDA

View Full Version : validate data with a database


FishMA
12-09-2009, 05:45 AM
I am new to this forum. I use dw8 infrequently, but I am working with it now on a project. In this project, commercial fishermen can transfer some of their fish quota to another fisherman. The fisherman must login to post transactions on the site. There are several tables on the server using a mySQL a database. Login is validated with a user table.

Once logged-in, the fisherman selects what action he wishes to conduct and his login username is set as a session variable. If he wishes to transfer quota to another fisherman, then he must enter the username of the fisherman which will receive the quota, along with the amount of quota and species of fish.

To avoid having mis-typed usernames entered into the database, messing up the transfer, I wish to validate that the second fisherman's username is valid and is stored in the database. If it is not valid then he would receive a message asking him to check is spelling.

I cannot figure out how to accomplish this validation against the database with DW8. It seems so simple and it may simply be my lack of use of the program, but I need help on this. I hope my description is clear enough for some positive assistance.

edbr
12-09-2009, 06:03 AM
you could check with a conditional from the form say the field is passed as $_POST['name']
if ( $_POST['name'] !=$row[''name] {
echo "no such name is registered":
}
else {
continue with your stuff
}

Corrosive
12-09-2009, 06:20 AM
I would double this up with a form select generated with options generated from the names in the database. This way they will start typing and get a prompt for the names in there. Not a necessity but it will help.

FishMA
12-12-2009, 04:26 AM
edbr and Corrosive

Thanks for the replies. I tried posting this earlier but it did not seem to work. I have been out of town on business. As I said I thought that I posted ealier, but this evening is my son's 21st birthday and in the US that means he can legally drink the drink that he has enjoyed for the last couple of years anyway. So I just have returned from the tavern. But I left him in good hands.

Below is my code. This does not work so if you have any suggestions please make suggestions.


$newowner = $_POST['newownerID'];
$Result2 = "SELECT ID FROM individuals Where ID = $newowner" or die(mysql_error());
if ($newowner != $Result2) {
header ("Location: qs_newuser-doesnotexist.php");
exit;
}