PHP mariaDB updating token in database [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 1 year ago.
Improve this question
i have some trouble to find the correct syntax to update a token in a database.
I'm having some trouble trying to fine the correct syntax in order to write a query that updates a token in the database.
This is what my current attempt looks like:
$sql = "UPDATE ComptePro
SET `Token` = :Token,
WHERE `Index` = :Index";
echo $Indexuser;
echo " ";
echo $token;
$req = $bdd->prepare($sql);
$req->bindParam(':Token', $token, PDO::PARAM_STR);
$req->bindParam(':Index', $Indexuser, PDO::PARAM_INT);
$req->execute();
Though this is the error I am getting:

$sql = "UPDATE ComptePro
SET `Token` = :Token, <----problem is here
WHERE `Index` = :Index";
If you remove the comma, that code should run ok

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.

SQL in PHP seems to not 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 7 years ago.
Improve this question
I want to write some Data in my MySQL database but it seems to not work.
All the variables are filled, tested it by echoing them. Now I want to insert them into my sip table but it just doesnt do it.
Where did I go wrong on this?
echo $a_dw.$a_name.$a_an.$a_pw."<br>";
$sql = "INSERT INTO sip VALUES ('".$a_dw."','".$a_name."', '".$a_an."', '".$a_pw."')";
mysql_query($sql);
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
You forgot the column names.

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

PHP T string error for sql statement [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 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");

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