I’ll preface by stating that I am a bit new to PHP and MySQL. I am attempting to write my session variables to a MySQL database. I thought that I had performed this correctly after I was able to use my HTML form to submit the first record, but I am unable to submit additional records. Only one record shows in my database, and any attempts to submit new records do not error out, but instead just simply do not appear in my database.
My forms are carried across multiple pages, so I’ll include my PHP code:
<?php
$con = mysql_connect("localhost","user","mypassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydatabase", $con);
mysql_query("
INSERT INTO imaging (os,MAC,Model,AntiVirus,Browser,Email,Connectivity,Sound,Ports)
VALUES ('".$_SESSION['imaging2']."','".$_SESSION['imaging3']."','".$_SESSION['imaging4']."','".$_SESSION['antivirus']."','".$_SESSION['browser']."','".$_SESSION['email']."','".$_SESSION['connectivity']."','".$_SESSION['sound']."','".$_SESSION['ports']."')
OR die("Could not update: ".mysql_error());
mysql_close($con);
?>
My table name is: imaging
My columns in my database are as follows:
id - My primary key field set to Auto_Increment, type is int(11)
os - text
MAC - text
Model - text
AntiVirus - text
Browser - text
Email - text
Connectivity - text
Sound - text
Ports - text
Since it worked at least one time, it seems obvious that this is a problem with the codes interpretation of my primary key field.
Any help is always greatly appreciated. And hey, who knows? Maybe it is just a matter of stepping away from the computer long enough to get my eyes uncrossed and clear again. 🙂
Am I missing a reference to my id field in my PHP code?
If this is really your code you have a problem with the call to
mysql_query. As you can see by the syntax highlighting it is incorrect. You need an extra")at the end:By the way, this code is vulnerable to SQL Injection. Be careful!