-1

When I write the code out without a function it works, otherwise I get a 500 connection error. Not sure what error I'm making. Here is my code:

$date = "2016-01-12";
$date = date("Y-m-d", strtotime($date));

$sql    = 'INSERT INTO `campaigns` (campaign_id, campaign_date) VALUES (9001, "' . $date . '")';
$result = $link->query($sql);

if ($result) {
    echo "database updated";
} else {
    echo $link->error;
}

function insertIntoDB($mysqli, $date) {

    $sql    = 'INSERT INTO `campaigns` (campaign_id, campaign_date) VALUES (9001, "' . $date . '")';
    $result = $mysqli->query($sql);

    if ($result) {
        echo "database updated";
    } else {
        echo $mysqli->error;
    }

}

insertIntoDB($link, $date);
bpr
  • 483
  • 1
  • 11
  • 23

1 Answers1

0

The function works properly when I call it above defining it. Dunno.

bpr
  • 483
  • 1
  • 11
  • 23