0
I have a small problem where if in the form I type only a quote ' it does not add in the database. Could someone tell me why and how I could solve this?
OBS¹: only with a quote, if I close it with another quote or put another type of symbol sends.
OBS²: no error appears, it performs the procedure of send but does not insert into database.
<?php
require_once("../config.php");
$nome = $_POST['nome'];
$tipo = $_POST['tipo'];
$data = $_POST['data'];
/*Inserar na tabela */
$query_evento = "INSERT INTO evento (nome, tipo, data) VALUES ('".$nome."', '".$tipo."', '".$data."')";
$inserir_evento = mysql_query($query_evento);
?>
Related: https://answall.com/q/579/57801
– Don't Panic
In case the name has single quotes?
– Don't Panic
Like this let’s say that in the name I type animal’s it does not send to the bank because it has a ' but if I type Animals it sends. So in case I have to use the right mysqli or Pdo?
– kaiquemix
But this is simple to solve:
$nome = str_replace("'","''",$_POST['nome']);
– Don't Panic
Yes I understood, I will be taking the test and reading the article you sent me friend. Thank you very much
– kaiquemix
@kaiquemix what you have to do is use
prepared statments
or use the functionaddslashes
.– Roberto de Campos
@Robertodecampos I will be disallowing your reply and I will search on thank you
– kaiquemix