1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Whats wrong with my code?

Discussion in 'Programming' started by NITRO23456, Aug 26, 2017.

  1. NITRO23456

    NITRO23456 Well-Known Member

    Messages:
    503
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #21
    OK, the output is now populated but I get the connection error again

    mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
    SEMrush
     
    NITRO23456, Aug 27, 2017 IP
    SEMrush
  2. sarahk

    sarahk iTamer Staff

    Messages:
    23,477
    Likes Received:
    3,171
    Best Answers:
    86
    Trophy Points:
    615
    #22
    sarahk, Aug 27, 2017 IP
  3. NITRO23456

    NITRO23456 Well-Known Member

    Messages:
    503
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #23
    see image
     

    Attached Files:

    • ss2.jpg
      ss2.jpg
      File size:
      30.9 KB
      Views:
      8
    NITRO23456, Aug 27, 2017 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    23,477
    Likes Received:
    3,171
    Best Answers:
    86
    Trophy Points:
    615
    #24
    sarahk, Aug 27, 2017 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    23,477
    Likes Received:
    3,171
    Best Answers:
    86
    Trophy Points:
    615
    #25
    ok, so through conversation I've seen the mysql library that's being used, out of date, but lets work with it for now.

    you therefore need to have these steps in your code

    
    global $db;
    $db = new MySQLConnection($myDbParams);
    
    function BeforeAdd(&$values, &$message, $inline){
    global $db;
    
    // rest of the function
    
    /* don't use this line
    // mysql_query($query) or die(mysql_error(). '<br />'.$query);
    // instead use this:
    */
    $db->query($query);
    
    }
    PHP:
     
    sarahk, Aug 27, 2017 IP
  6. NITRO23456

    NITRO23456 Well-Known Member

    Messages:
    503
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #26
    Can't get that to work without breaking the app.

    What should it be exactly?
     
    NITRO23456, Aug 27, 2017 IP
  7. sarahk

    sarahk iTamer Staff

    Messages:
    23,477
    Likes Received:
    3,171
    Best Answers:
    86
    Trophy Points:
    615
    #27
    trawl through their code and see how they do it. If you're hooking into a bigger page then they will probably handle the connection for you. Check to see how they access their database variable. It will be something like what I've written.
     
    sarahk, Aug 27, 2017 IP
  8. NITRO23456

    NITRO23456 Well-Known Member

    Messages:
    503
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #28
    Now I am using this:

    
    $count = $values["Number Received"];
    
        for($i = 1; $i < $count; $i++)
        {
            $sql = "INSERT INTO `Stock`
            (`Hospital`,`Manufacturer`,`Department`,`Item Type`,`Batch/Lot Number`,`Expiry Date`,`Number Received`,`Received By`,`Received On`,`Package Insert/Condition Checked`,`Use Commenced By`,`Use Commenced On`,`Notes/Comments`,`Value`)
            VALUES
            (`{$values["Hospital"]}`
            ,`{$values["Manufacturer"]}`
            ,`{$values["Department"]}`
            ,`{$values["Item Type"]}`
            ,`{$values["Batch/Lot Number"]}`
            ,`{$values["Expiry Date"]}`
            ,`{$values["Number Received"]}`
            ,`{$values["Received By"]}'`
            ,`{$values["Received On"]}`
            ,`{$values["Package Insert/Condition Checked"]}`
            ,`{$values["Use Commenced By"]}`
            ,`{$values["Use Commenced On"]}`
            ,`{$values["Notes/Comments"]}`
            ,`{$values["Value"]}`);";
                      
           CustomQuery($sql);
        }
        return true;
    
    Code (markup):
    But I get an error (thankfully not a connection error)

    This is driving me mad!
     
    NITRO23456, Aug 28, 2017 IP
  9. sarahk

    sarahk iTamer Staff

    Messages:
    23,477
    Likes Received:
    3,171
    Best Answers:
    86
    Trophy Points:
    615
    #29
    columns get backticks `
    values get single quotes '

    you have backticks around your values

    upload_2017-8-29_8-52-23.png
     
    sarahk, Aug 28, 2017 IP