Error with Inserting Data Into a Database Using a HTML Form
<p>I am attempting to create a website in which an admin can view details about customers who shop at the store. The homepage lists the names of all of the customers, and when clicked, each name is directed to a page called CustomerDetails.php which provides more details about that particular customer. I am attempting to write some code which allows the admin to add notes to a particular customer. The two tables are as follows: </p>

<pre><code> CREATE TABLE PHPNotes(
 NoteID INT,
 NoteContent VARCHAR(100) NOT NULL,
 CustomerID INT,
 FOREIGN KEY (CustomerID) REFERENCES CustomerEnrolment(CustomerID),
 PRIMARY KEY(NoteID))ENGINE=InnoDB;

 CREATE TABLE CustomerEnrolment(
 CustomerID INT,
 Name VARCHAR(30),
 Email VARCHAR(30),
 PhotoURL VARCHAR(30),
 PRIMARY KEY(CustomerID)) ENGINE=InnoDB;
</code></pre>

<p>I am attempting to take data from a form (shown below) and insert this particular data into the database. However I am told there are errors with the code that I have written.</p>

<pre><code> &lt;?php 

 $Name = $_GET['Name']; 
 $CustomerID = $_GET['CustomerID'];
 $sql1 ="SELECT * FROM CustomerEnrolment WHERE CustomerID='$CustomerID'";
 $sql2 ="SELECT c.*, e.CustomerID FROM CustomerNotes c, CustomerEnrolment e WHERE e.CustomerID=n.CustomerID AND Name='$Name'" ;


 if(! get_magic_quotes_gpc() ) {
    $NoteContent = addslashes ($_POST['NoteContent']);
 }

 else {
     $NoteContent = $_POST['NoteContent'];
 }

 $NoteID = $_POST['NoteID'];          
 $sql = "INSERT INTO CustomerNotes ". "(NoteID,NoteContent,CustomerID) ". "VALUES('$NoteID','$NoteContent','$CustomerID')";
 $result = mysql_query($sql);

 if(! $result ) {
    die('Could not enter data: ' . mysql_error());
 }

 echo "Entered data successfully\n"; 

 ?&gt;

 &lt;p&gt; Add New Customer Record &lt;/p&gt;   

 &lt;form method = "post" action = "&lt;?php $_PHP_SELF ?&gt;"&gt;
 &lt;table id="Add Record"&gt;
 &lt;tr&gt; &lt;td&gt; Note ID &lt;/td&gt; 
 &lt;td&gt; &lt;input name = "NoteID" type="text" id="NoteID"&gt;&lt;/td&gt;
 &lt;td&gt; &lt;input name = "NoteContent" type="text" id="NoteContent"&gt;&lt;/td&gt; &lt;/tr&gt;
 &lt;tr&gt; &lt;td&gt;  &lt;input type="hidden" name="CustomerID" value="$CustomerID"&gt;&lt;/td&gt; &lt;/tr&gt;
 &lt;tr&gt; &lt;td&gt; &lt;input name = "Add Customer Note" type = "submit" id = "Add Customer Note"  value = "Add Customer Note"&gt; &lt;/td&gt; &lt;/tr&gt;
 &lt;/table&gt;
 &lt;/form&gt;
</code></pre>

<p>The errors are : </p>

<pre><code> Notice: Undefined index: CustomerID 
 Notice: Undefined index: NoteContent
 Notice: Undefined index: NoteID 
 Could not enter data: Duplicate entry '0' for key 'PRIMARY'
</code></pre>

<p>Some advice as to where I am going on would be great!</p>