I am trying to enter 5 variables into a MySQL database. Here is the code:
foreach ($avail_t as $row) {
$ava = explode("+",$row);
$day = $ava[0];
$from = $ava[1];
$to = $ava[2];
//echo $day." ".$from." ".$to;
$query = "INSERT INTO availability (username, login_value, day, from, to) VALUES ('{$_SESSION['username']}', '{$_SESSION['login_value']}', '{$day}', '{$from}', '{$to}')";
mysql_query($query);
}
When I uncomment that echo statement all variables print out just fine, but when I process the query it doesn’t enter into the database. Weirdly, if I cut out $from and $to and just enter $day it will enter the day. When I put back the $from and $to nothing gets entered.
Do you see any problems with this code? Data type is integer in military time format 2100, 1300 etc. for $from and $to.
You are using
fromandtoas a column name which are reserved keywords, escape them using backticks`in your query