I got this error message when running PHP Code Igniter project:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$members_id
Filename: models/mtree.php
Line Number: 33
In line 33 ($row->members_id) refer to field in my database
VALUES (" . $this->db->escape($row->members_id) . ", " . $this->db->escape($left_parent) . ")";
My model function is:
function insert_to_right($direct_id='members_direct_id') {
$left_parent = $this->get_right_parent('members_id');
$row->members_direct_id = $left_parent;
$row->members_spillover_id = $left_parent;
$this->db->insert('ajmatrix_members_table', $row);
$sql = "INSERT INTO ayman_mot (child, parent)
VALUES (" . $this->db->escape($row->members_id) . ", " . $this->db->escape($left_parent) . ")";
$this->db->query($sql);
}
Your code don't have the members_id property in row.
$row variable have only 2 properties:
$row->members_direct_id = $left_parent;
$row->members_spillover_id = $left_parent;
Somewhere in your Model where you have the db select statement, for example:
$this->db->select('field1, field2, field3, field4');
try and replace it with:
$this->db->select('*');
Worked out for me, after battling it out for weeks through forums.
Though my initial mistake was putting the statement like this:
$this->db->select('field1', 'field2', 'field3', 'field4');
~ Mistakes are the ones we make ~ (speaking for myself here, don't hit me ^_^ )
Best Regards
You're not defining $row->members_id in your code - elsewhere you're referencing a members_direct_id - is that what you meant to use perhaps?
Related
Everyday I see this error in log file:
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /home/xxxxxxxx/public_html/wp-content/plugins/affiliate-link-cloaking/dbtable.php on line 252 and defined in /home/xxxxxx/public_html/wp-includes/wp-db.php on line 1246
In /dbtable.php on line 252 I have this code:
$result = $wpdb->query($wpdb->prepare("DELETE FROM ". $this->track_table_name . " WHERE YEAR(visittime)=". date('Y',$sdate) . " AND MONTH(visittime)=" . date('m',$sdate) ));
And in /wp-db.php on line 1246 I have this code:
public function prepare( $query, $args ) {
Please, keep in mind that I'm very inexperienced in PHP/SQL and I'll not understand general kind of tips. Please tell me, what to copy and paste where))
Thanks
That is not the correct way to use $wpdb->prepare, the first value should be the SQL with replacement tokens (%s=string, %d=digit, etc), followed by the values to replace them with.
$sql = "DELETE FROM {$this->track_table_name} WHERE YEAR(visittime) = %d AND MONTH(visittime) = %d";
$query = $wpdb->prepare($sql, date('Y', $sdate), date('m', $sdate))
$wpdb->query($query);
See examples here:
https://developer.wordpress.org/reference/classes/wpdb/prepare/
I keep getting the following errors. The $query produces a 1300 result list. When I run echo $query I get the following MySQL error:
[25-Aug-2016 21:38:32 America/New_York] PHP Warning: mysql_fetch_row() expects parameter 1 to be resource, null given in song.php on line 285
[25-Aug-2016 21:38:32 America/New_York] PHP Notice: Undefined variable: song_hash in song.php on line 292
$query = "select " . $query_data . " from " . $query_tables . " where " . $query_where;
//echo $query;
$result = mysql_query($query,$database);
while($row = mysql_fetch_row($result)){
$key = $row[0];
$song_hash[$key] = ($song_hash[$key] + 1);
}
$largest = max($song_hash);
In order to help you the contents of $query_data, $query_tables and $query_where needed. You can also print the error with mysql_error(). More likely you will be able to find out the solution from that output.
http://php.net/mysql_error
when you run echo query and you get those errors it simply means you don't have a query..
try hardcoding the query for debugging,
also you need to initialize your song_hash array
I'm writing a generic function that will take a large number of fields from $_POST and build an SQL insert into a table. In this case, I have a number of Undefined indexes and from reading other posts on SO, I am using a ternary to test if the variable exists. This works perfectly when I use it in interactive php, especially since there are no $_POST variables defined.
But when I use it in my form, I seem to get a extra quote and a few returns but I cannot see where they are coming from. I've beaten about this in different ways but am hoping someone can help me see what I'm not seeing.
function SaveDonation($form) {
try {
$querystr = "INSERT INTO GeneralDonations(donationForm, firstName, startYear)"
. "VALUES(" . "'" . $form . "', "
. ((!isset($_POST['firstName']))
? "'', " : ("'" . mysql_real_escape_string($_POST['firstName'])."', "))
. ((isset($_POST['startDate']))
? ("'" . mysql_real_escape_string($_POST['startDate'])."' ") : "'' ")
.")";
echo "<pre>query = "; var_dump($querystr);die;
$donation = $this->db->insertRow($querystr);
$result = true;
} catch(MysqlException $e) {
$result = false;
$this->errorMsg = $e->getMessage();
}
return $result;
}
The startDate is the undefined index value. This is the browser output using var_dump. It appears that the x-debug output is showing instead of the variable. But all table, no useful data? Please help me see what's different here?
string 'INSERT INTO GeneralDonations(
donationForm, firstName, startYear)VALUES('buy-a-foot', 's',
'<br />\r\n<font size=\'1\'><table class=\'xdebug-error xe-notice\'
dir=\'ltr\' border=\'1\' cellspacing=\'0\' cellpadding=\'1\'>\r\n
<tr><th align=\'left\' bgcolor=\'#f57900\' colspan=' )' (length=284)
Your code has some problems:
Please use prepared statements (see below)!
The error message (which is not entirely shown) would continue with "Undefined index firstName", since there's an ! too much in (!isset($_POST['firstName'])).
The error message is incomplete because your xdebug shortens var_dump output. You can change this behaviour with the settings xdebug.overload_var_dump and xdebug.var_display_max_data. See xdebug documentation.
If you can't use prepared statements, consider using some sprintf() construction to improve readability.
// Prepared statements (untested)
$stmt = $db->prepare("
INSERT INTO GeneralDonations(donationForm, firstName, startYear)
VALUES (?, ?, ?)");
$stmt->execute(array(
$form,
isset($_POST['firstName']) ? $_POST['firstName'] : '',
isset($_POST['startDate']) ? $_POST['startDate'] : ''
));
i got this error message while running my Php codeigniter project :
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for mtree::insert_to_right(), called in
C:\AppServ\www\News\application\controllers\bcontroller.php on line 20
and defined
Filename: models/mtree.php
Line Number: 28
this is my model function :
function insert_to_right($row, $direct_id) {
$left_parent = $this->get_right_parent($direct_id);
$row->members_direct_id = $left_parent;
$this->db->insert('table1', $row);
$sql = "INSERT INTO table2 (child, parent)
VALUES (" . $this->db->escape($row->members_id) . ", " . $this->db->escape($left_parent) . ")";
$this->db->query($sql);
}
function get_right_parent($id) {
return $id;
}
Since the function insert_to_right($row, $direct_id) requires two arguments, either you can pass in those two variables when you call them, or you can assign default values for it like insert_to_right($row = '....', $direct_id = '...'). I don't think you can just pass in any default variable as this would insert it into the database, so I would recommend you pass in the argument from the controller.
I need some help understanding the correct way to mix variables with strings like this. I have tried every configuration I can think of and I keep getting an error.
<?php
include('connect.php');
foreach($_GET['item'] as $key=>$value) {
mysql_query("UPDATE userprojectlist SET category_display_order = '$key' WHERE category_id = '$value' ");
}
?>
Notice: Undefined index: item in updatedb.php on line 3
Warning: Invalid argument supplied for foreach() in pdatedb.php on line 3
Is item an array in the url like item[]? If it's not that's the reason you get that error, you cannot iterate through a non-iterator object!
Also get rid of the single quotes around the values if they are numeric and use string concatenation,
"UPDATE userprojectlist SET category_display_order = " . $key . " WHERE category_id = " . $value . ";"
Notice: Undefined index: item in updatedb.php on line 3
This error is saying that there's no such variable as $_GET['item'] defined. You probably did not pass $_GET['item'] to this page.
Warning: Invalid argument supplied for foreach() in pdatedb.php on line 3
Thus because of the previous error, you get this, as $_GET['item'] is not an array.
The error has nothing to do with the SQL code.
mysql_query('UPDATE userprojectlist SET category_display_order = ' . $key . ' WHERE category_id = ' . $value );
or
mysql_query("UPDATE userprojectlist SET category_display_order = $key WHERE category_id = $value" );
This is assuming both variables are integers.