-1
I am creating a webservice that will have to pick up some. pdf files saved in the database and send to a user x.
To save this file in the bank, I’m trying to do it this way:
<?php
require("conexao.php");
$nome = $_POST['nome'];
$email = $_POST['email'];
$texto = $_POST['texto'];
$arq_complementar = $_FILES['arquivo_complementar'];
$arquivo_complementar = mysqli_real_escape_string($connection, $arq_complementar);
print_r($arquivo_complementar);
$sql = "INSERT INTO cartas(nome, email, texto, arq_complementar) VALUES ('$nome', '$email', '$texto', '$arquivo_complementar')";
$testar_conexao = mysqli_query($connection,$sql);
//header("Location: ".$_SERVER['HTTP_REFERER']."");
?>
But the system returns me the following error: "Warning: mysqli_real_escape_string() expects Parameter 2 to be string, array Given in"
Below is the way I’m calling this registration service
<form action="cadastrarMensagem.php" method="POST" enctype="multipart/form-data">
<fieldset>
<legend>Integração</legend>
<label>Nome:</label> <br>
<input type="text" name="nome"> <br>
<label>Email:</label> <br>
<input type="email" name="email"> <br>
<label>Texto da carta:</label> <br>
<textarea name="texto"></textarea> <br>
<label>Arquivo Complementar:</label>
<input name="arquivo_complementar" type="file"> <br> <br>
<input id="button" type="submit" name="Enviar">
</fieldset>
</form>
I think the message is clear: the function expects a string as the second parameter and you passed an array. You can check that it is an array from the
print_r
which you did. After fixing this it will probably give array to string conversion error when trying to save an array in the database. In short, review what you did in the code and match what you wanted to do.– Woss