Gestion Stage etudiant

Fermé
kreutz201 Messages postés 11 Date d'inscription mardi 11 juin 2013 Statut Membre Dernière intervention 14 décembre 2020 - Modifié le 7 févr. 2018 à 17:54
jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 - 7 févr. 2018 à 19:05
Bjr, voici un code que j’ai travaillé en php-mysql, dont le nom du fichier est login.php :
<?php include('entete.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>
</head>

<body>
<table width="556" border="0" cellspacing="2" cellpadding="10">
  <tr>
    <td height="300" valign="top" bgcolor="#FFFFCC"><h6>Connexion au système de gestion des stages</h6>
      <form name="form1" method="post" action="connexion.php">
        <p>
          <label>Paramètres de connexion:</label>
        </p>
        <p>
          <label>
          <input name="categorie" type="radio" value="1" checked>Elève</label>
          <br />
          <label>
          <input type="radio" name="categorie" value="2" />Maitre de stage</label>
          <br />
          <label>
          <input type="radio" name="categorie" value="3" />Responsable de site</label>
        </p>  
        <p>ID
          <input type="text" name="login" />
        </p>
        <p>Mot de passe
          <input type="password" name="pwd" />
          <label></label>
        </p>
        <p>
          <input type="submit" name="Submit" value="Aller" />
        </p>
      </form>
      <p> </p></td>
  </tr>
</table>
<?php include('pied.php'); ?>
</body>
</html>

Et voici la base de données GestionStage :
-- phpMyAdmin SQL Dump
-- version 4.1.4
-- [http://www.phpmyadmin.net]
-- Client :  127.0.0.1
-- Généré le :  Dim 21 Janvier 2018 à 12:30
-- Version du serveur :  5.6.15-log
-- Version de PHP :  5.4.24

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Base de données :  `gestionstages`
--

-- --------------------------------------------------------

--
-- Structure de la table `eleve`
--

CREATE TABLE IF NOT EXISTS `eleve` (
  `login` varchar(8) NOT NULL,
  `pw` varchar(30) NOT NULL,
  `nom` varchar(50) NOT NULL,
  `prenom` varchar(50) NOT NULL,
  `classe` enum('5M','6M','4M','3M') NOT NULL,
  PRIMARY KEY (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Contenu de la table `eleve`
--

INSERT INTO `eleve` (`login`, `pw`, `nom`, `prenom`, `classe`) VALUES
('jdu', 'aaaaaa', 'Duval', 'Jacques', '5M'),
('lde', 'cccccc', 'Devreux', 'Ludovic', '6M'),
('lma', 'eeeeee', 'Martin', 'Luc', '6M'),
('mde', 'dddddd', 'Dethy', 'Marc', '4M'),
('ple', 'bbbbbb', 'Lemoine', 'Pierre', '3M');

-- --------------------------------------------------------

--
-- Structure de la table `lieu`
--

CREATE TABLE IF NOT EXISTS `lieu` (
  `login` varchar(8) NOT NULL,
  `pw` varchar(30) NOT NULL,
  `denomination` varchar(50) NOT NULL,
  `nom` varchar(50) NOT NULL,
  `prenom` varchar(50) NOT NULL,
  `adresse` varchar(50) NOT NULL,
  PRIMARY KEY (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Contenu de la table `lieu`
--

INSERT INTO `lieu` (`login`, `pw`, `denomination`, `nom`, `prenom`, `adresse`) VALUES
('jhe', 'c3c3c3', 'Crèche les poussins', 'Herman', 'Josiane', 'avenue des Arts Namur'),
('mre', 'a1a1a1', 'Hopital Saint-Jean', 'Renders', 'Michel', 'rue des Haies Namur'),
('rfa', 'b2b2b2', 'Home Les Magnolias', 'Falise', 'Roger', 'rue du Centre Jambes');

-- --------------------------------------------------------

--
-- Structure de la table `maitre`
--

CREATE TABLE IF NOT EXISTS `maitre` (
  `login` varchar(8) NOT NULL,
  `pw` varchar(30) NOT NULL,
  `nom` varchar(50) NOT NULL,
  `prenom` varchar(50) NOT NULL,
  PRIMARY KEY (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Contenu de la table `maitre`
--

INSERT INTO `maitre` (`login`, `pw`, `nom`, `prenom`) VALUES
('fmi', '333333', 'Miller', 'François'),
('jve', '111111', 'Verbois', 'Jacques'),
('pde', '222222', 'Desmedt', 'Paul'),
('vmo', '444444', 'Morel', 'Vincent');

-- --------------------------------------------------------

--
-- Structure de la table `stage`
--

CREATE TABLE IF NOT EXISTS `stage` (
  `id` tinyint(11) NOT NULL,
  `domaine` varchar(50) NOT NULL,
  `date_debut` date NOT NULL,
  `date_fin` date NOT NULL,
  `note` tinyint(4) unsigned DEFAULT NULL,
  `id_eleve` varchar(8) NOT NULL,
  `id_lieu` varchar(8) NOT NULL,
  `id_maitre` varchar(8) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `id_eleve` (`id_eleve`),
  KEY `id_lieu` (`id_lieu`),
  KEY `id_maitre` (`id_maitre`),
  KEY `id_maitre_2` (`id_maitre`),
  KEY `id_lieu_2` (`id_lieu`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Contenu de la table `stage`
--

INSERT INTO `stage` (`id`, `domaine`, `date_debut`, `date_fin`, `note`, `id_eleve`, `id_lieu`, `id_maitre`) VALUES
(1, 'Crèche', '2005-05-15', '2005-05-30', NULL, 'mde', 'jhe', 'jve'),
(2, 'Pédiatrie', '2005-05-10', '2005-05-28', NULL, 'ple', 'mre', 'fmi'),
(3, 'Gériartrie', '2005-05-12', '2005-06-02', NULL, 'ide', 'rfa', 'fmi'),
(4, 'Gériartrie', '2005-05-15', '2005-06-04', NULL, 'ple', 'rfa', 'fmi'),
(6, 'Pédiatrie', '2005-05-11', '2005-06-04', NULL, 'jdu', 'mre', 'jve'),
(9, 'Crèche', '2005-06-06', '2005-06-13', NULL, 'lde', 'jhe', 'fmi'),
(8, 'Crèche', '2005-06-06', '2005-06-13', NULL, 'jdu', 'jhe', 'jve'),
(10, 'Gériartrie', '2005-05-23', '2005-05-29', NULL, 'jdu', 'rfa', 'jve');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Et voici, la page connexion.php:
 <?php
session_start();
include('entete.php'); ?>
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
<table width="556" border="0" cellspacing="10">
  <tr>
    <td height="300" valign="top" bgcolor="#FFFCC">
<?php
$_SESSION['categorie']=$_POST['categorie'];
$_SESSION['login']=$_POST['login'];
$_SESSION['pw']=$_SESSION['pw'];
echo "<h6>Système de gestion des stages</h6>";
$c=$_POST['categorie'];
if($c==1){$t='eleve';}
elseif($c==2){$t='maitre';}
else{$t='lieu';}
$link = mysql_connect('localhost', 'encodeur', 'aaaaaa');
if (!$link) {
 die('<p>Impossible de se connecter : '. mysql_error().'</p>');
}
$db = mysql_select_db('gestionstages', $link);
if ($db) {
 die ('<p>Impossible d\'utiliser la base : '.mysql_error().'</p>');
}
$login=$_POST['login'];
$sqlquery="select nom,prenom,login,pw from $t where login='$login'";
$queryresult=mysql_query($sqlquery);
if(mysql_num_rows($queryresult)==0){
 echo "<p>Identifiant inconnu!</p>";
 echo "<p><a href='login.php'>Retour</a></p>";}
else{
 $row=mysql_fetch_array($queryresult,MYSQL_ASSOC);
 if($row['pw']!=$_POST['pw']){
  echo "Mot de passe incorrect!";
  echo "<p><a href='login.php'>Retour</a></p>";}
 else{echo "<p>Bienvenue <strong>".$row['prenom']." ".$row['nom']."</strong>"."</p>";
      echo "<p><a href='menu.php?".SID."'>Continuer</a></p>";
   include('deconnexion.php');
 }
}
?>
    </td>
  </tr>
</table>
<?php
include('pied.php'); ?>
    </body>
</html>

lorsque je saisi les coordonnées dans login.php, il affiche le message dans la page connexion.php :
Notice: Undefined index: pw in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\projects\stage\connexion.php on line 22
Système de gestion des stages
Impossible d'utiliser la base :
Svp, aidez-moi à retrouver ce problème



A voir également:

1 réponse

jordane45 Messages postés 38139 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 20 avril 2024 4 649
7 févr. 2018 à 19:05
Bonjour,

1 - Attention, l'extension mysql était obsolète en PHP 5.5.0, et a été supprimée en PHP 7.0.0.
https://www.commentcamarche.net/faq/43261-php-l-extension-mysql-est-obsolete#top

À la place, tu peux (<gras DOIS </gras> ) utiliser l'extension MySQLi ou l'extension PDO_MySQL
https://www.commentcamarche.net/faq/44117-connexion-a-une-base-avec-pdo-mysqli

Si tu choisis PDO, pense à activer la gestion des erreurs : https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs


2 - Concernant ton souci : https://forums.commentcamarche.net/forum/affich-37636387-php-notice-undefined-index


.
0