I am trying to input data from a form into a database for a simple guestbook. I can get it to enter the first entry but thats it. I keep getting the error "Duplicate entry '0' for key 1". I would be extremely greatful if someone could explain to me what I might be doing wrong. I am using a mySQL db. The code that I wrote is as follows:
[indent]
<?php
$dateTime = date("F j, Y, g:i a");
require('../connections/conn_guestbook_db.php');
if(isset($_POST['frmName'])):
if( $_POST['frmAction'] == 'addPost' ) {
$frmName = $_POST['frmName'];
$frmEmail = $_POST['frmEmail'];
$frmWebSite = $_POST['frmWebSite'];
$frmMessage = $_POST['frmMessage'];
$frmName = strip_tags($frmName);
$frmEmail = strip_tags($frmEmail);
$frmWebSite = strip_tags($frmWebSite);
$frmMessage = strip_tags($frmMessage);
$sql = "INSERT INTO tbl_guestbook SET
name='$frmName',
email='$frmEmail',
website='$frmWebSite',
text='$frmMessage',
date='$dateTime'";
if(@mysql_query($sql)) {
echo "Your post has been added. <a href='guest_book.php'>Click here</a> to view it now.";
} else {
echo "<p>Error adding new post: " . mysql_error() . "</p>";
}
}
?>
<?php else: ?>
<form name="addPost" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<p>Your Name:</p>
<p><input name="frmName" type="text" size="40" maxlength="255" class="textBox" /></p>
<p>Your Email:</p>
<p><input name="frmEmail" type="text" size="40" maxlength="255" class="textBox" /></p>
<p>Your Web Site:</p>
<p><input name="frmWebSite" type="text" size="40" maxlength="255" class="textBox" /></p>
<p>Your Message:</p>
<p><textarea name="frmMessage" cols="39" rows="4" class="textBox"></textarea></p>
<p><input name="frmAction" type="hidden" value="addPost" />
<input name="submit" type="submit" value="Submit" class="formButton" />
<input name="reset" type="reset" value="Reset" class="formButton" />
</p></form>
<?php endif; ?>
[/indent]
The order for the db is guestbookID, name, email, website, text, date. Thanks for the help
very confused!
Started by magiclifer, Jan 16 2006 04:12 PM
2 replies to this topic
#1
Posted 16 January 2006 - 04:12 PM
#2
Posted 16 January 2006 - 04:49 PM
Is your id auto_increment? and is it used as unique? If other fields are unique youll run into that problem.
#3
Posted 16 January 2006 - 06:01 PM
well i feel like a complete dork
. i think i need a break. thanks for your help.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
