I'm currently using the following insert query to update values in mysql using php:
$UpdateQuery = "UPDATE `mysqldb`.`cu_data` SET
`app_status` = '".$_POST['Est']."',
`nacionalidad` = '".$_POST['Nac']."',
`ciudad_ini` = '".$_POST['CiudadI']."',
`ciudad_ent` = '".$_POST['CiudadE']."',
`ciudad_dest` = '".$_POST['CiudadD']."',
`ciudad_land` = '".$_POST['PEntrada']."',
`uso_consr` = '".$_POST['U_Abog']."',
`start` = '".$_POST['Envi']."',
`t1` = '".$_POST['Cob']."',
`t2` = '".$_POST['Acus']."',
`t3` = '".$_POST['Invit']."',
`t4` = '".$_POST['Entre']."',
`t5` = '".$_POST['Recibo']."',
`t6` = '".$_POST['EnvioF)']."',
`t7` = '".$_POST['DatInternet']."',
`t8` = '".$_POST['SoliMed']."',
`t9` = '".$_POST['OrdeMe']."',
`t10` = '".$_POST['SoliciPasa']."',
`t11` = '".$_POST['EnvioPasas']."',
`t12` = '".$_POST['RecepPasa']."',
`end` = '".$_POST['Landing']."',
`Notas` = '".$_POST['Notas']."',
`LastChange` = NOW()
WHERE `cu_data`.`procid` = '".$_POST['Proceso']."' AND
`cu_data`.`userid` = '$userid'
";
$result = mysqli_query($con, $UpdateQuery);
The code is working, but now I'm worried about sql inyections (not only the bad kind, but also things like the user including a semi-colon in any of the form fields)
I was thinking using some kind of escaping using mysql_real_escape_string (as suggested in the sencond most voted answer to this question), but then I see some pitfalls in the comments (and I'm having a hard time understanding the most voted one).
any tips?
thanks in advance
Ps: At least for the last field (notas) I need the user to enter any symbols such as ($ # % ; : ,.>
Edited:
I did look at the suggested answer (sorry I had a bad like to another SO answer in the original question). So, as not to be duplicate, could I ask for a clue on on how to do the PDO thing to a update query like the one I'm showing above? (My php is from the mysql_ days!)
Edited (2): Ok, so this question has been flagged as duplicate, yet I don't agree with the selected answer (the one that shows after This question already has an answer here: as that's the one I read before asking this question. I did found another one that looks more interesting (at least to me) here: Replacing mysql_* functions with PDO and prepared statements (of course this one starts to make sense once one is aware of PHP Data Objects, aka PDO, which I wasn't
Edited (3): Well I got this to work as follow:
$UpdateQuery1 = "UPDATE `mysqldb`.`cu_data` SET
`app_status` = ?,
`nacionalidad` = ?,
`ciudad_ini` = ?,
`ciudad_ent` = ?,
`ciudad_dest` = ?,
`ciudad_land` = ?,
`uso_consr` = ?,
`start` = ?,
`t1` = ?,
`t2` = ?,
`t3` = ?,
`t4` = ?,
`t5` = ?,
`t6` = ?,
`t7` = ?,
`t8` = ?,
`t9` = ?,
`t10` = ?,
`t11` = ?,
`t12` = ?,
`end` = ?,
`Notas` = ?,
`LastChange` = NOW()
WHERE `cu_data`.`procid` = ? AND
`cu_data`.`userid` = ?";
$stmt = $con->prepare($UpdateQuery1);
$stmt->bind_param('ssssssssssssssssssssssss',
$_POST['Estatus'],$_POST['Nacionalidad'],$_POST['CiudadI'],$_POST['CiudadE'],$_POST['CiudadD'],
$_POST['PEntrada'],$_POST['Uso_Abog'],$_POST['Envi'],$_POST['Cobro_de_Fee'],
$_POST['Acus'],$_POST['Invit'],$_POST['Entre'],$_POST['Recibo'],$_POST['EnvioF'],
$_POST['DatInternet'],$_POST['SoliMed'],$_POST['OrdeMe'],$_POST['SoliciPasa'],
$_POST['EnvioPasa'],$_POST['RecepPasa'],$_POST['Landing'],$_POST['Notas'],
$_POST['Proceso'],$userid);
$stmt->execute();
As a bonus, my field Notas seems to be able to hold any text, without having to escape special character