0

im trying to execute an UPDATE query in Mysqli OOP. I know there are many tutorials in google but nothing worked for me :( I will appreciate if someone could write a simple code with a simple query example that will include all neccesery steps begining with creating a connection object.

this is my code, i tried to echo some things to try to find a problem. outputs are OK except the line "echo "test2"; that echo and the code below are not executed..

<?php if ((isset($_POST['title'])) && (isset($_POST['post']))) { $title= $_POST['title']; $post= $_POST['post']; $date = date("d-m-Y H:i"); //UPDATE post echo $title, $post, $_SESSION['rec_id']; $stmt = $connection->query("UPDATE blog_post SET title=? AND post=? WHERE id=?"); echo 'test1'; $stmt->bind_param("ssi", $title , $post, $_SESSION['rec_id']); echo 'test2'; printf("Affected rows (UPDATE): %d\n", $connection->affected_rows); } ?> 
2
  • 1
    Nobody will do your work for you. Start it from the connection down to the query lets see where you are getting it wrong. Then can you get help here. Commented Sep 30, 2013 at 9:48
  • @Chibuzo I didnt ask for any one to do the work for me, i just wanted someone to explain me the steps i need to do. im a beginner in PHP. Commented Sep 30, 2013 at 13:13

1 Answer 1

2

Your MYSQL is wrong.

UPDATE blog_post SET title=? AND post=? WHERE id=? 

Should be

UPDATE blog_post SET title=?, post=? WHERE id=? 

You should always use some kind of error checking, like the following,

if(!$stmt = $connection->prepare("UPDATE blog_post SET title=?, post=? WHERE id=?")){ die($connection->error); } 

You also never called $stmt->execute();.

Also you can't use $stmt = $connection->query(); with prepared statements. Use $stmt = $connection->prepare();.

Sign up to request clarification or add additional context in comments.

1 Comment

You can bind the parameters for the query before or after preparing it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.