I'm having a problem with my hosting add form.
Indeed I have a form of addition of hergement.
I encountered some problem adding an image in the database and in a file but now it works. To make it work I "isolated" adding image to the database by creating another file telling me that once it will work I will just add it to the form and everything will work as expected. Except that when I add it to my final form (complete, with all the fields) it puts me that the new lenames that I insert are undefined with that in the other file or I just added the image in the database works .... can you take a look at this problem please?
Thank you
My code "isolated"
<?php
$bdd = new PDO('mysql:host=127.0.0.1;dbname=resa', 'root', '');
if(isset($_POST['formAjoutHebergement']))
{
$target = "imgheb/images/".basename($_FILES['imageheb']['name']);
$temp = explode (".", $_FILES["imageheb"]["name"]);
$nomimg = $_FILES['imageheb']['name'];
if(move_uploaded_file($_FILES["imageheb"]["tmp_name"],$target)){
$valide = 'Ok';
/*$insertimg = "INSERT INTO hebergement(IMAGEHEB) VALUES('$nomimg')";*/
$sql = $bdd->prepare("INSERT INTO `hebergement` (`IMAGEHEB`) VALUES (?)");
$sql->execute(array($nomimg));
}
else
{
$erreur = "Probleme upload image";
}
}
?>
My complete code telling me that lines 80, 82, 84 and 87 are Undefined index ... I do not understand:
<?php
$bdd = new PDO('mysql:host=127.0.0.1;dbname=resa', 'root', '');
if(isset($_POST['formAjoutHebergement']))
{
$codetypeheb = htmlspecialchars($_POST['codetypeheb']);
$nomheb = htmlspecialchars($_POST['nomheb']);
$nbplaceheb = htmlspecialchars($_POST['nbplaceheb']);
$surfaceheb = htmlspecialchars($_POST['surfaceheb']);
$internet = htmlspecialchars($_POST['internet']);
$anneeheb = htmlspecialchars($_POST['anneeheb']);
$secteurheb = htmlspecialchars($_POST['secteurheb']);
$orientationheb = htmlspecialchars($_POST['orientationheb']);
$etatheb = htmlspecialchars($_POST['etatheb']);
$descriheb = htmlspecialchars($_POST['descriheb']);
$tarifsemheb = htmlspecialchars($_POST['tarifsemheb']);
if(!empty($_POST['codetypeheb']) AND !empty($_POST['nomheb']) AND !empty($_POST['nbplaceheb']) AND !empty($_POST['surfaceheb']) AND !empty($_POST['internet']) AND !empty($_POST['anneeheb']) AND !empty($_POST['secteurheb']) AND !empty($_POST['orientationheb']) AND !empty($_POST['etatheb']) AND !empty($_POST['descriheb']) AND !empty($_POST['tarifsemheb']))
{
$codetypeheblenght = strlen($codetypeheb);
$nomheblenght = strlen($nomheb);
$nbplaceheblenght = strlen($nbplaceheb);
$surfaceheblenght = strlen($surfaceheb);
$anneeheblenght = strlen($anneeheb);
$secteurheblenght = strlen($secteurheb);
$orientationheblenght = strlen($orientationheb);
$etatheblenght = strlen($etatheb);
$descriheblenght = strlen($descriheb);
$tarifsemheblenght = strlen($tarifsemheb);
$reqcodetypeheb = $bdd->prepare("SELECT * FROM hebergement WHERE codetypeheb = ?");
$reqcodetypeheb->execute(array($codetypeheb));
$codetypehebexist = $reqcodetypeheb->rowCount();
$reqnomheb = $bdd->prepare("SELECT * FROM hebergement WHERE nomheb = ?");
$reqnomheb->execute(array($nomheb));
$nomhebexist = $reqnomheb->rowCount();
if($codetypehebexist == 0)
{
if($nomhebexist == 0)
{
$target = "imgheb/images/".basename($_FILES['imageheb']['name']);
var_dump($target);
$temp = explode (".", $_FILES["imageheb"]["name"]);
var_dump($temp);
$nomimg = $_FILES['imageheb']['name'];
var_dump($nomimg);
if(move_uploaded_file($_FILES["imageheb"]["tmp_name"],$target)){
$valide = 'Ok';
$sql = $bdd->prepare("INSERT INTO `hebergement` (`IMAGEHEB`) VALUES (?)");
$sql->execute(array($nomimg));
var_dump($sql);
}
else
{
$erreur = "Probleme upload image";
}
$insertheb = $bdd->prepare("INSERT INTO hebergement(codetypeheb, nomheb, nbplaceheb, surfaceheb, internet, anneeheb, secteurheb, orientationheb, etatheb, descriheb, tarifsemheb) VALUES(?,?,?,?,?,?,?,?,?,?,?)");
$insertheb->execute(array($codetypeheb, $nomheb, $nbplaceheb, $surfaceheb, $internet, $anneeheb, $secteurheb, $orientationheb, $etatheb, $descriheb, $tarifsemheb ));
$valide = "Votre hebergement a bien été créé !";
/*header('Location: index1.php');*/
}
else
{
$erreur = "Nom hebergement déjà utilisé !";
}
}
else
{
$erreur = "Code type hebergement déjà utilisé !";
}
}
}
?>