coiso
coiso

Reputation: 7479

mysql query difficulty with type

This makes no sense! The update query only actually updates if the value is an INT (yes it is defined as text). The INSERT which has the same variables works with type of value!

mysql_query("UPDATE  `atuam_mae`.`missoes` SET  `mensagemdeuser` =  $message WHERE  `missoes`.`id` =$idmissao;");
mysql_query("INSERT INTO  `atuam_mae`.`concelhos` (`id` ,`tempo` ,`userid` ,`concelho`) VALUES (NULL , CURRENT_TIMESTAMP , $user ,  '$message');");

Upvotes: 0

Views: 37

Answers (2)

knittl
knittl

Reputation: 265171

That is because you are not enclosing your input variable in quotes:

"UPDATE  `atuam_mae`.`missoes`
 SET  `mensagemdeuser` =  '$message'
 WHERE  `missoes`.`id` = '$idmissao';"

NB. Don't do this and use prepared statements instead!

$stmt = $db->prepare('UPDATE  `atuam_mae`.`missoes`
     SET  `mensagemdeuser` = :message
     WHERE  `missoes`.`id` = :id');
$stmt->execute(array(':message' => $message, ':id' => $idmissao));

Upvotes: 3

danicotra
danicotra

Reputation: 1433

I am not sure I understand what you meant but try putting values (right of the =) between single quotes this way:

mysql_query("UPDATE  `atuam_mae`.`missoes` SET  `mensagemdeuser` =  '$message' WHERE  `missoes`.`id` ='$idmissao';");

Upvotes: 0

Related Questions