简体   繁体   English

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

[英]Not able to store data into database in joomla 2.5

I've tried a lots of method to insert my data into joomla database but it's not working. 我尝试了很多方法将数据插入到joomla数据库中,但是它不起作用。 Even though i have readed previous questions that has been asked by other stackoverflow members but still it is not solving my problem and also tried to understand the official joomla website but all goes in vain. 即使我已经阅读了其他stackoverflow成员曾经提出的问题,但仍然不能解决我的问题,并且还试图了解joomla官方网站,但徒劳无功。 Below is my code:- 下面是我的代码:

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>

Please help me to know my mistakes and any help will be appreciated the most... 请帮助我知道我的错误,任何帮助将最感激...

So finally i have managed to found it's solution. 所以最后我设法找到了解决方案。 Below is the updated code :- 下面是更新的代码:

    <?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>

The main problem was that i forgot to put ` in name and also '' in $name and $class which was stated by the Nicarus(A Stackoverflow member). 主要的问题是我忘记了Nicarus(Stackoverflow成员)所说的名称以及$ name和$ class中的。 Thanks for the reply..:) 谢谢回复..:)

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

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