jeudi 6 août 2015

Just wondering why this isn't working, I want to insert data from submit form to database

I'm trying to send data from my submit form to the database, I'm using phpliteadmin as my database manager.

here is my php

<?php

if (isset($_POST['submitted'])) {

    include('connect-phpliteadmin.php');

$make = $_POST['Make'];
$model = $_POST['Model'];
$badge = $_POST['Badge'];
$price = $_POST['Price'];
$trans = $_POST['Transmission'];
$ppl = $_POST['P_Plate_Legal'];

$sqlinsert("INSERT INTO Cars_On_Network (Make, Model,  Badge, Price, Transmission, P_Plate_Legal) VALUES ('$make, $model, $badge, $price, $trans, $ppl'");

    if (!mysqli_query($dbcon, $sqlinsert)) {
        die("Error inserting new vehicle");
    }

    $newrecord = "New record added to the database";

}

echo "Make: " . $_POST['Make'] . "<br>";
echo "Model: " . $_POST['Model'] . "<br>";
echo "Badge: " . $_POST['Badge'] . "<br>";
echo "Price: " . $_POST['Price'] . "<br>";
echo "Transmission: " . $_POST['Transmission'] . "<br>";
echo "P Plate Legal: " . $_POST['P_Plate_Legal'] . "<br>";




try {
  # Connect to SQLite database
  $dbh = new PDO("sqlite:Car_Sales_Network");



  # Prepare SQL statemen
  #$sth = $dbh->prepare("INSERT INTO Cars_On_Network (Make, Model,  Badge, Price, Transmission, P_Plate_Legal) VALUES ('$make, $model, $badge, $price, $trans, $ppl'");

  # Run the query on the database
  $sth->execute(array($make, $model));



?>

I'm not sure why this isn't working, I have followed a YouTube video and it didn't work. A fix would be greatly appreciated.

Cheers.

Aucun commentaire:

Enregistrer un commentaire