Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 8 years ago.
Improve this question
I need to insert image row from table 'users2' to 'allbets'. But suddenlly this code don't working and I don't know why.. What is wrong with this?
$q2 = $pdo->prepare('INSERT INTO allbets (image) SELECT users2.image FROM users2 WHERE username = ?');
$q2->bindValue(1, $_SESSION['name']);
$q2 -> execute();
This code did not suddenly stop working, it never could have worked with its present query syntax. Change the query to this -
$q2 = $pdo -> prepare('INSERT INTO allbets (user, bet, komanda, teams, cof, data, image) VALUES ($user, $bet, $komanda, $teams, $cof, $data, (SELECT `users2`.`image` FROM `users2` WHERE `username` = ?));
Do yourself a service and error checking to your PHP code and to your PDO. This will let you know where to look when errors occur.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 1 year ago.
Improve this question
When I put a number myself the database gets updated to Success but when I try to access the same number from $_POST It complete the transaction but doesn't affect the rows even thought it's using the same number.
Example of a query that works perfectly and updates the database
$sql = "UPDATE `transactions` SET `status` ='Success' WHERE `transactions`.`txn_id` = 65765756";
Example of a query that doesn't work
$sql = "UPDATE `transactions` SET `status` ='Success' WHERE `transactions`.`txn_id` = ".$_POST['m_payment_id'];
First, check what's in the value, and make sure it is the same as what you are manually entering.
var_dump($_POST['m_payment_id'])
Second, the code without any other checks is a SQL injection vulnerability.
You could convert the value into an integer to protect against this, e.g. intval($_POST['m_payment_id'])
Ideally though, you would be using bindings.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 4 years ago.
Improve this question
$statement = $pdo->prepare("UPDATE config SET (name, value) VALUES(:name, :value) WHERE id = 1");
Hello, i need your Help, i know her is a syntax error but i dont know what is the syntax error.
Can you Help
Separate assignments for the set:
UPDATE config
SET name = :name,
value = :value
WHERE id = 1;
The syntax for UPDATE has not changed in MySQL and has never (to the best of my knowledge) included a VALUES clause. The documentation is pretty clear on the subject. If you don't think the documentation is clear, you can provide feedback on it.
Here is a full code:
$id = 1;
$sql = "UPDATE config SET `name`=?, `value`=? WHERE id=?";
$stmt= $dpo->prepare($sql);
$stmt->execute([$name, $value, $id]);
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 6 years ago.
Improve this question
I have one table which need to find all date and put the name just once (this is workig = $sql), but i have problem to select the that name of data and count how much time is repeats in same table. So where is name Test(down) there needs to be count for how much time that name repeats in whole table.
If I put one more while function the table dies.
Im stacked. Im not very good with php and mysql. If someone can help.
$sql = "SELECT DISTINCT one,two FROM results";
$sql2 = "select test, count(*) as foo_count from results group by test;";
$result = mysqli_query($conn,$sql);
$result2 = mysqli_query($conn,$sql2);
<?php
while($row = mysqli_fetch_assoc($result)) {
echo "<tr><td>".$row["one"]."</td><td>".$row["two"]."</td><td>";}?> Test</td></tr>
I'm having a little bit of a hard time following your question, but I think you are looking for a single sql statement like this
$sql = "select test, count(one) as foo_count from results group by test";
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 5 months ago.
Improve this question
I have this code
$SQL = "UPDATE cart SET a = ? WHERE b = ? AND c = ?";
if($stmt2 = mysqli_prepare($conn, $SQL )){
mysqli_stmt_bind_param($stmt2, "iii", $a1, $b1, $c1);
mysqli_stmt_execute($stmt2);
if(mysqli_affected_rows($conn)){
echo "updated";
mysqli_stmt_close($stmt2);
}
else
echo "nope";
}
I was figuring out why above code never work. I have debug every way that I know.
Lastly I delete the if condition. Somehow, it is working. Tried to browse on the internet to figure out what is the cause but did not find any. Can somebody please explain to me why does it happen so?
You should be using
mysqli_stmt_affected_rows($stmt2);
mysqli_stmt::$affected_rows -- mysqli_stmt_affected_rows — Returns the total number of rows changed, deleted, or inserted by the last executed statement
Instead of
mysqli_affected_rows($conn);
which is for plain query executions.
Manual
Edit
I just noticed that your question title mentions the right function name, and your code uses the wrong one.
Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 7 years ago.
Improve this question
I've been trying to insert a tuple into my relation, but it doesn't seem to work.
<?php
$link=mysql_connect ("connection", "name", "pw");
mysql_select_db('pizzaria');
$sql = "INSERT INTO pizza_bakery (Name, Address, Telenum)
VALUES ('Test', 'Test', '111')";
?>
The connection seems to go through ok, as I'm able to print the table out easily on my html page, why is this failing?
Your insert statement should look something like this:
$sql = "INSERT INTO pizza_bakery (Name, Address, Telenum)
VALUES ('Test', 'Test', 111)";
Reason: The last column (Telenum) is an integer datatype and the insert statement was treating it like a string.