无法在joomla 2.5中将数据存储到数据库中

时间:2012-12-31 06:45:59

标签: php mysql joomla2.5 joomla-extensions

我已经尝试了很多方法将我的数据插入到joomla数据库中,但它无法正常工作。即使我已经提到其他stackoverflow成员已经提出的问题,但仍然没有解决我的问题,并试图了解官方的joomla网站,但一切都是徒劳的。以下是我的代码: -

defined( '_JEXEC' ) or die( 'Restricted access' );

   $app =& JFactory::getDocument();
   $page_title = $app->getTitle();

    $name = $_POST['name'];
    $class = $_POST['class'];


   $db =& JFactory::getDBO();
   echo $query = "INSERT INTO ' k2store'.'os0fr_jd'('id','name', 'class')
                  VALUES ('','$name','$class')";
                  mysql_query($query);
   $db->setQuery( $query );
   $db->query(); 







?>
<form action="index.php" method="post" name="adminForm">
<input type="hidden" name="option" value="com_sms" />
<input type="hidden" name="view" value="Sms" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
Name:&nbsp;<input type="text" name="name">
Class:&nbsp;<input type="text" name="class">
<input type="submit" value="Register" name="register">
</form>

请帮助我了解我的错误,任何帮助都会得到最多的赞赏......

1 个答案:

答案 0 :(得分:1)

所以最后我设法找到了它的解决方案。以下是更新后的代码: -

    <?php
/**
 *
 * @file        $Id: default.php 0.0.2 2012-12-28 00:00:00 Joydeep Banerjee $
 * @package        School Mangement System 
 * @version     0.0.2
 * @description Simple School Management System component for joomla 2.5
 * @copyright      Copyright © 2012 - All rights reserved.
 * @license          GNU General Public License v2.0
 * @author          Joydeep Banerjee
 * @author mail    joy@vividtechno.com
 * @website          http://www.indiawebsitedesigndevelopment.com
 *
 **/

  // No direct access
  defined( '_JEXEC' ) or die( 'Restricted access' );
       $app =& JFactory::getDocument();
       $page_title = $app->getTitle();

       echo $name = $_POST['name'];
       echo $class = $_POST['class'];


       $db =& JFactory::getDBO();
echo $query = "INSERT INTO `#__jd` (`id`,`name`, `class`)
    VALUES ('','$name', '$class');";
$db->setQuery( $query );
$db->query(); 
?>
<form action="index.php" method="post" name="adminForm">
<input type="hidden" name="option" value="com_sms" />
<input type="hidden" name="view" value="Sms" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
Name:&nbsp;<input type="text" name="name">
Class:&nbsp;<input type="text" name="class">
<input type="submit" value="Register" name="register">
</form>

主要的问题是我忘了在名字中加上'和''和$ Nicarus(Stackoverflow成员)所说的$ name和$ class。谢谢你的回复.. :))