Hi
I'm attempting to connect a survey up to a db. Everything was working fine until I added a comment box. Now I'm getting the following error. Hope someone can help.
Error:
Query failed: Duplicate entry '0' for key 1
survey code:
<html>
<head>
<title>NCI Process - An InDepth Analysis</title>
<style type="text/css">
<!-- .style1
{
font-family: "Times New Roman", Times, serif;
font-weight: bold;
font-size: 18px;
}
.style11 {font-size: 16px}
--> </style>
</head>
<body>
<link href="styles.css" rel="stylesheet" type="text/css">
<div align="center">
<p class="style1"><img src="nci5.gif" width="140" height="121"></p>
<p class="style1">Please answer all questions as honestly as possible! </p></div>
<form action="surveyconnect.php" method="post"><div align="center"><table border="1">
<tr>
<td><div align="left" class="style11">What gender are you?</div></td>
<td colspan="5"><div align="left" class="style11">
<input type="radio" name="gender" value="1">
Male |
<input type="radio" name="gender" value="2">
Female</div></td>
</tr>
<tr>
<td><div align="left" class="style11">What is your relationship with the college?</div></td>
<td colspan="5"><div align="left" class="style11">
<input type="radio" name="relationship" value="1">
Lecturer |
<input type="radio" name="relationship" value="2">
Marketing</div></td>
</tr>
<tr>
<td>
<div align="left" class="style11">Are you aware of how courses are currently introduced?</div></td>
<td colspan="5"><div align="left" class="style11">
<div align="left">
<input type="radio" name="awareness" value="1">
Yes |
<input type="radio" name="awareness" value="2">
No
</div></td>
</tr>
<tr>
<td>
<div align="left" class="style11">Do you feel you should be included more in relation to how courses are introduced?
</div>
</td>
<td colspan="5"><div align="left" class="style11">
<div align="left">
<input type="radio" name="inclusion" value="1">
Yes |
<input type="radio" name="inclusion" value="2">
No
</div></td>
</tr>
<tr>
<td><div align="left" class="style11">Would it be a good idea to get feedback from students about potentially new courses?
</div></td>
<td colspan="5"><div align="left" class="style11">
<div align="left"> <input type="radio" name="studentfeedback" value="1">
Yes |
<input type="radio" name="studentfeedback" value="2">
No
</div></td>
</tr>
<tr>
<td><div align="left" class="style11">How satisfied are you in relation to how courses are currently introduced? (1=not very, 4=very) </div></td>
<td><div align="left" class="style11">
<input type="radio" name="satisfaction" value="1" />
1</div></td>
<td><div align="left" class="style11">
<input type="radio" name="satisfaction" value="2" />
2</div></td>
<td><div align="left" class="style11">
<input type="radio" name="satisfaction" value="3" />
3</div></td>
<td><div align="left" class="style11">
<input type="radio" name="satisfaction" value="4" />
4</div></td> </tr> <tr>
<td><div align="left" class="style11">Additional Comments:</div></td>
<td colspan="5"><div align="left" class="style11">
<div align="left">
<textarea rows="3" cols="20"></textarea><br />
</div></td>
</tr>
</table>
<br />
<input type="submit" value="Submit" name="Submit" />
<input name="reset" type="reset" value="Reset" />
<br>
<br>
</div>
</form>
</body>
</html>
surveyconnect.php
<?PHP
require "db_survey.php";
$link = mysql_connect("localhost","sea10004_jack4","haha","sea10004_survey");
// connection to databas
if ( !$link ) exit ( "Database error: " . mysql_error() );
mysql_select_db ( $db_name, $link );
// selects database name
$gender = $_POST ['gender'];
$relationship = $_POST ['relationship'];
$awareness = $_POST ['awareness'];
$inclusion = $_POST ['inclusion'];
$studentfeedback = $_POST ['studentfeedback'];
$satisfaction = $_POST ['satisfaction'];
$comments = $_POST ['comments'];
$result = mysql_query( "INSERT INTO onlinesurvey (gender, relationship, awareness, inclusion, studentfeedback, satisfaction, comments) VALUES('$gender', '$relationship','$awareness','$inclusion','$studentfeedback','$satisfaction','$comments')", $link );
// insert post into db
if( !$result ) exit ( "Query failed: " . mysql_error() );?>
<html>
<head>
<title>Results</title>
<style type="text/css">
<!--
.style1
{
font-size: 24px;
font-weight: bold;
}
-->
</style>
</head>
<body>
<div align="center" class="style1">
<p> </p>
<p> </p>
<p>Thank you for taking the time to complete the survey.</p>
<p> </p>
<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="103" height="24">
<param name="movie" value="button1.swf">
<param name="quality" value="high">
<embed src="button1.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="103" height="24" ></embed>
</object>
</p>
</div>
</body>
</html>