SQL Syntax error upon submit

  • Profile Image
    foodorders
    Asked on March 13, 2012 at 05:45 PM

    Getting an error when I submit, 

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '', '', 'Yes', '', 'Yes', '', 'Yes', '')' at line 4

     

    Here is my thankyou.php file:

     

     

    <?php


    // This function will run within each post array including multi-dimensional arrays 

    function ExtendedAddslash(&$params)

            foreach ($params as &$var) {

                // check if $var is an array. If yes, it will start another ExtendedAddslash() function to loop to each key inside.

                is_array($var) ? ExtendedAddslash($var) : $var=addslashes($var);

                unset($var);

            }


    // Initialize ExtendedAddslash() function for every $_POST variable

    ExtendedAddslash($_POST);      


    $submission_id = $_POST['submission_id']; 

    $formID = $_POST['formID'];

    $ip = $_POST['ip'];

    $bsr = $_POST['bsr'];

    $bsrstate14 = $_POST['bsrstate14'];

    $projectsupport = $_POST['projectsupport'][0] ."-". $_POST['projectsupport'][1];

    $createddate = $_POST['createddate'][0] ."-". $_POST['createddate'][1] ."-". $_POST['createddate'][2];

    $evaluationdate = $_POST['evaluationdate'][0] ."-". $_POST['evaluationdate'][1] ."-". $_POST['evaluationdate'][2];

    $bestevaluator = $_POST['bestevaluator'][0] ."-". $_POST['bestevaluator'][1];

    $isthe = $_POST['isthe'];

    $comments26 = $_POST['comments26'];

    $doesthe54 = $_POST['doesthe54'];

    $comments29 = $_POST['comments29'];

    $casetransitioning = $_POST['casetransitioning'];

    $comments30 = $_POST['comments30'];

    $wasthe = $_POST['wasthe'];

    $comments33 = $_POST['comments33'];

    $werethe = $_POST['werethe'];

    $comments35 = $_POST['comments35'];

    $wasthe36 = $_POST['wasthe36'];

    $comments37 = $_POST['comments37'];

    $wasthe39 = $_POST['wasthe39'];

    $comments40 = $_POST['comments40'];

    $wasthe41 = $_POST['wasthe41'];

    $comments48 = $_POST['comments48'];

    $wasthe43 = $_POST['wasthe43'];

    $comments49 = $_POST['comments49'];

    $arethe = $_POST['arethe'];

    $comments42 = $_POST['comments42'];

    $weredecrypted = $_POST['weredecrypted'];

    $comments47 = $_POST['comments47'];

    $wasthe44 = $_POST['wasthe44'];

    $comments50 = $_POST['comments50'];



    $db_host = '127.0.0.1';

    $db_username = 'root';

    $db_password = 'admin';

    $db_name = 'techeval';


    mysql_connect( $db_host, $db_username, $db_password) or die(mysql_error());

    mysql_select_db($db_name); 


    // search submission ID


    $query = "SELECT * FROM `data` WHERE `submission_id` = '$submission_id'";

    $sqlsearch = mysql_query($query);

    $resultcount = mysql_numrows($sqlsearch);


    if ($resultcount > 0) {

     

        mysql_query("UPDATE `data` SET 

                                    `bsr` = '$bsr',

                                    `bsrstate` = '$bsrstate14',

                                    `projectsupport` = '$projectsupport',

                                    `createddate` = '$createddate',

                                    `evaluationdate` = '$evaluationdate'

    `bestevaluator` = '$bestevalutaor'

    `isthe` = '$isthe'

    `comments25` = '$comments26'

    `doesthe54` = '$doesthe54'

    `comments29` = '$comments29'

    `casetransitioning` = '$casetransitioning'

    `comments30` = '$comments30'

    `wasthe` = '$wasthe'

    `comments33` = '$comments33'

    `werethe` = '$werethe'

    `comments35` = '$comments35'

    `wasthe36` = '$wasthe36'

    `comments37` = '$comments37'

    `wasthe39` = '$wasthe39'

    `comments40` = '$comments40'

    `wasthe43` = '$wasthe43'

    `comments49` = '$comments49'

    `arethe` = '$arethe'

    `comments42` = '$comments42'

    `weredecrypted` = '$weredecrypted'

    `comments47` = '$comments47'

    `wasthe44` = '$wasthe44'

    `comments50` = '$comments50'

     

                                 WHERE `submission_id` = '$submission_id'") 

         or die(mysql_error());

        

    } else {


        mysql_query("INSERT INTO `data` (submission_id, formID, IP, 

                                                                              bsr, bsrstate14, projectsupport, createddate, evaluationdate) 

                                   VALUES ('$submission_id', '$formID', '$ip', 

                                                     '$bsr', '$bsrstate14', '$projectsupport', '$createddate', '$evaluationdate', '$bestevaluator', '$isthe', '$comments26', '$doesthe54', '$comments29', '$casetransitioning', '$comments30', '$wasthe', '$comments33', '$werethe', '$comments35', '$wasthe36', '$comments37', '$wasthe39', '$comments40', $wasthe43', '$comments49', '$arethe', '$comments42', '$weredecrypted', '$comments47', '$wasthe44', '$comments50') ") 

        or die(mysql_error());  


    }

    print("Your Technical evaluation form has been submitted successfully!");

    ?>

     

    Not sure where the problem is.  please help (file attached).
    thanks!
  • Profile Image
    jeanettebmz
    Answered on March 13, 2012 at 06:17 PM

    This is a problem related to PHP /mySQL programming that our Team have kindly suggested you, in order to  provide an example on what to do to create tables and insert data recieved from a submission. The problem obviously has to do with PHP programming code, not with the form itself.

    However I will assign this to our second level support, so they may have a hint or provide further assistance.  .


  • Profile Image
    liyam
    Answered on March 13, 2012 at 11:59 PM

    Hello foodorders.  Here are some things that you need to fix:

    1.) if ($resultcount > 0) {  - This may not show an error for now but it will not get a result in your conditions since your query that corresponds this result is not a count query.  To fix this, change this to:

    if (count($resultcount) > 0) {

    2.) On the line where mysql_query("UPDATE `data` SET is:

     mysql_query("UPDATE `data` SET
                                    `bsr` = '$bsr',
                                    `bsrstate` = '$bsrstate14',
                                    `projectsupport` = '$projectsupport',
                                    `createddate` = '$createddate',
                                    `evaluationdate` = '$evaluationdate'
                                    `bestevaluator` = '$bestevalutaor'
                                    `isthe` = '$isthe'
                                    `comments25` = '$comments26'
                                    `doesthe54` = '$doesthe54'
                                    `comments29` = '$comments29'
                                    `casetransitioning` = '$casetransitioning'
                                    `comments30` = '$comments30'
                                    `wasthe` = '$wasthe'
                                    `comments33` = '$comments33
                                    `werethe` = '$werethe'
                                    `comments35` = '$comments35'
                                    `wasthe36` = '$wasthe36'
                                    `comments37` = '$comments37'
                                    `wasthe39` = '$wasthe39'
                                    `comments40` = '$comments40'
                                    `wasthe43` = '$wasthe43'
                                    `comments49` = '$comments49'
                                    `arethe` = '$arethe'
                                    `comments42` = '$comments42'
                                    `weredecrypted` = '$weredecrypted'
                                    `comments47` = '$comments47'
                                    `wasthe44` = '$wasthe44'
                                    `comments50` = '$comments50'
                                 WHERE `submission_id` = '$submission_id'")

    Notice you are missing commas starting from `evaluationdate` = '$evaluationdate'.  I highlighted in red the parts that are missing commas in the end.  Adding a comma will fix your query.

    Please let us know if you're still getting MySQL error results after these edits.

  • Profile Image
    khrisell
    Answered on July 05, 2013 at 12:55 AM
    Greetings!

    We are happy to announce that we have released Jotform Webhooks,  this feature would replace Send Post Data + Custom URL Thank You Page workaround in order to help you transfer forms data to your own database using your own script codes.

    To know more about Jotform Webhooks, please click here.

     

    Thank you for using JotForm. :)