PDO Update statement, work in PHPmyadmin but not in PHP [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
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.
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.
Improve this question
I am trying to make an update statement with PDO and i found out it doesn´t work.
I have testet the SQL statement in phpMyadmin and it works if i put '' arround the passkey, but why wont it work with this ?
INFO:
The passkey is a md5 string
<?php
include('../mysql/pdoconn.php');
$passkey = $_GET['passkey'];
$stmt = $conn->prepare("UPDATE user SET com_code='' WHERE com_code = :passkey");
$stmt->bindParam(':passkey', $passkey , PDO::PARAM_STR);
$stmt->execute;
$error = "Jon Snow";
$stmt1 = $conn->prepare("SELECT com_code from user where com_code =''");
$stmt1->execute;
$result = $stmt1->fetchColumn();
if($result === "")
{
$error = 'Your account is now active. You may now Log in';
$conn = null;
} else
{
$error = $passkey;
$conn = null;
}
?>
i have tested that it gets the passkey, and it does, but it dont update the table...
I have tried anything, but i cant get it to work

$stmt = $conn->prepare("UPDATE user SET com_code='' WHERE com_code = :passkey");
$stmt->bindParam(':passkey', $passkey , PDO::PARAM_STR);
$stmt->execute();
execute() is a function
You don't need to quote bound parameters

Related

Uncaught PDOException: SQLSTATE[HY093] [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 3 years ago.
Improve this question
I get this erro: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\PHP\tennis\ronde2-wijziging.php:59
// code van het knop wijzigen
if(isset($_POST['wijzig'])){
$id = $_POST['id'];
$speler1 = $_POST['speler1'];
$speler2 = $_POST['speler2'];
$uitslag1 = $_POST['uitslag1'];
$uitslag2 = $_POST['uitslag2'];
$datum = $_POST['datum'];
$veld = $_POST['veld'];
//UPDATE: gegevens in de form wijzigen.
$sql = "UPDATE ronde1 SET speler1 = :speler1, speler2 = :speler2, uitslag1 = :uitslag1,
uitslag2= :uitslag2, datum= :datum, veld= :veld WHERE id=:id";
$stmt = $pdoConnect->prepare($sql); //stuur naar mysql.
$stmt->bindParam(":id", $id );
$stmt->bindParam(":speler1", $speler1 );
$stmt->bindParam(":speler1", $speler1 );
$stmt->bindParam(":uitslag1", $uitslag1 );
$stmt->bindParam(":uitslag2", $uitslag2 );
$stmt->bindParam(":datum", $datum );
$stmt->bindParam(":veld", $veld );
$stmt->execute();
// $_SESSION['message'] = "Speler is gewijzigd";
// $_SESSION['msg_type'] = "warning";
header("location: #.php");
exit;
}
I want to update my data.strong text
My solution worked but didn't explain why it did go wrong in the first place. The user dpant explains in the comments why your code snippet was not working.
Credits go to him
dpant:
Most probably the problem with your original code was that you were binding the :speler1 parameter twice (the :speler2 parameter was never bound). This was just a typo in your code. Take a close look at it.

What is the issue with this mysqli 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 am not quite sure how to convert the mysql code here to a mysqli version. I keep getting the error like:
Warning: mysql_result() expects parameter 1 to be resource, object given in....
Can you please help? thanks.
<?php
function the_user($username) {
$myqli = mysqli_connect("localhost", "root", "", "sometable");
$username = sanitize($username);
$user_query = mysqli_query($myqli, "SELECT COUNT('user_id') FROM 'users' WHERE 'username' = '$username'");
return (mysql_result($user_query, 0) == 1) ? true : false;
}
?>
The 's around the column names & table name. Should be -
SELECT COUNT(user_id) FROM users WHERE username = '$username'
Or backticks.
Also mixing mysql & mysqli.
Instead of mysql_result you should use mysqli like mysqli_fetch_array.
You should use :
$row = mysqli_fetch_array($user_query, MYSQLI_NUM);
return ($row[0] == 1) ? true : false;
Instead of:
return (mysql_result($user_query, 0) == 1) ? true : false;
Ofcourse don't forget to fix sql syntax as described in earlier answer:
$user_query = mysqli_query($myqli, "SELECT COUNT(user_id) FROM users WHERE username = '$username'")

PDO Variable Update Error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
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.
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.
Improve this question
these are my query codes. Please help me.
PDO Error: Array
PDO Eror Code: 00000
<?php if ($_POST){
$title = trim($_POST['title']);
$content = trim($_POST['content']);
$id = $_GET['id'];
$save = $PDO->prepare("UPDATE `news` SET `title` = :title WHERE `id` = :id");
$save->execute(array(
"title" => $title,
"id" => $id
));
print_r("Error: ".$save->errorInfo());
print $save->errorCode();
}
?>
It the OK status code.
You always print error but you should to print that only when the query failed.
$sql = $save->execute(...)
if ($sql === FALSE) {
print ('Error: ' . $save->errorCode());
}

pdo query not running [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 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
i can't seem to figure out why this query isn't running
if ( $productName && $productDescription && $productPrice ) {
// SQL
// UPDATE `prostud_tristurion`.`products` SET `product_title` = 'ajax test', `product_description` = 'Was certainty remaining engrossed applauded sir how discovery.', `product_price` = '524' WHERE `products`.`product_id` = 10;
try {
$query = "update products set product_title = :pName, product_description = :pDescription, product_price = :pPrice, where product_id = :pid";
//prepare query for excecution
$stmt = $con->prepare($query);
//bind the parameters
$stmt->bindParam(':pid', $id);
$stmt->bindParam(':pName', $productName);
$stmt->bindParam(':pDescription', $productDescription);
$stmt->bindParam(':pPrice', $productPrice);
// echo "$productPrice / $productDescription / $productName / $id\n $stmt";
var_dump($_POST);
// Execute the query
if ($stmt->execute() ) {
echo "Record was updated.";
} else {
die('Unable to update record.');
}
}catch(PDOException $exception){ //to handle error
echo "Error: " . $exception->getMessage();
}
}
all i get is Unable to update record.
var_dump($_POST);
is looking good
You have an errant comma at product_price = :pPrice, where
If your code reaches the die statement then you have exceptions turned off (not recommended) but you can get the error message from the database (to log or echo) with $stmt->errorInfo()

Unexepected T_VARIABLE [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 9 years ago.
Improve this question
Unexecpected T_VARIABLE in SQL Query on Line 5
How to fix this?
<?php
include "system.php";
$usersystem = $_SESSION['username'];
$passw = $_SESSION['password'];
$query= "SELECT * FROM users WHERE username = "$usersystem" AND password = "$passw";
$autoexec= $mysqli->query($query);
$earnings = $autoexec['earnings'];
$completed = $autoexec['completed'];
if ($_SESSION['loggedin'] !=1){
header ('Location: index.php);
}
?>
The syntax highlighter makes your issue obvious: quotes. You need to use single quotes for your strings in your query:
$query= "SELECT * FROM users WHERE username = '$usersystem' AND password = '$passw'";
Basic PHP syntax:
$query= "SELECT * FROM users WHERE username = "$usersystem" AND pas
^-- ^---
You cannot use the same type of quotes that you've used to delimit the string. Try
$query= "SELECT * FROM users WHERE username = \"$usersystem\" AND pas
^--- ^--- note the escapes
And since this is a simple typo-type problem, voting to close the question...

Categories