1

i try to use PDO but i get 1,1,1 for result but database wont updated. I dont know whats wrong with my code.

try {$db = new PDO("mysql:dbname=$db_name;host=$db_host", $db_user, $db_pass );}
catch(PDOException $e){echo $e->getMessage();}

$title_insert = $db->prepare("UPDATE topics SET topic_title = ? WHERE id = ?");
$title_insert->bindParam(1, $id);
$title_insert->bindParam(2, $topic_title);

$tag_insert = $db->prepare("UPDATE topics SET topic_tags = ? WHERE id = ?");
$tag_insert->bindParam(1, $id);
$tag_insert->bindParam(2, $topic_tags);

$story_insert = $db->prepare("UPDATE topics SET topic_story = ? WHERE id = ?");
$story_insert->bindParam(1, $id);
$story_insert->bindParam(2, $topic_story);


$id = 1;
$topic_title = "title";
$topic_tags = "tags";
$topic_story = "story";

$result_title = $title_insert->execute();
echo $sonuc_title.',';

$sonuc_tag = $tag_insert->execute();
echo $sonuc_tag.',';

$result_story = $story_insert->execute();
echo $result_story;

Thanks for answers...

1
  • Do you really need 3 UPDATE's on 1 record? Commented Jan 8, 2014 at 12:01

2 Answers 2

2

Have you tried switching the param numbers?

$title_insert = $db->prepare("UPDATE topics SET topic_title = ? WHERE id = ?");
$title_insert->bindParam(1, $topic_title);
$title_insert->bindParam(2, $id);

Good luck!

PDO Bind param

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

Comments

0

you should affect your variable before the bind statement :

$id = 1;
$topic_title = "title";
$topic_tags = "tags";
$topic_story = "story";

$title_insert = $db->prepare("UPDATE topics SET topic_title = ? WHERE id = ?");
$title_insert->bindParam(1, $id);
$title_insert->bindParam(2, $topic_title);

$tag_insert = $db->prepare("UPDATE topics SET topic_tags = ? WHERE id = ?");
$tag_insert->bindParam(1, $id);
$tag_insert->bindParam(2, $topic_tags);

$story_insert = $db->prepare("UPDATE topics SET topic_story = ? WHERE id = ?");
$story_insert->bindParam(1, $id);
$story_insert->bindParam(2, $topic_story);


$result_title = $title_insert->execute();
echo $sonuc_title.',';

$sonuc_tag = $tag_insert->execute();
echo $sonuc_tag.',';

$result_story = $story_insert->execute();
echo $result_story;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.