Php formulaire
- Accueil
- Forum
- Programmation
- PHP
- Php formulaire
shung Le 10 octobre 2021 à 01:20 (Édité le 1 janvier 1970 à 01:00)
Salut prim, j'ai un problème, j'espère que tu peux m'aider, le code du formulaire, chaque fois qu'un membre envoi le formulaire, j'aimerais introduire le $_session[id] du tableaux user (déjà inscrit) pour que je vois qui a envoyé cette formulaire qui vas apparetre dans un autre tableau formulaire
<?php session_start(); $bdd = new PDO('mysql:host=localhost;dbname=basedonnee', 'root', ''); if(!$_SESSION['tex']){ header('Location: text.php'); }
if(isset($_POST['submit'])){ if(!empty($_POST['nom']) AND !empty($_POST['email']) AND !empty($_POST['text1']) AND !empty($_POST['text2']) AND !empty($_POST['text3']) AND !empty($_POST['text4'])){ $nom = htmlspecialchars($_POST['nom']); $email = htmlspecialchars($_POST['email']); $text1 = htmlspecialchars($_POST['text1']); $text2 = htmlspecialchars($_POST['test2']); $text3 = htmlspecialchars($_POST['test3']); $text4 = htmlspecialchars($_POST['test4']);
$insererTransaction = $bdd->prepare('INSERT INTO table1(nom, email, text1, test2, test3, test4) VALUES(?, ?, ?, ?, ?, ?)');
$insererTransaction->execute(array($nom, $email, $text1, $test2, $test3, $test4));
$succes = "lablablablablablabla ";
}else{ $erreur = "lablablablablablabla"; } if(isset($_FILES['file'])){ $tmpName = $_FILES['file']['tmp_name']; $name = $_FILES['file']['name']; $size = $_FILES['file']['size']; $error = $_FILES['file']['error'];
$tabExtension = explode('.', $name);
$extension = strtolower(end($tabExtension));
$extensions = ['jpg', 'png', 'jpeg', 'gif'];
$maxSize = 400000;
if(in_array($extension, $extensions) && $size <= $maxSize && $error == 0){
$uniqueName = uniqid('', true);
$file = $uniqueName.".".$extension;
move_uploaded_file($tmpName, './upload/'.$file);
$req = $bdd->prepare('INSERT INTO table1 (name) VALUES (?)');
$req->execute(array($name));
echo "";
}
else{
echo "";
}
}
} ?>
<!DOCTYPE html> <html lang="pt">
<meta charset="utf-8">
</head>
<section id="container">
<header class="header black-bg">
<!--logo start-->
<a href="index.php" class="logo"><b>text<span>text</span></b></a>
</header>
<?php
if(isset($succes)) {
echo '<font color="blue">'.$succes."</font>";
}
?>
<?php
if(isset($erreur)) {
echo '<font color="red">'.$erreur."</font>";
}
?>
<hr>
<form method="POST" action="" enctype="multipart/form-data">
<div class="top-margin">
<label>nom completo <span class="text-danger">*</span></label>
<input type="text" name="nom" class="form-control">
</div>
<br />
<div class="top-margin">
<label>Email <span class="text-danger">*</span></label>
<input type="email" name="email" class="form-control" value="<?php if(isset($mail)) { echo $mail; } ?>" />
</div>
<br />
<div class="row top-margin">
<div class="col-sm-6">
<label>Endereço da test4<span class="text-danger">*</span></label>
<input type="text" name="text1" class="form-control">
</div>
<div class="col-sm-4">
<label>test2 <span class="text-danger">*</span></label>
<input type="text" name="test2" class="form-control" value="">
</div>
</div>
<br /><br />
<div class="row top-margin">
<div class="col-sm-3">
<label>test3(kzs) <span class="text-danger">*</span></label>
<input type="number" name="test3" class="form-control" value="">
</div>
<div class="col-sm-3">
<label> compravativo <span class="text-danger">*</span> </label>
<input type="file" name="file" />
</div>
</div>
<br /><br />
<div class="row top-margin">
<div class="col-sm-6">
<label>test4 <span class="text-danger">*</span></label>
<select select name="test4" required>
<option selected hidden value=""></option>
<option value="btc">BTC</option>
<option value="bnb">BNB</option>
<option value="trx">TRX</option>
<option value="xlm">XLM</option>
<option value="usdt-tcr20">USDT-TRC20</option>
</select>
</div>
</div>
<br />
<div class="panel-footer">
<input value="Submit" type="submit" name="submit" name="file" class="btn btn-primary pull-right">
</div>
</div>
</form>
</div>
</div>
</div>
</body> </html>