I’ve been reading threads here on how to format the string date probably, however it wont add the date. Instead it just adds 0000-00-00. How come it wont format the string date?
the $date variable could for instance be equal to 10/10/2014
$date = str_replace('.', '-', $undate);
$timestamp = strtotime($date);
$newdate = date("Y-m-d", $timestamp);
$wpdb->query("INSERT INTO " . $your_db_name . "
(date, time, hometeam, awayteam, score)
VALUES ($newdate, '$time', '$opp1', '$opp2', '$score')");
If you already got the correct date format
Y-m-d
, those needed to be quoted as well:With @hakre’s suggestion on the comment below. It also has a prepared statement wrapper, might as well use it for safer queries:
If this
$your_db_name
(most likely a table name) is a user input as well, you need to whitelist this as you cannot bind table names. A simplein_array()
with predefined table names should suffice.