Unknown column 'value' in 'where clause' - database

I have reviewed every post and tried a few recommendations but nothing is working. My code has been fine -- but Gravity Forms did an update and messed up the database tables the data was pulling from so I edited that but the data is still not pulling properly and I am getting the error: Unknown column 'value' in 'where clause' when I turn on debug.
Can anyone see why I am getting this error? The page should be retrieving a list of team members based on the value they have entered in a graavity form field.....all was fine until the update.
Here is the code that is causing the issues - specifically the $get_team_ids and $user_email lines seem to be the offenders.
function showstep1(){
$concate='';
$postid = get_the_ID();
$post_7 = get_post($postid);
if( is_mr() ) {
//print_r($post_7->post_title);
}
//echo $postid;
global $wpdb;
$table_name = $wpdb->prefix . "walking_steps";
$table_name1 = $wpdb->prefix . "users";
$table_name2 = $wpdb->prefix . "gf_entry_meta";
$get_team_ids = $wpdb->get_results("SELECT * FROM $table_name2 where value = '" .$post_7->post_title. "'");
if( is_mr() ) {
//print_r($get_team_ids);
//print_r( $getuserids );
}
$users = array();
if(!empty($get_team_ids)){
foreach ($get_team_ids as $idlead) {
$user_email = $wpdb->get_var("SELECT value FROM wp_gf_entry_meta WHERE form_id=4 AND lead_id=$idlead->lead_id AND field_number=3");
if( empty( $user_email ) ) {
$user_email = $wpdb->get_var("SELECT value FROM wp_gf_entry_meta WHERE form_id=1 AND lead_id=$idlead->lead_id AND field_number=2");
}
if( $user_email ) $users[] = $user_email;
//$concate .= $idlead->lead_id.',';
}
$concate = substr($concate, 0,-1);
//echo $concate;
}

Unknown column 'value' in 'WHERE clause' would usually indicate that the column does not exist in the table.
You say that this is also happening for the other line 'user_email' which also is trying to SELECT the column 'value' again, if this causing you a problem, the column name is not correct it would seem.
Is it the correct header for the column? Seems like an ambiguous name. Try renaming the column 'value' to something less generic or change the where clause to
"WHERE table_name2.value = "
If this is not the column header, please replace 'value' with the correct column header
EDIT: Correct Code below as per comments
Replace all instances of 'value' with 'meta_value'

Related

How to check whether value is in database without throwing an exception in Zend?

I have a registration action in Zend controller and I want to ensure that given username isn't already in the database.
$tUser = $userMapper->getDbTable();
$select = $tUser->select()
->from(array('u'=>'users'))
->where('u.user_username = ' . $value);
$row = $tUser->fetchRow($select);
Unfortunately, this snippet of code throws the Exception when i just want to check the $row is null or not and keep writing my code.
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'admin' in 'where clause', query was: SELECT u.* FROM users AS u WHERE (u.user_username = admin) LIMIT 1
Should I remove the try/catch blocks in my controller or can I do it in another way?
Judging by error description, I'd say it will throw an exception always, no matter if user exists or not, because bad SQL query will be generated. Try passing $value as second parameter to where, like this:
$tUser = $userMapper->getDbTable();
$select = $tUser->select()
->from(array('u'=>'users'))
->where('u.user_username = ?', $value);
$row = $tUser->fetchRow($select);
You will then check if user exists like this:
if(!$row) {
// user doesn't exist
} else {
// user exists
}
try {
$tUser = $userMapper->getDbTable();
$select = $tUser->select()
->from(array('u'=>'users'))
->where('u.user_username = ?', $value);
$row = $tUser->fetchRow($select);
} catch (Zend_Db_Exception $e) {
echo "<pre>";print_r($e);
}

Zend query sort by multiplication of columns

I am trying to query some rows from a MySQL database with Zend Framework 1. I need all columns, but want to sort them by a multiplication of columns:
$select = $this
->select()
->where('start_date < ' . $currentTime)
->where('end_date >' . $currentTime)
->order('columnA * columnB DESC');
This obviously isn't working.
With the Zend documentation, I'm getting to this:
$select = $this->select()
->from(array('p' => 'products'),
array('product_id',
'order_column' =>
new Zend_Db_Expr('columnA * columnB'))
)
->order('order_column DESC);
However, this only returns the product_id and new order_column, but I need all columns.
How to get there? How to return all columns of the selected rows, ordered by columnA * columnB?
Too quick. I found the solution by trying:
$select = $this
->select()
->where('start_date < ' . $currentTime)
->where('end_date >' . $currentTime)
->order(new Zend_Db_Expr('columnA * columnB DESC'));
This gives the desired result.

database not inserting using PDO prepared statements

I have a paypal form which is submitted and working, this is part of the ipn, which means I can not see the error reporting on page which means I am a little blind on what is the issue.
Everything looks fine I think.
Here is the code:
$newcustom = rtrim($_POST['custom'], ',');
$buyingarray = explode('~', $newcustom);
$name = $buyingarray[1];
$phone = $buyingarray[2];
$email = $buyingarray[3];
$comments = $buyingarray[4];
$date = $buyingarray[5];
$time = explode(",",$tt[6]);
$person = explode(",",$tt[7]);
$orderID = $tt[0];
$booking_date = strtotime($date);
$nowitsdate = date('Y-m-d G:i:s', strtotime("now"));
$addreservation = $pdo->prepare("INSERT INTO reservations (id, dateCreated, name, email, phone, comments, status, eventID, voucherCode, voucherplace, OrderID) VALUES ('', :dateCreated, :name, :email, :phone, :comments, 1, NULL, '', 'PayPal Purchase', :OrderID)");
$addreservation->execute(array(':dateCreated' => $nowitsdate,':name' => $name,':email' => $email,':phone' => $phone,':comments' => $comments,':OrderID' => $orderID));
$addreservation_num = $addreservation->rowCount();
if($addreservation_num == 0){ $inserterror = $pdo->query("INSERT INTO testipn (id, testing, testing2) VALUES ('','Input into reservations died','')"); exit();}
Now I know that everything is ok with the details coming in as I have input each of the variables into the testipn row which is telling me if an error occurred when the ipn is being used.
As far as I can see everything looks fine yet it still is not finding the problem.
Now the only thing I can think it can be is the NULL within the eventID, maybe that is causing an issue?
If a ID is not present which it wont be within this table, then it needs to be NULL.
The rows effected is 0 which means my error row in the database says: Input into reservations died
Thanks for any input into finding a solution :)

Generate wrong "Update" query cakephp

I am trying to update data using below code but it is generating wrong SQL query. don't understand why it is generating wrong one. Please help me out.
$data = array();
$data['Pers']['etat'] = 1;
$data['Pers']['Activation'] = '';
$this->Pers->id = $results['Pers']['persID'];
$this->Pers->save($data);
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'bdr+.pers.persID' in
'where clause'
SQL Query: UPDATE `bdr+`.`pers` SET `etat` = 1, `Activation` = '',
`date_time` = '2014-03-19 11:33:21' WHERE `bdr+.pers.persID` = 37
It means bdr+.pers.persID is generating wrong. Don't understand why it is generating like this.
check if this $results['Pers']['persID'] variable if it is returning a proper format
then try this
$data = array();
$data['Pers']['persID'] = $results['Pers']['persID'];
$data['Pers']['etat'] = 1;
$data['Pers']['Activation'] = '';
//Just to make sure your model is loaded
$this->loadModel('Pers');
if ($this->Pers->save($data, false)) {
echo 'Pres has been saved :) ';
}
Your code containing bdr+.pers.persID` = '37' because $results['Pers']['persID'] supplying 37

Passing 2 strings through array to the where clause in codeigniter

I want to send 2 strings through array from controller to model and get the results from db, but there is a problem I'm facing.
My controller is like:
$data = array();
if($query = $this->authors_model->get_authors_list(array('author_Type' => array('admin', 'author'))))
{
$data['authors'] = $query;
}
My Model :
function get_authors_list($options = array())
{
if(isset($options['author_Type']))
$this->db->where('author_Type', $options['author_Type']);
$this->db->order_by('author_Id', 'ASC');
$query = $this->db->get('mg_authors');
return $query->result();
}
and the error I'm getting:
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: database/DB_active_rec.php
Line Number: 427
Error Number: 1054
Unknown column 'Array' in 'where clause'
SELECT * FROM (mg_authors) WHERE author_Type = Array ORDER BY
author_Id ASC LIMIT 15
Filename: D:\xampp\htdocs\sport\system\database\DB_driver.php
Line Number: 330
You need to use WHERE IN when you put array. In CodeIgniter, it need to do like this:
$this->db->where_in('author_Type', $options['author_Type']);

Resources