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 have a table named ORDER with the title order_date where I need to put the date.
function NewOrderID()
{
$date = date('Y-m-d H:i:s');
$t = "INSERT INTO order (order_date)
VALUES (' ".$date." ')";
$query = sprintf($t);
$result = mysql_query($query);
if (!$result)
die(mysql_error());
return mysql_insert_id();
}
and I got the following 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 'order ('order_date')
VALUES (' 2014-04-29 15:02:40 ')' at line 1
Any ideas where I messed up with the query?
Order is reserved word in MySQL, you can use back tick(`) around table name
Also you can use MySQL NOW() function for date instead of PHP variable $date
$t = "INSERT INTO `order` (order_date) VALUES (NOW())";
Firstly, You are using mysql_* functions which are now deprecated and will be removed from PHP in the future. So you need to start using MySQLi or PDO instead.
Your getting MYSQL error because :
order is reserved keyword of MYSQL so you have to use back ticks ` around your tablename :
$t = "INSERT INTO `order` (order_date) VALUES ('".$date."')";
Related
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.
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 am writing a query which takes a pair of dates from user and searches whether it overlaps with any of the start and end column dates in my database table.
$from = $_GET['from'];
$to = $_GET['to'];
$sql="select bikeid from bikebookings where date('Y-m-d',strtotime(str_replace('/', '-', $from))) <= end and date('Y-m-d',strtotime(str_replace('/', '-', $to))) >= start";
mysqli_query($link,$sql) or die(mysqli_error($link));
I am getting an error as follows:
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 'strtotime(str_replace('/', '-', 20/03/2018))) <= end and date('Y-m-d',strtotime(' at line 1
You should use use mysql str_to_date function and for avoid sql injection. You should use binding param. For example:
$stmt = $mysqli->prepare("select bikeid from bikebookings
where str_to_date( ?, '%Y-%m-%d') <= end and str_to_date( ?, '%Y-%m-%d') >= start");
$stmt->bind_param('ss',$from, $to);
$stmt->execute();
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
The following is my query:
$sql = "SELECT date, status, reason
FROM tbl_attendance_mgmt ORDER BY date $order
LIMIT $number
WHERE fk_stu_id = '$stu_id'";
Here:
$order: ASC or DESC
$number: Number of rows to be displayed.
Can someone please help me out why this query gives me the error while executing it?
You must have follow sequence for sql query. WHERE place before order by clause
$sql = "select `date`, status, reason from tbl_attendance_mgmt where fk_stu_id = '$stu_id' order by `date` $order limit $number";
Write your query this way:
$sql = "SELECT date, status, reason
FROM tbl_attendance_mgmt
WHERE fk_stu_id = '{$stu_id}'
ORDER BY date $order
LIMIT $number ";
You have to bind your php variables using curly braces{}
$sql = "SELECT date, status, reason
FROM tbl_attendance_mgmt
WHERE fk_stu_id = " . mysqli_real_escape_string($con, $stu_id) . "
ORDER BY date $order
LIMIT $number ";
You should escape your variables
A query should be in this order: SELECT, FROM, WHERE, ORDER BY, and LIMIT:
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 try to execute this query with PHP. but mysql server is giving to error like this.
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 'index='CEA/EO/MA/0001'' at line 1. What is the reason for that?
My PHP code part is
$index = ($_POST['index']);
$sql = "SELECT * FROM results WHERE index='CEA/EO/MA/0001'";
$query = mysql_query($sql) or die(mysql_error());
index is a reserved keyword in MySQL. If you're going to name a column index you wrap it in backticks:
$sql = "SELECT * FROM results WHERE `index`='CEA/EO/MA/0001'";
Refer to the following page for the full list of MySQL reserved words:
http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
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},
^