Forum Moderators: coopster

Message Too Old, No Replies

INSERT INTO problem - help

Prepared Statement

         

bethesda

5:23 pm on Nov 22, 2011 (gmt 0)

10+ Year Member



Hi, did i do something wrong ?
Code below:


$db = new mysqli('X', 'X', 'X', 'X');
$db -> query("SET NAMES 'latin2'");
$stmt = $db->stmt_init();
if($stmt->prepare("INSERT INTO `a` SELECT `*` FROM `b` WHERE `c` = ?")) {
$stmt->bind_param('s', $a);
$a = "$user";
if (!$stmt) {
$feedback1 = die(mysql_error());
echo "myscript.php error #206 $feedback1";
$stmt->close();
$db->close();
}} else {
echo "Everything OK !";
}


I don't have any errors.
Data from table a wont copy to table b..

gholiath

5:49 pm on Nov 22, 2011 (gmt 0)

10+ Year Member



Hi im not 100% sure on this as im new, but you might try this:

add an equal sign to set the "NAMES" to 'latin2:
$db -> query("SET NAMES = 'latin2'");

And remove the extra quote characters on your query:
if($stmt->prepare("INSERT INTO a SELECT * FROM b WHERE c = ?"))

If its completely wrong sorry im a noob, but thats what stood out for me :D
Hope it helps!

gholiath

5:53 pm on Nov 22, 2011 (gmt 0)

10+ Year Member



However it might be because, you need to setup your select statement first, then import all data from the selection into 'a'.

eelixduppy

6:01 pm on Nov 22, 2011 (gmt 0)



You are not calling execute...

$stmt->execute();


[php.net...]

bethesda

6:03 pm on Nov 22, 2011 (gmt 0)

10+ Year Member



I found the solution by adding


$stmt->execute();


my bad ;) ! im forgot about it ..

Thanks eelixduppy You were the first ;)