简体   繁体   English

JoomLa更新查询不起作用

[英]JoomLa update query is not working

I'm new to the joomla and php. 我是joomla和php的新手。 I having problem on my sql query in joomla in which it does not update the table, and it giving me error message. 我在joomla的sql查询中遇到问题,它没有更新表,并且给了我错误消息。 Is there any mistake i had made on my up date query? 我在更新查询中犯了任何错误?

Here is my code: 这是我的代码:

// 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';}

}

I'm getting this error message. 我收到此错误消息。

You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near ''TEST2' AND campusid = Campus3' at line 1 SQL=UPDATE intake SET startdate = 05/06/2014 WHERE courseid = 'TEST1','TEST2' AND campusid = Campus3 检查与您的MySQL服务器版本相对应的手册,以在第1行的“ TEST2”和“ campusid = Campus3”附近使用正确的语法SQL = UPDATE入口SET startdate = 05/06/2014 WHERE courseid ='TEST1','TEST2 'AND campusid = Campus3

Where the courseid is an array value that post by other form with a checkbox input. 其中courseid是一个数组值,该数组值通过其他形式与复选框输入一起发布。

your variable $courseID1 in the query turns out to 您在查询中的变量$ courseID1原来是

courseid = 'TEST1','TEST2'

while should have been 应该是

courseid in( 'TEST1','TEST2' )

Also your dateformat is wrong for mysql. 另外,您的dateformat对于mysql是错误的。 Try 尝试

$from=date('Y-m-d', strtotime($from));
$query = "UPDATE intake SET startdate = '$from' WHERE courseid in ( $courseID1 ) 
AND campusid = $campusID";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM