Vote count:
0
I'm currently writing an sql that has me confused. I've got two possible ways to accept data - insert or update, depending on how the check for present data goes. If I do insert, everything goes in smoothly. However, if I do update, it only takes the year from the data (aka 2015-03-31 becomes 2015).
Insert statement + bind:
$sql = "insert into track_ach_mini values (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?)";
$stmt = $mysqli->prepare($sql); $stmt->bind_param("iiiiiiiiiiiiss", simple_decrypt($_POST['uid']), $_POST['data']['a'], $_POST['data']['b'], $_POST['data']['c'], $_POST['data']['d'], $_POST['data']['e'], $_POST['data']['f'], $_POST['data']['g'], $_POST['data']['h'], $_POST['data']['i'], $_POST['data']['j'], $_POST['data']['k'], $_POST['l'], $date);
Update sql + prepare + bind:
$sql = "update track_ach_mini set status = 0, a = ?, b = ?, c = ?, d = ?, e = ?, f = ?, g = ?, h = ?, i = ?, j = ?, k = ?, l = ?, m = ? where uid = ?";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("siiiiiiiiiiiis", $_POST['a'], $_POST['data']['b'], $_POST['data']['c'], $_POST['data']['d'], $_POST['data']['e'], $_POST['data']['f'], $_POST['data']['g'], $_POST['data']['h'], $_POST['data']['i'], $_POST['data']['j'], $_POST['data']['k'], $_POST['data']['l'], $date, simple_decrypt($_POST['uid']));
(array keys & db cols altered, as you probably guessed).
By echoing out $date, I get 2015-03-31. On the insert, it sets it to 2015-03-31. On the update, it only submits 2015, causing the db to truncate it to 0000-00-00.
PHP Mysqli Prepared statement removes part of date
Aucun commentaire:
Enregistrer un commentaire