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.
Related
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 7 years ago.
Improve this question
I'm having problems with a query that should "rank an user to 3" but instead in the MySQL it gives to the user X rank 0.
Here is the code
if($_POST['rank'] == '3')
{
mysql_query("UPDATE users SET rank='3' AND LPT='1' where username='".$_post['u_name']."' LIMIT 1")or die(mysql_error());
$query = true;
}
Waiting for answers
Use comma instead of AND when updating multiple columns:
UPDATE users
SET rank='3',
LPT='1'
where username= ?
You should:
Use parametrized query instead of concatenating SQL string
$_post is a superglobal and must be in uppercase $_POST
Reference: http://php.net/manual/en/language.variables.superglobals.php
Additional reference:
UPDATE http://dev.mysql.com/doc/refman/5.7/en/update.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 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");
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},
^