PHP T string error for sql statement [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm having a strange error with my PHP code. it says there is a unexpected T_CONSTANT_ENCAPSED_STRING error, but I simply can't see it.
$dateResult = mysqli_query($connection, 'select county, cuisine,
count(*) from inspection, restaurant where inspection.rid =
restaurant.rid and inspection.passfail = ''PASS'' and idate like '$date%'
group by county, cuisine');
I'm assuming its an issue with either my like pattern '$date%' or with 'PASS'.
Thank you!

Try this your are conflicting ' and "
$dateResult = mysqli_query($connection, "select county, cuisine,
count(*) from inspection, restaurant where inspection.rid =
restaurant.rid and inspection.passfail = 'PASS' and idate like '$date%'
group by county, cuisine");

Related

PDO Prepared Statements How to Select From Database Where Id = Value or Tell = Value [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I want to Select one record from a table Named 'sms_students' by using Student Id or Student Telephone
Here is My Code
$student_rand_id=$_GET['std_rand'];
$std_tell=$_GET['std_tell'];
$view_student = $config->prepare("SELECT * FROM sms_students WHERE st_rand = :random_id || st_tel =: st_tel");
$view_student->execute(['random_id' => $student_rand_id]);
$view_student->execute(['st_tel' => $std_tell]);
$row = $view_student->fetch();
Since you call execute twice, this executes twice, both times with an incomplete set of arguments. It's an easy fix though:
$view_student = $config->prepare("SELECT * FROM sms_students WHERE st_rand = :random_id OR st_tel = :st_tel");
$view_student->execute(['random_id' => $_GET['std_rand'], 'st_tel' => $_GET['std_tell'] ]);
$row = $view_student->fetch();
Try and get rid of single-use variables, they're almost always unnecessary, and do try and steer towards having names that match precisely. Seeing st_tel and std_tell together is a sign something's not quite right. Get your code to agree on names and stick with them.

How to count distinct columns query? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I have to find the total number or records but count is based on distinct of multiple columns.
I have following lines in my query.
$query = $this->createQueryBuilder("j");
$query->select(
"COUNT(DISTINCT
'j.mark',
'j.model'
) as total");
But this is giving me error:
[Syntax Error] line 0, col 76: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ','
Can anybody please help me solve this issue?
Thank You.
I used concat instead which worked for me. But I am not sure if its the correct solution or not.
$query->select(
"COUNT(DISTINCT(concat(j.mark, j.model))
) as total");

Error Get Data SQL from controller PHP CI [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
i getting data sql from controller and here is my code
$qr = $this->db->query("select journalDetail.JOURNAL_ID, JOURNAL_TYPE_CODE, JOURNAL_NUMBER, JOURNAL_MEMO, COA_CODE, JOURNAL_DETAIL_DESC, CURRECY_ID, JOURNAL_DETAIL_ORIG, JOURNAL_DETAIL_SUM, JOURNAL_DETAIL_TYPE, date_format(JOURNAL_DATE,'%d %M %Y') AS DATE, from t_journal_detail journalDetail left join t_journal journal on journalDetail.journal_id=journal.journal_id where JOURNAL_DETAIL_ID = '".$journalDetailId."'");
$gen = $qr->result();
But my code was 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 'from t_journal where JOURNAL_ID = '83'' at line 1
select JOURNAL_NUMBER, JOURNAL_MEMO, date_format(JOURNAL_DATE,'%d %M %Y') AS DATE, from t_journal where JOURNAL_ID = '83'
Please i need help i don't know to fix this syntax
You have a comma (,) before the from keyword: and after 'AS DATE'-
date_format(JOURNAL_DATE,'%d %M %Y') AS DATE, from t_journal_detail
Remove the comma and I think your problem will be solved.

MYSQL select query with union [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am trying to run following query:
$result = mysql_query(SELECT SecurityQues FROM reg_indi WHERE UserName='$usrnm') UNION (SELECT SecurityQues FROM reg_ac WHERE UserName='$usrnm');
But i am getting error in this syntax.
What is the error?
You need to put the query in quotes because for PHP it's a string, your parenthesis are wrong too:
$result = mysql_query(
"SELECT SecurityQues
FROM reg_indi
WHERE UserName='" . $usrnm . "'
UNION
SELECT SecurityQues
FROM reg_ac
WHERE UserName='" . $usrnm . "'"
);
Btw mysql_ extension is deprecated and removed from more recent PHP versions. Use PDO or MySQLi instead.

SQL WHERE syntax error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
When I run:
$query = "UPDATE subjects SET
menu_name = '{$menu_name}',
position = {$position},
visible = {$visible},
WHERE ID = {$ID}";
$result = mysql_query($query, $connection);
I get back:
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 ID = 1' at line 5
Remove this comma before the WHERE clause. Since there are no more values to update, the comma is not needed and hence causes a syntax error.
visible = {$visible},
^

Categories