MySQL #1064 error for location finder [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 4 years ago.
Improve this question
I'm trying to find the 10 entries that are closest to the user with the following search:
$data_query = mysqli_query($db, "SELECT *
111.045 * DEGREES(ACOS(COS(RADIANS(latpoint))
* COS(RADIANS(latitude))
* COS(RADIANS(longpoint) - RADIANS(longitude))
+ SIN(RADIANS(latpoint))
* SIN(RADIANS(latitude)))) AS distance_in_km
FROM merchants
JOIN (
SELECT 33.889676 AS latpoint, 151.193024 AS longpoint
) AS p ON 1=1
ORDER BY distance_in_km
LIMIT 15");
However I'm getting the following error:
#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 '111.045 * DEGREES(ACOS(COS(RADIANS(latpoint))
* COS(RADIANS(la' at line 2
I tried changing SELECT * to SELECT latitude, longitude (with `` but Stack Overflow keeps messing up syntax) but it's not doing much.
I'm new to PHP and MySQL so I'm feeling pretty out of depth as to what could be going wrong here.
Cheers :)

If you want also select everything, then add comma after first *: SELECT *, 111.045 ...
If not, then remove first *

Related

1064 - You have an error in your SQL syntax; [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
This is my code below to find numbers starting 34 and 54 but i am getting the error
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 address LIKE '34%' at line 1, Time: 0.123000s
SELECT *
FROM db.table
WHERE uid = 'test'
AND WHERE destination_addr LIKE '34%'
AND WHERE address LIKE '54%';
What could i be doing wrong ?
Too many WHERE clause usage. Use only one WHERE like below-
SELECT *
FROM db.table
WHERE uid = 'test'
AND destination_addr LIKE '34%'
AND address LIKE '54%';
See Syntax: https://dev.mysql.com/doc/refman/8.0/en/select.html

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.

Count all recent posts from user - doesn't work [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 6 years ago.
Improve this question
I want to count all the posts from the user, from the last hour. This is my code:
$all_user_recent_posts=mysql_query("select * from user_post where user_id=$userid and where post_time >= DATE_SUB(NOW(),INTERVAL 1 HOUR);");
$count_user_recent_posts=mysql_num_rows($all_user_recent_posts);
This code doesn't work(it has the value 0). But when I delete and where post_time >= DATE_SUB(NOW(),INTERVAL 1 HOUR), it does work, but it show me ALL the post of the user, and not posts from the last hour. Code:
$all_user_recent_posts=mysql_query("select * from user_post where user_id=$userid;");
$count_user_recent_posts=mysql_num_rows($all_user_recent_posts);
As I stated in comments, and posting this as a community wiki because nothing should be gained from this in regards to rep points.
where user_id=$userid and where post_time it's a syntax error.
where user_id=$userid and post_time the where clause uses ONE where, not multiple and seperated by AND or OR.
Reference:
http://dev.mysql.com/doc/en/where-optimizations.html
and error checking against your query would have told you about it too.
http://php.net/manual/en/function.mysql-error.php
and should also be checked against your query, should there be any there also.
Add or die(mysql_error()) to mysql_query()
Error reporting is an additional tool you can use.
http://php.net/manual/en/function.error-reporting.php
Additionally, the post_time column must be a valid MySQL date type.
If you're trying to do math on a varchar type, then it won't work, or anything that isn't a valid date-related type.
Consult:
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
http://dev.mysql.com/doc/refman/5.7/en/date-and-time-types.html
It is unknown as to how you're using mysql_num_rows().
The following two examples will react differently.
if(mysql_num_rows($result) > 0)
and
if(mysql_num_rows($result) == 1)
You have an extra where in your query
near
and where post_time >= DATE_SUB(NOW(),INTERVAL 1 HOUR);
Replace your with this
$all_user_recent_posts=mysql_query("select * from user_post where user_id=$userid and post_time >= DATE_SUB(NOW(),INTERVAL 1 HOUR);");
Hope that helps :-)

Mysql error 1064.PHP when select data with forward slashes [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 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

multiple number select statement sql [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
looking for something like
Select * FROM 'database' WHERE id = 1-40
something where I can select a number through a number like 1 through 40
multiple number select statement sql
SELECT * FROM database_table WHERE id BETWEEN 1 AND 40
This is an example page you can use: http://www.w3schools.com/sql/trysql.asp?filename=trysql_select_between
The between operator is what you're looking for:
SELECT * FROM `database` WHERE id BETWEEN 1 AND 40
Try:
Select * FROM `tablename` WHERE id >= 1 AND id <= 40
Two possible ways for selecting range in DB:
Select * FROM `database.tablename` WHERE id BETWEEN 1 AND 40 ;
or
SELECT * FROM `DATABASE.TABLENAME` WHERE ID >= 1 AND <=40;
In case, you want to select multiple items which are not in range, you can use:
Select * FROM `database.tablename` WHERE id in (1,2,3,4,5,6.....40);

Categories