Jump to content

INSERTING VALUES problem


franknu

Recommended Posts

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

 


<?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>

 

Link to comment
https://forums.phpfreaks.com/topic/55577-inserting-values-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.