0

I will admit I am a newbie when it comes to PDO, but I have to change over a form that is in mysql.. I am getting connection, but nothing inserted.. I am truly stuck and feel like an idiot because I know it is something simple I am missing

I have tried having the arrays above and after the insert.. Neither work

Any help would be appreciated

Here is my code:

$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);


$STH = $conn->prepare("INSERT INTO PinTrade (ID, PIN, Year, Make, Model, Mileage, FirstName, LastName, Phone, Email, Date)
VALUES ('', '$pin', '$year', '$make', '$model', '$mileage', '$first', '$last', '$phone', '$email', '1234' )");
$STH->bindParam(':PIN', $_POST['pin']);
$STH->bindParam(':Year', $_POST['year']);
$STH->bindParam(':Make', $_POST['make']);   
$STH->bindParam(':Model', $_POST['model']); 
$STH->bindParam(':Mileage', $_POST['mileage']); 
$STH->bindParam(':FirstName', $_POST['first']); 
$STH->bindParam(':LastName', $_POST['last']);
$STH->bindParam(':Phone', $_POST['phone']); 
$STH->bindParam(':Email', $_POST['email']);
$STH->execute();

1 Answers1

1

Get rid of the dollar signs and quotes in your query values:

$STH = $conn->prepare("INSERT INTO PinTrade (ID, PIN, Year, Make,
                        Model, Mileage,        FirstName, LastName, Phone, Email, Date)
                       VALUES (null, :PIN, :Year, :Make, //and so on.... 

Also note, assuming ID is an auto incrementing field, just insert null

  VALUES (null, :PIN, 

Finally, if you're pulling from the post array, I'd use bindValue over bindParam

Ray
  • 40,256
  • 21
  • 101
  • 138