LaDissertation.com - Dissertations, fiches de lectures, exemples du BAC
Recherche

TD Informatique de connection et tableau tri client/forfait PHP

TD : TD Informatique de connection et tableau tri client/forfait PHP. Recherche parmi 300 000+ dissertations

Par   •  9 Mai 2022  •  TD  •  1 563 Mots (7 Pages)  •  410 Vues

Page 1 sur 7

<?php

include("../connexion.php");

$req="SELECT * FROM cat";

$resultat=$connexion->query($req);

$res=$resultat->fetchAll(PDO::FETCH_ASSOC);

if(isset($_POST['designation']) && !empty($_POST['designation']) && isset($_POST['description']) && !empty($_POST['description']) && isset($_POST['categorie']) && !empty($_POST['categorie']) && isset($_POST['prix']) && !empty($_POST['prix']) && isset($_POST['tva']) && !empty($_POST['tva']) && isset($_FILES['image']) && !empty($_FILES['image']))

{

$cat=$_POST['categorie'];

$designation=$_POST['designation'];

$prix=$_POST['prix'];

$tva=$_POST['tva'];

$description=$_POST['description'];

$nomAvatar=$_FILES['image']['name'];

$upload="images/magasin/".$nomAvatar;

move_uploaded_file($_FILES['image']['tmp_name'],"../".$upload);

$present=false;

$req1="SELECT * FROM article";

$resultat1=$connexion->query($req1);

$res1=$resultat1->fetchAll(PDO::FETCH_ASSOC);

foreach($res1 as $k => $v){

if($description==$v['description'])

$present=true;

}

if(!$present){

$insertion="INSERT INTO article (id_categorie, Designation, Prix, tva, description, img_article) VALUES ('$cat','$designation','$prix','$tva','$description','$upload')";

$insert=$connexion->exec($insertion);

if($insert>0)

echo "<script>alert('Insertion reussit')</script>";

else

echo "<script>alert('Insertion echouée')</script>";

}

}

?>

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<title>Admin</title>

<meta name="description" content="An interactive getting started guide for Brackets.">

<link rel="stylesheet" href="styleadmin.css">

</head>

<body>

<div id="container">

<h1> Administration du site OpenShop</h1>

<h2>Ajout d'un article</h2>

<form method="post" action="index.php" enctype="multipart/form-data">

<fieldset>

<legend>Ajout d'un article</legend>

<p><label for="designation">Designation</label>

<input type="text" name="designation" id="designation"/></p>

<p><label for="description">Description</label>

<input type="text" name="description" id="description"/></p>

<p><label>Catégorie</label>

<select name="categorie">

<?php

foreach($res as $k=>$v){

echo "<option value=".$v['id_categorie'].">".$v['Nom']."</option>";

}

?>

</select></p>

<p><label for="prix">Prix</label>

<input type="text" name="prix" id="prix"/></p>

...

Télécharger au format  txt (8.5 Kb)   pdf (52.6 Kb)   docx (12.1 Kb)  
Voir 6 pages de plus »
Uniquement disponible sur LaDissertation.com