If you want to get a sense of the error, just do something like:
$qry = "INSERT INTO trabalhe (id, nome, email, cpf, telefone, cidade,
interesse, mensagem, nome_arquivo, arquivo, tipo) VALUES (0, '$interessado','$email','$cpf','$telefone','$cidade','$interesse','$mensagem','$nome','$conteudo','$tipo')";
mysql_query($qry) or die( mysql_error() );
It will probably return some syntax error or will state that the id is zero 0
is wrong, yes the id can not be zero, alliis if id
for AUTOINCREMENT
this field should be omitted, so:
$qry = "INSERT INTO trabalhe (nome, email, cpf, telefone, cidade,
interesse, mensagem, nome_arquivo, arquivo, tipo) VALUES ('$interessado','$email','$cpf','$telefone','$cidade','$interesse','$mensagem','$nome','$conteudo','$tipo')";
Another important thing to say, the addslashes
is not used to escape in mysql, its purpose is another, Allels none of its variables has escaped:
$interessado = $_POST["nome"];
$email = $_POST["email"];
$cpf = $_POST["cpf"];
$telefone = $_POST["telefone"];
$cidade = $_POST["cidade"];
$interesse = $_POST["interesse"];
$mensagem = $_POST["msg"];
Any character in this can cause the syntax error in mysql INSERT.
I highly recommend updating your scripts to MYSQLI, ie the bank is still mysql, but the access API is now MYSQLI or PDO, you choose, I believe mysqli will be easier and familiar.
Then following the examples of doc: http://php.net/manual/en/mysqli.affected-rows.php
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
if (!$link) {
printf("Can't connect to localhost. Error: %s\n", mysqli_connect_error());
exit;
}
//Escapa as variaveis conforme as configurações de conexão
$interessado = mysqli_real_escape_string($link, $_POST["nome"]);
$email = mysqli_real_escape_string($link, $_POST["email"]);
$cpf = mysqli_real_escape_string($link, $_POST["cpf"]);
$telefone = mysqli_real_escape_string($link, $_POST["telefone"]);
$cidade = mysqli_real_escape_string($link, $_POST["cidade"]);
$interesse = mysqli_real_escape_string($link, $_POST["interesse"]);
$mensagem = mysqli_real_escape_string($link, $_POST["msg"]);
//Se o arquivo estiver ok o erro é igual a constante UPLOAD_ERR_OK
if ($_FILES['userfile']['error'] == UPLOAD_ERR_OK) {
$arquivo = $_FILES["arquivo"]["tmp_name"];
$tamanho = $_FILES["arquivo"]["size"];
$tipo = $_FILES["arquivo"]["type"];
$nome = $_FILES["arquivo"]["name"];
$fp = fopen($arquivo, "rb");
$conteudo = fread($fp, $tamanho);
$conteudo = mysqli_real_escape_string($link, $conteudo);
fclose($fp);
$qry = "INSERT INTO trabalhe (nome, email, cpf, telefone, cidade,
interesse, mensagem, nome_arquivo, arquivo, tipo) VALUES ('$interessado','$email','$cpf','$telefone','$cidade','$interesse','$mensagem','$nome','$conteudo','$tipo')";
//Se funcionar informa quantas linhas foram inseridas (vai retornar "1" sempre/provavelmente)
if (mysqli_query($link, "CREATE TABLE Language SELECT * from CountryLanguage")) {
echo 'linhas atualizadas: ', mysqli_affected_rows($link));
} else {
//Se falhar informa o erro
echo 'Erro:', mysqli_error($link)
}
} else {
echo 'Erro no upload';
}
Of course I really do not recommend saving the data of an image directly in the database, it would be better to save on disk and put the image path in the database.
I believe this question answers why I do not find a good way to record directly in the bank:
I’m not saying it’s totally wrong, only in most cases it’s not a good way.
If your intention is to block external access to documents you can limit access to folder by using a .htaccess
allowing only one php to get the content or if the goal is only to block google and index Bing would just use robots.txt
:
Disallow: /imagens/*
This doesn’t seem to have to do with database, are you inserting a pdf into the database? In blob is it? Can’t understand, put your code
– Anderson Henrique
UPLOAD_ERR_OK
Value: 0; no error, upload was successful.– Woss
@Andersonhenrique I really want to record in blob and it returns me this error
– Betinho Silva
@Andersoncarloswoss it returns me the error and does not write the file in blob
– Betinho Silva
Use the function
mysql_error
to display some error that helps you in development - leave these messages friendly of "could not do ..." for the production environment. Moreover, there is a mandatory reading for you: Why should we not use mysql type functions_*?– Woss
I deleted the previous comment, because I think it would lead to some confusion about the technical use, however I still recommend not to upload the data directly in the database. I will formulate a response.
– Guilherme Nascimento
Dear @betinhosilva I edited the answer https://answall.com/a/322295/3635 - I had more to say, but I think I would go way beyond asking.
– Guilherme Nascimento