Hi guys!
I have a slight problem. When I pass values as variables to a sql statement it doesnt work. This is the example:
THIS WORKS:
[php]<?php
require ‘DB/dbinc.php’;
try {
// Connect and create the PDO object
$conn = new PDO(“mysql:host=$dbhost; dbname=$dbname”, $usernm, $dbpass);
$conn->exec(“SET CHARACTER SET utf8”); // Sets encoding UTF-8
// changes data in “text” and “text” where title = some title
$sql = “UPDATE bloging SET title=‘Novi Title’, tekst=‘Novi tekst’ WHERE title=‘Update post’”;
$count = $conn->exec($sql);
$conn = null; // Disconnect
}
catch(PDOException $e) {
echo $e->getMessage();
}
// If data added ($count not false) displays the number of rows added
if($count !== false) echo 'Number of rows added: '. $count;
?>[/php]
THIS DOES NOT WORK
[php]<?php
require ‘DB/dbinc.php’;
$oldTitle = ‘Stari naslov’;
$nTitle = ‘novinaslov’;
$nText = ‘novitekst’;
try {
// Connect and create the PDO object
$conn = new PDO(“mysql:host=$dbhost; dbname=$dbname”, $usernm, $dbpass);
$conn->exec(“SET CHARACTER SET utf8”); // Sets encoding UTF-8
// changes data in “text” and “text” where title = some title
$sql = “UPDATE bloging SET title=$nTitle, tekst=$nText WHERE title=$oldTitle”;
$count = $conn->exec($sql);
$conn = null; // Disconnect
}
catch(PDOException $e) {
echo $e->getMessage();
}
// If data added ($count not false) displays the number of rows added
if($count !== false) echo 'Number of rows added: '. $count;
?>[/php]
I don’t get it why it wont accept variable instead of string text as a value?
Thanx in advance!