我是joomla和php的新手。我在joomla中的sql查询有问题,它不更新表,它给我错误消息。我的上线日期查询是否有任何错误?
这是我的代码:
// Get default database object
$db =JFactory::getDBO();
// Get a new JDatabaseQuery object
$query = $db->getQuery(true);
$tmpIds = array();
foreach($courseID as $cId){
$tmpIds[]= $db->quote($cId);
//sanitize the input
}
$courseID1 = implode(',',$tmpIds);
// Build the query
$query->select($db->quoteName('courseid'));
$query->from($db->quoteName('intake'));
$query->where($db->quoteName('campusid').'='. $db->quote($campusID));
$query->where($db->quoteName('courseid').'IN('.$courseID1.')');
// Set the query for the DB oject to execute
$db->setQuery($query);
// Get the DB object to load the results as a list of objects
$results = $db->loadObjectList();
if($results){
$query = "UPDATE intake SET startdate = $from WHERE courseid = $courseID1 AND campusid = $campusID";
echo"$query";
$db->setQuery( $query );
$db->query();
}
else{ echo 'Error';}
}
我收到此错误消息。
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 在''TEST2'附近并且校园=校园3'在第1行SQL =更新摄入量SET startdate = 05/06/2014 WHERE courseid ='TEST1','TEST2'和campusid = Campus3
其中courseid是一个数组值,以其他形式发布,带有复选框输入。
答案 0 :(得分:0)
查询中的变量$ courseID1变为
courseid = 'TEST1','TEST2'
虽然应该是
courseid in( 'TEST1','TEST2' )
你的dateformat对于mysql也是错误的。尝试
$from=date('Y-m-d', strtotime($from));
$query = "UPDATE intake SET startdate = '$from' WHERE courseid in ( $courseID1 )
AND campusid = $campusID";