require_once("$CFG->libdir/formslib.php");
class block_add_edit_form extends moodleform {
public function definition()
{
global $CFG,$DB;
$mform = $this->_form;
$mform->addElement('text', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('editor', 'attachment',get_string('file', 'block_add'),);
$mform->setType('attachment', PARAM_RAW);
$this->add_action_buttons();
}
function validation($data, $files) {
return array();
}
This is my form where i assigning values, down below is the code where i want insert but getting this error
Coding error detected, it must be fixed by a programmer: Invalid context id specified context::instance_by_id()
Debug info:
Error code: codingerror
Stack trace:
line 5346 of \lib\accesslib.php: coding_exception thrown line 1776 of \lib\blocklib.php: call to context::instance_by_id() line 1478 of \lib\blocklib.php: call to block_manager->process_url_edit() line 1645 of \lib\pagelib.php: call to block_manager->process_url_actions() line 1110 of \lib\pagelib.php: call to moodle_page->starting_output() line 1391 of \lib\outputrenderers.php: call to moodle_page->set_state() line 179 of \my\index.php: call to core_renderer->header()
require_once (__DIR__ . '/../../config.php');
require_once('edit_form.php');
$mform = new block_add_edit_form();
global $DB;
if ($mform->is_cancelled()) {
print_r("1");
}else if ($fromform = $mform->get_data()) {
var_dump($mform->get_data());
$record = new stdClass();
$record->id = $fromform->id;
$record->attachment = $fromform->attachment;
$DB->insert_record('image', $record);
}
echo $OUTPUT->header();
$mform->display();
echo $OUTPUT->footer();
I am working with Magento 1.8.0.0,
I have a test version installed on a WAMP server via localhost and when I want to add category's i get the next error:
Fatal error: Call to a member function getId() on a non-object in C:\wamp\www\magentno\lib\Varien\Data\Tree\Dbp.php on line 332
i have not made a store yet because i need category's for that.
I have already added a try and catch code to the line that gives the error.
this is the code that gives the error:
public function loadEnsuredNodes($category, $rootNode)
{
$pathIds = $category->getPathIds();
$rootNodeId = $rootNode->getId();
$rootNodePath = $rootNode->getData($this->_pathField);
$select = clone $this->_select;
$select->order($this->_table.'.'.$this->_orderField . ' ASC');
if ($pathIds) {
$condition = $this->_conn->quoteInto("$this->_table.$this->_idField in (?)", $pathIds);
$select->where($condition);
}
$arrNodes = $this->_conn->fetchAll($select);
if ($arrNodes) {
$childrenItems = array();
foreach ($arrNodes as $nodeInfo) {
$nodeId = $nodeInfo[$this->_idField];
if ($nodeId<=$rootNodeId) {
continue;
}
$pathToParent = explode('/', $nodeInfo[$this->_pathField]);
array_pop($pathToParent);
$pathToParent = implode('/', $pathToParent);
$childrenItems[$pathToParent][] = $nodeInfo;
}
$this->_addChildNodes($childrenItems, $rootNodePath, $rootNode, true);
}
}
this line is the killer:
$rootNodeId = $rootNode->getId();
This problem occurs due to reindexing problem. You can run this query in order to solve this problem
INSERT INTO catalog_category_entity(entity_id,entity_type_id,attribute_set_id,parent_id,created_at,updated_at,path,POSITION,level,children_count) VALUES (1,3,0,0,'0000-00-00 00:00:00','2009-02-20 00:25:34','1',1,0,1),(2,3,3,0,'2009-02-20 00:25:34','2009-02-20 00:25:34','1/2',1,1,0); INSERT INTO catalog_category_entity_int(value_id,entity_type_id,attribute_id,store_id,entity_id,value) VALUES (1,3,32,0,2,1),(2,3,32,1,2,1); INSERT INTO catalog_category_entity_varchar(value_id,entity_type_id,attribute_id,store_id,entity_id,value) VALUES (1,3,31,0,1,'Root Catalog'),(2,3,33,0,1,'root-catalog'),(3,3,31,0,2,'Default Category'),(4,3,39,0,2,'PRODUCTS'),(5,3,33,0,2,'default-category');
Note:- answer taken from This Link
I have a class that running inside a form to talk to a database, however the variables I'm using are returning errors. I have searched google but I cannot get a clear answer to my problem. Here are the errors, I've probably missed something obvious...hopefully:
Notice: Undefined variable: beer_name in /home/carlton/public_html/PHPproject/models/beer.php on line 28
Notice: Undefined variable: beer_type in /home/carlton/public_html/PHPproject/models/beer.php on line 35
Notice: Undefined variable: beer_abv in /home/carlton/public_html/PHPproject/models/beer.php on line 42
Notice: Undefined variable: beer_rating in /home/carlton/public_html/PHPproject/models/beer.php on line 49
Notice: Undefined variable: BeerEditor in /home/carlton/public_html/PHPproject/forms/beeradded.php on line 38
Fatal error: Call to a member function addBeer() on a non-object in /home/carlton/public_html/PHPproject/forms/beeradded.php on line 38
Here is my class:
protected $beer_name; //varchar(45)
protected $beer_type; //varchar(45)
protected $beer_abv; //decimal(4,2) alcohol percentage ex. 06.50
protected $beer_rating; //char(10) 1 awful beer, 10 great beer
public function __construct($beer_name = null){
if ($beer_name !== null){
$this->setBeerName($beer_name);
}
//defaults
//$this->setBeerType($beer_type);
//$this->setBeerABV($beer_abv);
//$this->setBeerRating($beer_rating);
}
public function setBeerName(){
$this->beer_name = $beer_name;
}
public function getBeerName(){
return $this->beer_name;
}
public function setBeerType(){
$this->beer_type = $beer_type;
}
public function getBeerType(){
return $this->beer_type;
}
public function setBeerABV(){
$this->beer_abv = $beer_abv;
}
public function getBeerABV(){
return $this->beer_abv;
}
public function setBeerRating(){
$this->beer_rating = $beer_rating;
}
public function getBeerRating(){
return $this->beer_rating;
}
}
Here is my form:
<?php
session_start();
ini_set('display_errors', 1);
error_reporting(E_ALL); ini_set('display_errors', 1);
require "/home/carlton/public_html/PHPproject/allincludes.php";
//var_dump($_POST);
if ($_SESSION['logged_in']!="yes"){
header ("Location: unauth.php");
}
//if (count($_POST)>0){
//need to add in validation check here
//
//
//
//
//$validationErrors= 0;
//if(count($validationErrors == 0 )){
$form=$_POST;
$beer_name = $form['beer_name'];
$beer_type = $form['beer_type'];
$beer_abv = $form['beer_abv'];
$beer_rating = $form['beer_rating'];
// }
$new_beer = new Beer($beer_name);
$new_beer->setBeerType($beer_type);
$new_beer->setBeerABV($beer_abv);
$new_beer->setBeerRating($beer_rating);
$BeerEditor->addBeer($new_beer);
echo "Beer added.";
echo ' Back to add menu ';
//}
you forget to pass the argument, here:
public function setBeerName(){
$this->beer_name = $beer_name;
}
it should be:
public function setBeerName($beer_name){
$this->beer_name = $beer_name;
}
please check in function setBeerType, setBeerABV, setBeerRating too.
im doing a PHP project using codeigniter 2.1.2 , using mySql database on WAMP, i have stumbled upon the following problem:
Here is my model
function loadUserData() {
$sql = "SELECT username FROM user WHERE username = ?";
$query = $this -> db -> query($sql, $this->session->userdata('username'));
if ($query -> num_rows() > 0) {
foreach ($query->result() as $row) {
$data = $row;
}
return $data;
}
}
The controller
function profile_access() {
if ($this -> session -> userdata('is_logged_in')) {
$this->load-> model('profile_model');
$uData['rows']=$this->profile_model->loadUserData();
$this->load->view('profile_view',$uData);
} else {
echo "<script type=\"text/javascript\"> alert(\"You need to provide your credentials first.\");</script>";
redirect('login_controller/index');
}
}
and the view
<?php
foreach($rows as $r){
echo print_r($r);
echo $r[username]->username; //line no. 81 in my code
}
?>
the print_r($r) from view gives me the following errors:
alphaomega1
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant username - assumed 'username'
Filename: views/profile_view.php
Line Number: 81
A PHP Error was encountered
Severity: Warning
Message: Illegal string offset 'username'
Filename: views/profile_view.php
Line Number: 81
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: views/profile_view.php
Line Number: 81
I expect the above code to return only "alphaomega" which is the username in the database. it is however displayed, but i dont know why i'm getting those errors. would appreciate some help with this. thanks.
In your view:
foreach($rows as $r){
echo $r->username;
}
In your model:
function loadUserData() {
$sql = "SELECT username FROM user WHERE username = ?";
$query = $this->db->query($sql, $this->session->userdata('username'));
return $query->result();
}
Getting the following the error :
Fatal error: Call to a member function load() on a non-object in C:\xampp\htdocs\Joomla15\components\com_book\book.php on line 43
Here is my php function :
function viewBook($option)
{
$id = JRequest::getVar('id', 0);
$row =& JTable::getInstance( 'book', 'Table');
$row->load($id);
if(!$row->type)
{
JError::raiseError( 404, JText::_('Invalid ID Provided'));
}
HTML_book::viewBook($row, $option);
}
Also, when i tried printing echo $row + " "; , it returned 0!!
Thanks
Have you checked you actually have a Table class well named?
For example, if your table class is called BooksTableBook, your call to JTable::getInstance should be:
JTable::getInstance( 'book', 'BooksTable' );
And if you're using a recent version of PHP, you should remove the "&" from this line (it's deprecated now):
$row =**&** JTable::getInstance( 'book', 'Table');
I hope it helped!