The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed May 02, 2012 8:11 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Tue May 01, 2012 5:01 pm
Posts: 1
Hi everybody,

today I encounter a problem concerning the inserting of data into my database.

I've created a module to insert data into a table. There are two locations to complete the fields, the first one is on an article and second one is in the admin's menu.

Here is the code about :
Code:
<?php
defined( '_JEXEC' ) or die;

function add_Age_row($label)
{
   
   $db = &JFactory::getDBO();

$query = "INSERT INTO '#__module_age' (label_age) VALUES (".$label."')";

print_r($label);
print_r($query);
$db->setQuery( $query );
$db->query();   

}





function get_Age()
{

   $database = &JFactory::getDBO();

   $query = "SELECT label_age FROM module_age ORDER BY id_age";
   $database->setQuery($query);
   $rows = $database->loadAssocList();

   foreach($rows as $key=>$row)
   {
      echo "<br/>";
      echo $row['label_age'];
      echo "<br/>";
   }


}


if (isset($_POST['age']))
{
   echo "passe là";
   add_Age_row($_POST['age']);
}

get_Age();

?>
<form method="POST" action ="<?php echo JURI::current(); ?>">
   <p><label> Age :</label></p>
   <p><input type="text" name="age"></p>
   <p><input id="submit" name="submit" type="submit" value="Submit Names" /></p>
</form>


The selection works but not the insertion.
Do you have any ideas ?

I've tried with the PDO Method and it's the same, selection works but insertion not.

Thank you in advance

Matt


Top
 Profile  
 
PostPosted: Wed May 02, 2012 1:26 pm 
User avatar
Joomla! Virtuoso
Joomla! Virtuoso

Joined: Thu Feb 15, 2007 5:48 am
Posts: 3344
Location: Sydney, Australia
Code:
$query = "INSERT INTO '#__module_age' (label_age) VALUES (".$label."')";
The single quotation mark after VALUES ( is missing. You should use the back tick characters ` around the table name, instead of apostrophe '.

_________________
toivo
my first programs were assembled and run in 16KB :)
http://archive.computerhistory.org/resources/text/GE/GE.GE-115SystemSoftware.1967.102646096.pdf#zoom=100


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 



Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group