0

I have some problems

Notice: Array to string conversion in x\contact_ajouter_verif.php on line 17

This is my form :

<form action="contact_ajouter_verif.php" method="post" name="ajoutContact" enctype="multipart/form-data" >
    <fieldset>
        <label>Nom :</label> <input size="30%" type="text" placeholder="" name="nom" /> 
        <label>Numéro :</label> <input size="30%" type="number" placeholder="" name="num" />
        <label>Image au format png :</label><input type="file" name="img" />
    </fieldset> 
    &nbsp;<input name="submit" type="submit" value="Ajouter"/>
</form>

And this is my pdo receiver page:

<?php
include('../inc/connexion.inc.php');
include('session.php');

$nom = $_POST['nom'];
$num = $_POST['num'];
$img = $_FILES['img'];

$pseudo = $user_check. "_contact";
$rqt1= "INSERT INTO $pseudo(CTC_NOM, CTC_NUMERO, CTC_IMG) VALUES(:nom, :num, :img)";
$result1 =$cnxpdo->prepare($rqt1);
$result1->execute(array(
    'nom' => "$nom",
    'num' => "$num",
    'img' => "$img" //line 17
)); 
?>

I really don't understand what I'm doing wrong, please if someone have the solution :)

7
  • 2
    VALUES($nom failed you. Commented Jan 16, 2017 at 13:09
  • Dont' save files in a database. stackoverflow.com/a/41235395/267540 Commented Jan 16, 2017 at 13:12
  • $nom is not a binding. Commented Jan 16, 2017 at 13:12
  • thx but still this one : Notice: Array to string conversion in x\contact_ajouter_verif.php on line 17 Commented Jan 16, 2017 at 13:14
  • 1
    @Drobulo basically you just have to have an idea what are you doing. Ask yourself, what are you trying to get from $img = $_FILES['img']. Then re-read the manual page on file uploads Commented Jan 16, 2017 at 13:26

1 Answer 1

2

Finally found for those in the same case than me (unlikely but we never know...) :

<?php
include('../inc/connexion.inc.php');
include('session.php');

$nom = $_POST['nom'];
$num = $_POST['num'];
$img =addslashes(file_get_contents ($_FILES['img']['tmp_name']));



$pseudo = $user_check. "_contact";
$rqt1= "INSERT INTO $pseudo(CTC_NOM, CTC_NUMERO, CTC_IMG) VALUES(:nom, :num, :img)";
$result1 =$cnxpdo->prepare($rqt1);
$result1->execute(array(
    'nom' => "$nom",
    'num' => "$num",
    'img' => "$img"
));

?>

Thanx for your help.

Sign up to request clarification or add additional context in comments.

1 Comment

You don't need to use addslashes() there, and also replace "$nom" and similar to just: $nom

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.