deny multiple entries in mysql database
Posted: Tue Aug 05, 2003 9:54 am
I have a page containing a series of survey question that when posted is put into a mysql database. My url for this page will always include a unique variable of a user id number.
My question is, how do I keep users from taking the survey twice?
My thoughts were to check to see if the user id already existed in the database. If yes, echo back the message that the survey has already been completed, and to contact my company if this was not correct. else, enter the survey info into the database.
I have tried a number of different things and cannot seem to get the syntax correct.
Here is my code for the survey... can anyone please help me?
(survey.php)
(add_client.php)
My question is, how do I keep users from taking the survey twice?
My thoughts were to check to see if the user id already existed in the database. If yes, echo back the message that the survey has already been completed, and to contact my company if this was not correct. else, enter the survey info into the database.
I have tried a number of different things and cannot seem to get the syntax correct.
Here is my code for the survey... can anyone please help me?
(survey.php)
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Survey</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="add_survey" method="post" action="add_client.php">
<table width="772" border="1" align="center" bgcolor="#FFFFE6">
<tr>
<td width="762" height="1146" align="left"> <font size="3" face="Arial, Helvetica, sans-serif">
</font>
<table width="97%">
<tr>
<td height="21"><div align="center"><font size="3" face="Arial, Helvetica, sans-serif"><img src="images/letterhead.gif" width="682" height="166"><br>
<hr width="90%">
<font size="2">
<?php
echo "
<b>Welcome $name and thank you for taking part in our survey!</b><br>
Here at *******, we are committed to providing the best service we can. The purpose for our survey is for you to instruct us on how we can improve and make our services more beneficial for you.
Please choose one answer from each of the following 7 questions. Then click submit at the bottom and you will automatically be entered into our drawing for 3 months of free service. Winners will be notified by the end of October.
";
?>
<br>
</font><font size="3" face="Arial, Helvetica, sans-serif"> <font color="#FF0000">
<?php
if ($_GET['id']) {
echo "<input type='hidden' name='client_id' value='".$_GET['id']."'>";
}
else {
echo "We did not get your <b>USER ID.</b> This is required to enter the contest.<br>";
// header ("Location: http://localhost/In_Progress/survey/sur ... ?id=123456");
}
?>
<?php
if ($_GET['name']) {
echo "<input type='hidden' name='client_name' value='".$_GET['name']."'>";
}
else {
echo "We did not get your <b>NAME.</b> This is required to enter the contest.<br><br>";
// header ("Location: http://localhost/In_Progress/survey/sur ... ?id=123456");
}
?>
</font></font></font>
<hr align="center" width="90%">
</div></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td width="53%"><font color="#000000" size="2" face="Arial, Helvetica, sans-serif">1.
</font><font color="#0000FF" size="3" face="Arial, Helvetica, sans-serif">The
method of communication that I prefer between myself and *****is by:</font> </td>
</tr>
<tr>
<td><table width="200">
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="method_of_communication" value="Email only">
Email only</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="method_of_communication" value="Phone">
Phone</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="method_of_communication" value="A secured website">
A secured website</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="method_of_communication" value="Newsletters in the mail">
Newsletters in the mail</label>
</font></td>
</tr>
</table></td>
</tr>
<tr>
<td height="21"></td>
</tr>
<tr>
<td height="21"><font size="2" face="Arial, Helvetica, sans-serif">2.
<font color="#0000FF" size="3">Overall, the level of customer service
I receive from ******* ******* is:</font></font></td>
</tr>
<tr>
<td><table width="200">
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="level_of_customer_service" value="Excellent">
Excellent</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="level_of_customer_service" value="Very good">
Very good</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="level_of_customer_service" value="Good">
Good</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="level_of_customer_service" value="Fair">
Fair</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="level_of_customer_service" value="Poor">
Poor</label>
</font></td>
</tr>
</table></td>
</tr>
<tr>
<td height="21"> </td>
</tr>
<tr>
<td height="21"><font size="2" face="Arial, Helvetica, sans-serif">3.
<font color="#0000FF" size="3">Generally, the time of day I'm available
to speak with my client advocate is:</font></font></td>
</tr>
<tr>
<td><table width="200">
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="speak_with_my_client" value="Morning">
Morning</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="speak_with_my_client" value="Afternoon">
Afternoon</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="speak_with_my_client" value="Evening">
Evening</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="speak_with_my_client" value="Weekends are better">
Weekends are better</label>
</font></td>
</tr>
</table></td>
</tr>
<tr>
<td height="21"> </td>
</tr>
<tr>
<td height="21"><font size="2" face="Arial, Helvetica, sans-serif">4.
<font color="#0000FF" size="3">The answers I receive in response
to my questions to ******* ******* are:</font></font></td>
</tr>
<tr>
<td><table width="200">
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="response_to_my_questions" value="Very informative">
Very informative</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="response_to_my_questions" value="Fairly informative">
Fairly informative</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="response_to_my_questions" value="Uninformative">
Uninformative</label>
</font></td>
</tr>
</table></td>
</tr>
<tr>
<td height="21"> </td>
</tr>
<tr>
<td height="21"><font size="2" face="Arial, Helvetica, sans-serif">5.
<font color="#0000FF" size="3">My client advocate is available by
phone and if I leave a voicemail, my advocate promptly returns my
call.</font></font></td>
</tr>
<tr>
<td><table width="200">
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="available_by_phone" value="Strongly agree">
Strongly agree</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="available_by_phone" value="Agree">
Agree</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="available_by_phone" value="Not sure">
Not sure</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="available_by_phone" value="Disagree">
Disagree</label>
</font></td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<label>
<input type="radio" name="available_by_phone" value="Strongly disagree">
Strongly disagree</label>
</font></td>
</tr>
</table></td>
</tr>
<tr>
<td height="18"> </td>
</tr>
<tr>
<td height="18"><font size="2" face="Arial, Helvetica, sans-serif">
6. <font color="#0000FF" size="3">The emails I send to *******
******* are responded to within 24 hours.</font></font></td>
</tr>
<tr>
<td height="117"> <table width="200">
<tr>
<td><label>
<input type="radio" name="emails_i_send" value="Strongly agree">
Strongly agree</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="emails_i_send" value="Agree">
Agree</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="emails_i_send" value="Not sure">
Not sure</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="emails_i_send" value="Disagree">
Disagree</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="emails_i_send" value="Strongly disagree">
Strongly disagree</label></td>
</tr>
</table></td>
</tr>
<tr>
<td height="21"> </td>
</tr>
<tr>
<td height="21"><font size="2" face="Arial, Helvetica, sans-serif">7.
<font color="#0000FF" size="3">Fill in the blank The value of results
(deletions) I get from ******* *******'s services is _________
my monthly retainer of $35.</font></font></td>
</tr>
<tr>
<td height="47"> <table width="200">
<tr>
<td><label>
<input type="radio" name="value_of_results" value="Above">
Above</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="value_of_results" value="Equal to">
Equal to</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="value_of_results" value="Below">
Below</label></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><p><font color="#0000FF" size="3" face="Arial, Helvetica, sans-serif">If
you have additional comments or suggestions on how we can improve,
you may enter them here. Please limit your feedback to 256 characters.
All comments will be reviewed over the next couple of months so
please do not submit any questions regarding your case in this
field. Direct any questions to your client advocate.</font></p>
<p><font color="#0000FF" size="3" face="Arial, Helvetica, sans-serif">
<textarea name="textarea" cols="50" rows="5"></textarea>
</font></p></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<input type="submit" value="Submit Survey Results" name="Submit Survey Results">
</font></td>
</tr>
</table></td>
</tr>
</table>
</form>
</body>
</html>(add_client.php)
Code: Select all
<?
//Database user info
$username="";
$password="";
$database="";
$server="";
//Survey Values
$method_of_communication = $_POST['method_of_communication'];
$level_of_customer_service = $_POST['level_of_customer_service'];
$speak_with_my_client = $_POST['speak_with_my_client'];
$response_to_my_questions = $_POST['response_to_my_questions'];
$available_by_phone = $_POST['available_by_phone'];
$emails_i_send = $_POST['emails_i_send'];
$value_of_results = $_POST['value_of_results'];
$client_id = $_POST['client_id'];
$client_name = $_POST['client_name'];
$textarea = $_POST['textarea'];
//Connect to database
mysql_connect($server,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
//Insert values from survey_add.htm variable
$query = "INSERT INTO results (method_of_communication, level_of_customer_service, speak_with_my_client, response_to_my_questions, available_by_phone, emails_i_send, value_of_results, client_id, client_name, textarea) VALUES ('$method_of_communication', '$level_of_customer_service', '$speak_with_my_client', '$response_to_my_questions', '$available_by_phone', '$emails_i_send', '$value_of_results', '$client_id', '$client_name', '$textarea')";
//run query variable
mysql_query($query);
//print errors if any on page
echo mysql_error();
//disconnect from the database
mysql_close();
?>