wordpress plugin sql synatax - mysql

problem in Mashable Slider Clone plugin when uload it in server
WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 3] SELECT * FROM wp_mash_fields WHERE docid IN()
code for this is
$sql = "SELECT *
FROM $this->flds
WHERE docid IN(".implode(',' , array_keys($r)).")";
$r2 = $this->db->get_results($sql, ARRAY_A);
WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0,999' at line 3] SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_mash_documents.* FROM wp_mash_documents WHERE wp_mash_documents.type='image' ORDER BY wp_mash_documents. LIMIT 0,999;
code for this is
function get($type, $page = 0, $limit = 10, $sort = 'modify_time', $ord = 'ASC', $rel = null, $dorder = false, $s = null)
{
$ll = $page * $limit;
$docs = $this->docs;
$flds = $this->flds;
$rels = $this->rels;
$inner = array();
$where = array();
$order = '';
// get ids
$sql = "SELECT SQL_CALC_FOUND_ROWS DISTINCT $docs.*".($dorder? ",$rels.dorder" : "")." FROM $docs";
switch ($sort) {
case "title":
$inner[$flds] = array("$docs.id", "$flds.docid");
$where["$flds.name"] = "='title'";
$order = "$flds.value_text $ord";
if (isset($s)) {
$where["MATCH ($flds.value_text)"] = " AGAINST ('$s')";
}

Given your error message:
ORDER BY wp_mash_documents. LIMIT 0,999;
^---missing field name

Related

issue in mysql query in codeigniter only if I add if condition

In below code, whenever I am adding below code with if conditions, i am getting error
if($this->ion_auth->is_customer())
$this->db->where('company_database.cdb_customer_id',$this->session->userdata('user_id'));
$this->db->select('company.*, cities.name as company_city, states.name as company_state, countries.name as company_country');
$this->db->from('company as company');
$this->db->join(CITIES.' as cities','cities.id = company.company_city_id' ,'left');
$this->db->join(STATES.' as states','states.id = company.company_state_id' ,'left');
$this->db->join(COUNTRIES.' as countries','countries.id = company.company_country_id' ,'left');
$this->db->join(COMPANY_DATABASE.' as company_database','company_database.cdb_company_id = company.company_id' ,'left');
if($this->ion_auth->is_customer())
$this->db->where('company_database.cdb_customer_id',$this->session->userdata('user_id'));
$this->db->where('company.company_delete_status',NOT_DELETED);
$query = $this->db->get();
echo '<pre>';
echo $this->db->get_compiled_query();
print_r($query->result());
echo $this->db->last_query();
What is the issue above query ?
I am getting below issue related to query
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `company_database`.`cdb_customer_id` = '19' AND `company`.`company_delete_' at line 2
SELECT * WHERE `company_database`.`cdb_customer_id` = '19' AND `company`.`company_delete_status` = 0
Filename: controllers/Test.php
Line Number: 112
You don't have a "from" clause in your where clause.
select * {from company} where 'company_database'.'cdb_customer_id' = ....
I suspect that the function
$this->ion_auth->is_customer()
may be calling another DB query and that pretty much completes the query you started above and once completed it does the $this->db with just the where clauses after.
To fix call the $this->ion_auth->is_customer() before you do $this->db->select and then in the IF statement simply just use the boolean returned so you don't
make another call to a query while you form another query.
Example:
--ADD THIS LINE
$bIsClient = $this->ion_auth->is_customer();
$this->db->select('company.*, cities.name as company_city, states.name as company_state, countries.name as company_country');
$this->db->from('company as company');
$this->db->join(CITIES.' as cities','cities.id = company.company_city_id' ,'left');
$this->db->join(STATES.' as states','states.id = company.company_state_id' ,'left');
$this->db->join(COUNTRIES.' as countries','countries.id = company.company_country_id' ,'left');
$this->db->join(COMPANY_DATABASE.' as company_database','company_database.cdb_company_id = company.company_id' ,'left');
--AND CHANGE THIS
if($bIsClient)
$this->db->where('company_database.cdb_customer_id',$this->session->userdata('user_id'));
$this->db->where('company.company_delete_status',NOT_DELETED);
$query = $this->db->get();
echo '<pre>';
echo $this->db->get_compiled_query();
print_r($query->result());
echo $this->db->last_query();

Uncaught PDOException: SQLSTATE[42000] With Where IN

I'm running Panda Resort CMS locally on XAMP, PHP 8.0.3, Mariadb/Phpmyadmin 5.1.0 so the "article" module is returning a SQLSTATE error:
1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') AND checked = 1 AND lang = 1 ORDER BY rank'
Exactly at line 28
<?php
if($article_alias == "") err404();
if($article_id > 0){
$title_tag = $article['title']." - ".$title_tag;
$page_title = $article['title'];
$page_subtitle = $article['subtitle'];
$page_alias = $article['alias'];
$publish_date = $article['publish_date'];
$edit_date = $article['edit_date'];
if(is_null($publish_date)) $publish_date = $article['add_date'];
if(is_null($edit_date)) $edit_date = $publish_date;
$result_article_file = $db->query(
"SELECT *
FROM pm_article_file
WHERE id_item = ".$article_id."
AND checked = 1
AND lang = ".DEFAULT_LANG."
AND type = 'image'
AND file != ''
ORDER BY rank
LIMIT 1");
if($result_article_file !== false && $db->last_row_count() > 0){
$row = $result_article_file->fetch();
$file_id = $row['id'];
$filename = $row['file'];
if(is_file(SYSBASE."medias/article/medium/".$file_id."/".$filename))
$page_img = getUrl(true).DOCBASE."medias/article/medium/".$file_id."/".$filename;
}
$result_tag = $db->query("SELECT * FROM pm_tag WHERE id IN (".$article['tags'].") AND checked = 1 AND lang = ".LANG_ID." ORDER BY rank");
if($result_tag !== false){
$nb_tags = $db->last_row_count();
$article_tags = "";
foreach($result_tag as $i => $row){
$tag_id = $row['id'];
$tag_value = $row['value'];
$article_tags .= $tag_value;
if($i+1 < $nb_tags) $article_tags .= ", ";
}
}
}else err404();
check_URI(DOCBASE.$page_alias);
I'm really stuck at this one any help would be appreciated. Thank you!
Be careful to check if your variables are empty before you interpolate them into an SQL query. If $article['tags'] is empty, you could end up with a query like this:
SELECT * FROM pm_tag WHERE id IN () AND checked = 1 AND lang = 123 ORDER BY rank
It's a syntax error to run an IN() expression with an empty list. There has to be at least one value inside the parentheses.
One way you can reduce this risk is to stop using string-interpolation, and start using query parameters. This is safer for several reasons, and it also makes it easier to write code because you don't have to get eyestrain counting your open-quote-close-quote-open-quote-close-quote-open-quote-close-quotes.

check the manual that corresponds to your MySQL server version for the right syntax to use near ' masalah = 'dsd' AND gambar = 'kerusi.JPG'' at line 1

I want to add record to a table which contain a picture. when i try to add, it shows me this error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' masalah = 'dsd' AND gambar = 'kerusi.JPG'' at line 1
so, here are the code
<?php
session_start();
include("Connections/connection.php");
$date = $_POST['date'];
$masalah = $_POST ['masalah'];
$gambar = $_POST ['gambar'];
$student_id = $_POST['student_id'];
$status = 'pending';
/*session yg di call tok lecturer tu*/
$student_id = "SELECT * FROM student WHERE student_id ='".$_SESSION['student_id']."'" ;
$result=mysql_query($student_id);
$getstudentid = mysql_fetch_assoc($result);
$student_id = $getstudentid['student_id'];
/*take 3 data from rc */
$sql = "SELECT * FROM aduan WHERE date = '$date', masalah = '$masalah' AND gambar = '$gambar' ";
$rr = mysql_query($sql) or die(mysql_error());
$tt = mysql_num_rows($rr);
if($tt > 0) {
header("Location: borang_aduan2.php?error=2");
} else { /*to check tarikh*/
$tarikh_user = strtotime($date);
$tarikh_harini = strtotime(date('Y-m-d'));
if($tarikh_user < $tarikh_harini) {
//error
header("Location: borang_aduan2.php?error=1");
} else {
//$No = $num_rows+1;
/*$sql_const = mysql_query ("Select MAX(user_name)as id from lecturer")or die (mysql_error());
$rows = mysql_fetch_array ($sql_const);
$id = $rows ['id'];*/
/*insert data*/
mysql_query("INSERT INTO aduan (date, masalah, gambar, student_id )
VALUES('$date','$masalah', '$gambar','$student_id')")
or die('Error: ' .mysql_error($conn));
echo "<script type='text/javascript'>
alert('Thanks make a report!')
location.href='borang_aduan2.php'
</script>";
}
//Freeing all memory associated with it
mysql_free_result($result);
//Closes specified connection
mysql_close($conn);
}
?>
Dont use "," in between two field selection criteria. So instead of:
SELECT * FROM aduan WHERE date = '$date',
^^
Use
SELECT * FROM aduan WHERE date = '$date' AND

PDO statement error #1064

I am trying to move from PDO quote et PDO prepare and execute, my query is like:
$sql = 'SELECT * FROM nav_top1 WHERE id_top = (SELECT top_fr FROM nav_top WHERE top_fr = :rub ORDER BY top1_order ASC';
echo $sql.'<br>';
$query = $connexion->prepare($sql);
$query->bindParam(':rub', $rub, PDO::PARAM_INT);
$query->execute();
$list = $query->fetchAll();
foreach ($list as $rs) {
$top1_fr = $rs['top1_fr'];
echo $top1_fr;
}
but I get an error:
[Sat Mar 07 14:08:05 2015] [error] [client 105.156.126.211]
PHP Warning: PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 in /home/www/Fashion/fashion.php on line 9, referer...
Thanks in advance
missing brace?
top1_order ASC)
$sql = 'SELECT * FROM nav_top1 WHERE id_top = (SELECT top_fr FROM
nav_top WHERE top_fr = :rub ORDER BY top1_order ASC';
Your are missing braces.
$sql = 'SELECT * FROM nav_top1 WHERE id_top = (SELECT top_fr FROM
nav_top WHERE top_fr = :rub ORDER BY top1_order ASC');

SQL statement not working SELECT 1064 Error in your SQL syntax

My SQL statement doesn't work...
Here is my variable:
$email="test#test.com";
These statements doesn't work :
$sql = "SELECT * FROM table WHERE email = $email";
$sql = 'SELECT * FROM table WHERE email = ' . $email;
1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '#test.com' at line 1
But if I use a string instead of the variable, it works:
$sql = "SELECT * FROM table WHERE email = 'test#test.com'";
What's wrong with my statement?
Thanks!
please escape strings in mysql
$sql = "SELECT * FROM table WHERE email = $email";
$sql = 'SELECT * FROM table WHERE email = ' . $email;
This should work
$sql = "SELECT * FROM table WHERE email = '$email'";
table is a keyword, so can write like this
$sql = "SELECT * FROM `table` WHERE email='$email'";
$this->db->where('email', $this->input->post('email'));
$query =$this->db->get($this->user);
//$sql = "SELECT * FROM user WHERE email = '$email'";
if($query->num_rows == 1)
{
return true;
}
else
{
return false;
}
}
}