sql & pdo syntax error? [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 6 years ago.
Improve this question
i have a pdo statement for select all rows for row count.... i keep getting this error "Call to member function execute() on Boolean" ...i have tripple checked my statement and database table but cant find anything wrong
$stmt = $connection->prepare("SELECT * FROM users_profile WHERE email=:email");
var_dump($connection->error);
$stmt->execute(":email",$email);
$count = $stmt->rowCount();
Var dump error says there is a syntax error here " :email" ..but i cant seem to see it...and its doing this through out my PDO code

The execute function of PDO expect to get array of parameters
public bool PDOStatement::execute ([ array $input_parameters ] )
This is how you should use it in your code:
$stmt->execute( [":email" => $email] );

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");

Query doesn't update correctly in mySql [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 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

Count Days Student has Attended [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 7 years ago.
Improve this question
I'm trying to count up the days a student has attended class.
I need it to display the total attendance based on what member_id is logged in.
This is what I have so far:
$id_member = 3;
$query = "SELECT COUNT(attendance) AS day_at FROM day_attendance WHERE id_member=$id_member";
$response = #mysqli_query($dbc, $query);
$row = mysqli_fetch_array($response);
$day_at = $row["day_at"];
echo $day_at;
It throws this error: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /usr/www/user1/web/data/test.php on line 737
I think you misspelled the id column, should be member_id (as in your screen) and not id_member as in your sql query.
That's why mysqli_fetch_array print you a warning, because mysqli_query fail, and when it fail it returns a boolean (false). (Btw it's really bad to use the # character)

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

Categories