INSERTING VALUES
Posted: Thu Jun 14, 2007 9:22 am
Ok. I want to insert values into a table my problem is that
I am gettin this error: Duplicate entry '' for key 1
I also want to insert some other values like a session and the date with the time
please help here is my code
I am gettin this error: Duplicate entry '' for key 1
I also want to insert some other values like a session and the date with the time
please help here is my code
Code: Select all
<?PHP
$BusinessName = addslashes($_POST['BusinessName']);
$date= addslashes($_POST['date']);
$from = addslashes($_POST['from']);
$status= addslashes($_POST['status']);
$subject= addslashes($_POST['subject']);
$message= addslashes($_POST['message']);
if(isset($_SESSION['BusinessName'])){
$query = "INSERT INTO `messages` (`BusinessName`,`date`,`from`,`status`,`subject`,`message`)
VALUES ('".$_SESSION['BusinessName']."','".$date."','".$from."', '".$status."','".$subject."',
'".$message."')";
$result = mysql_query($query);
echo mysql_error();
if($result)
{
echo mysql_affected_rows()." .Your Message have been sent. We will get back to you. <br>";
}
}
?>
<center>
<?
$_SESSION['BusinessName'];
?>
<? echo'<form action="'. $_SERVER['PHP_SELF'].'" method="post" >'; ?>
<table width="390" border="1" bordercolor="#FFFFFF">
<tr>
<td width="92" bgcolor="#CCCCCC"><strong>From</strong></td>
<td width="282"><? echo'<input name="from" type="text" size="60">'; ?></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><strong>Subject </strong></td>
<td><? echo'<input name="textfield2" type="subject" size="60">'; ?></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><strong>Body</strong></td>
<td><p>
<? echo'<textarea name="message" cols="75" rows="10"></textarea>'; ?>
</p>
<p> </p></td>
</tr>
<tr>
<td> </td>
<td bgcolor="#EFEFEF"><div align="right">
<table width="200" border="0" bgcolor="#EFEFEF">
<tr>
<td><? echo'<input type="submit" name="Submit2">'; ?></td>
<td><? echo'<input type="submit" name="Submit" >'; ?></td>
</tr>
</table>