0

I have a function that is supposed to store the array to my mysql table yet nothing is showing up in my database. This is my first time using Mysqli as I used to use Mysql.

The function is passed a $uniqueRef ID that is saved into the Database, The work order array, $coreSales which is another array that gets saved in the Database and $mysqli which passes the MYSQLI connection.

This is My Code :

function storeInDB($uniqueRef, $wo, $coreSales, $mysqli){
    $accountStatus = 0;
    $requiresAttention = 2;

    $stmt = $mysqli->prepare("INSERT INTO `workorder`(`id`, `uniqueRef`, `rep`, `repemail`, `date`, `event`, `otherNotes`, `repNotes`, `bookingNotes`, `reqInstallDate`, `tripplePlayPromo`, `fullName`, `address`, `contactNumber`, `accountNumber`, `custID`, `custEmail`, `cblPackage`, `cblNotes`, `cblEquipment`, `cblPromo`, `internetPackage`, `internetNotes`, `internetEquipment`, `internetPromo`, `phonePackage`, `phonePromo`, `portingNumber`, `phoneBook`, `portornew`, `cellorlandline`, `companyPortingfrom`, `servicesToDisco`, `alarm`, `intercom`, `nameOnBill`, `cellAccount`, `fromAddress`, `phoneNotes`, `creditName`, `creditContactNumber`, `creditAddress`, `creditAccount`, `status`, `requiresattention`, `creditAmount`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");


$stmt->bind_param('issssssssssssssssssssssssssssssssssssssssssiii',
    $idNum,
    $uniqueRef,
    $wo['rep'],
    $wo['repemail'],
    $wo['date'],
    $wo['event'],
    $wo['otherNotes'],
    $wo['repNotes'],
    $wo['bookingNotes'],
    $wo['reqInstallDate'],
    $wo['tripplePlayPromo'],
    $wo['fullName'],
    $wo['address'],
    $wo['contactNumber'],
    $wo['accountNumber'],
    $wo['custID'],
    $wo['custEmail'],
    $wo['cblPackage'],
    $wo['cblNotes'],
    $wo['cblEquipment'],
    $wo['cblPromo'], 
    $wo['internetPackage'],
    $wo['internetNotes'], 
    $wo['internetEquipment'], 
    $wo['internetPromo'], 
    $wo['phonePackage'], 
    $wo['phonePromo'],
    $wo['portingNumber'], 
    $wo['phoneBook'],
    $wo['portornew'], 
    $wo['cellorlandline'], 
    $wo['companyPortingfrom'], 
    $wo['servicesToDisco'], 
    $wo['alarm'],
    $wo['intercom'], 
    $wo['nameOnBill'], 
    $wo['cellAccount'], 
    $wo['fromAddress'],
    $wo['phoneNotes'],
    $wo['creditName'], 
    $wo['creditContactNumber'],
    $wo['creditAddress'],
    $wo['creditAccount'],
    $accountStatus,//Status
    $requiresAttention,
    $creditAmount);//Requires Attention



    echo $mysqli->error;
    $stmt->execute();
    $idNum = $mysqli->insert_id;
    $stmt->close();

    echo "<br>Stored in DB ID#" .$idNum ;
    return $idNum;
}

Thanks

Govinda Rajbhar
  • 2,778
  • 3
  • 32
  • 58
MrToast
  • 31
  • 9
  • 4
    Did you bother checking the return value each of those functions? `prepare()`, `bind_param()` and `execute()` will all return boolean false on failure, unless you've enabled Exceptions. That is one HELL of a lot of parameters to be beinding - are you sure you've got a 1:1:1 match between your fields:parameters:bindings? – Marc B Feb 18 '14 at 05:08
  • There is not enough information here to know what went wrong, but some basic debugging on your part might shed some light. First, ensure that your script has an `error_reporting` level of -1, to ensure all error levels are on, then either log errors or display them to get all error information. Include said errors in your question. This code contains no syntax errors and clearly parameters match, but nothing is known of potential runtime errors. – Sherif Feb 18 '14 at 05:14
  • I'm not even going to start to count these. I lost track after 7. – Funk Forty Niner Feb 18 '14 at 05:15
  • I will enable error reporting on my script and post back. I have used Count and everything is 1:1:1 there is 46 of each Thanks – MrToast Feb 18 '14 at 05:15
  • Any tips on how I can get the errors from this? Im a newb – MrToast Feb 18 '14 at 05:19
  • Well, the number of bound parameters do match the number of placeholders in your statement. That much is evident by reading the code, yes. However, what we can't know just by reading the code are what potential runtime errors this code is producing that could cause it to behave unexpectedly. For example, you have bound the variable `$creditAmount` in your statement, and yet this variable is never defined in this function. The schema is unknown to us, so if the driver fails to prepare the statement due to a `NOT NULL` constraint on `creditAmount`, the entire function fails. – Sherif Feb 18 '14 at 05:21
  • 3
    Solved my problem I used http://stackoverflow.com/questions/2552545/mysqli-prepared-statements-error-reporting for error reporting – MrToast Feb 18 '14 at 05:23
  • `Another Happing Ending` +1 for self-solving. – Funk Forty Niner Feb 18 '14 at 05:26

0 Answers0