0

I am having a hard time inserting data into my database, I created all the fields and made sure they are spelled correctly, I also made sure all the values are in the variable names I am trying to insert into the database, I am not sure what I am doing wrong, here is my code.

DB Script

//This script provides connection to the database//
//Connect
$user="root";
$pass="";
try {
    $connection = new PDO('mysql:host=localhost;dbname=forms', $user, $pass);
} catch (Exception $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
die();
}

Insert Data into Database Script

try {
        //Prepare
        $prepIt = $connection->prepare(
        "INSERT INTO `formdata`(`revision`, `printOnly`, `artOnly`, `sales`, `service`, `fBoth`, `clientRep`, `dealerName`, `clientContact`, `clientCell`, `clientEmail`, `orderDate`, `jobName`, `coOp`, `dateDrop1`, `dateDrop2`, `qty1`, `qty2`, `dateDrop1Exp`, `dateDrop2Exp`, `jobDesc`, `otherDesc`, `envelopes`, `otherEnvelope`, `scratcher`, `fInsert`, `fKey`, `kbbAppend`, `matchJob`, `4x6Note`, `postItNote`, `creditCard`, `busCard`, `bbAppend`, `font`, `fReal`, `preSort1Class`, `firstClassStamp`, `preSortStandard`, `canceledStamp`, `databaseEquity`, `dataDatabase`, `dataBk`, `dataCredit`, `dataOsBrand`, `dataOsNoBrand`, `dataSaturation`, `dataOther`, `dGiveaway`, `genGiveaway`, `inQuant1`, `inQuant2`, `inQuant3`, `inQuant4`, `inDesc1`, `inDesc2`, `inDesc3`, `inDesc4`, `inPricePc1`, `inPricePc2`, `inPricePc3`, `inPricePc4`, `total1`, `total2`, `total3`, `total4`, `recQuant1`, `recQuant2`, `recQuant3`, `recDesc1`, `recDesc2`, `recDesc3`, `recPerRecord1`, `recPerRecord2`, `recPerRecord3`, `recListTotal1`, `recListTotal2`, `recListTotal3`, `formComments`) VALUES ($revision, $printOnly, $artOnly, $sales, $service, $both, $clientRep, $dealerName, $clientContact, $clientCell, $clientEmail, $orderDate, $jobName, $coOp, $dateDrop1, 
            $dateDrop2, $qty1, $qty2, $dateDrop1Exp, $dateDrop2Exp, $jobDesc, $otherDesc, $envelopes, $otherEnvelope, $scratcher, $insert, $key, $kbbAppend, $matchJob, $_4x6Note, $postItNote, $creditCard, $busCard,
            $bbAppend, $font, $real, $preSort1Class, $firstClassStamp, $preSortStandard, $canceledStamp, $databaseEquity, $dataDatabase, $dataBk, $dataCredit, $dataOsBrand, $dataOsNoBrand, $dataSaturation, $dataOther,
            $dealerGiveaway, $genericGiveaway, $inQuant1, $inQuant2, $inQuant3, $inQuant4, $inDesc1, $inDesc2, $inDesc3, $inDesc4, $inPricePc1, $inPricePc2, $inPricePc3, $inPricePc4, $total1, $total2, $total3, $total4,
            $recQuant1, $recQuant2, $recQuant3, $recDesc1, $recDesc2, $recDesc3, $recPerRecord1, $recPerRecord2, $recPerRecord3, $recListTotal1, $recListTotal2,$recListTotal3, $comments)");
            //Execute
            $prepIt->execute();
            //Confirmation
            echo "Job Has Been Created";

    } catch (Exception $e) {
        //Catch any errors
        echo "there was an error.".$e->getMessage();
    }
user2684521
  • 380
  • 4
  • 20
  • 1
    Are all those variables integers? You should probably use a prepared statement here. – chris85 Jun 17 '15 at 21:40
  • 1
    What do you mean by "having a hard time"? Are you getting an error? If so, what is it? – jjj Jun 17 '15 at 21:40
  • 3
    You're probably suffering from unquoted strings, and very bad [sql injection attack](http://bobby-tables.com) vulnerabilities. – Marc B Jun 17 '15 at 21:41
  • I am getting no error, the "Job Has Been Created" confirmation message in the try block triggers, but nothing gets inserted to my database. The variables are a mixture of values, and everything in the database is set to varchar – user2684521 Jun 17 '15 at 21:42

0 Answers0