views:

50

answers:

1

Hi guys, I am having endless troubles with duplicate entries, so I need to check the database, and if a user has already entered that day, their entry will not be submitted and they will be redirected to a landing page that tells them they have already entered that day, and that they may only enter again tomorrow.

The field I would like to check is the id_number field in the database, since each user has a unique id number, so basically, if a user with the same id number submitted on the same date they should be redirected to a landing page, how would I go about doing this? I am still new to a lot of this, so please be forgiving.

Thanx in advance.

A: 

before you submit your sql query to add a new record you can read the DB first to make sure the ID is not already in there. Get the users id into a variable and do this query.

$query = "select * from mytable where `id` = '$id'";
$result = mysql_query($query);

then you can count the number of records returned and do different things depending on the result, checking that its zero before adding them. If its not zero then redirect.

if(mysql_num_rows($result) > 0)
{
 //add them
}
else
{
 //redirect them
}

Hope this helps you out

DrLazer
I think you mean mysql_num_rows($result) == 0
Matt Ellen
That looks great, I'll try that quick. How would I check if that specific id number was inserted on the same date? Because they basically need to still be able to submit a form the next day, since each user is only allowed one submission per day... would it maybe look something like this? $query = "select * from mytable where `id` = '$id'
select * from mytable where `id` = '$id' AND `date` = '$date'
Ergec
Awesome, thanx.
I seem to be getting this error: Fatal error: Can't use function return value in write context in /usr/wwws/users/ratesg/insurance/funeralplan/funeral-postpage.php on line 9What could be causing it?
lol - could be anything. post me line 9
DrLazer
Nvm, got it to work... idiot mistake! haha Thanx guys!