Jump to content

orpheus

Members
  • Posts

    1
  • Joined

  • Last visited

Posts posted by orpheus

  1. I am trying to code a query whereby the query checks for duplicate items in a table and if found sends an error back to jquery. However, what is happening, is that jquery keeps giving me a typeError and I cannot see why. In my posted code, the code that is commented out, /* if ($box == 'DEMO111') works fine but not my query.

    All mysql connections are working and I can connect to the db.

    I would be grateful if someone could check my code and show me where I have gone wrong. Thanks

     

    DB Config

    <?php
    
    function runSQL($rsql) {
        $hostname = "localhost";
        $username = "root";
        $password = "";
        $dbname   = "logistor_logistor";
        $connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
        $db = mysql_select_db($dbname);
        $result = mysql_query($rsql) or die (mysql_error());
        return $result;
        mysql_close($connect);
    
    ?>
    <?php
    
    $array = split('[,]', $_POST['box_add']);
    $boxerrortext = 'No duplicate boxes';
    ?>
    
    <?php
    
    if (isset($_POST['submit']))     {
                $error = array();
                foreach ($array as $box) {
                $sql = "SELECT * FROM act WHERE item = '" . $box . "'";
                $result = runSQL($sql) or die(mysql_error());
                $num_rows = mysql_num_rows($result);
                
                if ($num_rows) {
                //trigger_error('It exists.', E_USER_WARNING);
                
                $error[] = array('boxerror'=>$boxerrortext,
                                'box'=>$box);
                $result = json_encode($error);
    
                echo $result;
                return;
                }
                }
    
                /* if ($box == 'DEMO111')
                
                {
                //echo 'There was an error somewhere';
                //$box = 'ERROR';
    
                //$error = array('boxerror'=>$boxerrortext, 'box'=>$box);
                //$output = json_encode($error);
    
                //echo $output;
                //return;
                } */
                
                else {
        
                $form = array();
    
                foreach ($array as $box) {
    
                $form[] = array('dept'=>$dept,
                'company'=>$company,
                'address'=>$address,
                'service'=>$service,
                'box'=>$box,
                'destroydate'=>$destroydate,
                'authorised'=>$authorised,
                'submit'=>$submit);
    
                 $sql = "INSERT INTO `temp` (service, activity, department, company, address, user, destroydate, date, item, new) VALUES ('$service', '$activity', '$dept', '$company', '$address', '$requested', '$destdate', NOW(), '$box', 1)";
                 $result = runSQL($sql) or die(mysql_error());
                } 
               }
              }
    
                 $result=json_encode($form);
    
                 echo $result;
    
    ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.