Multiple insersion dans une base mysql dpuis php
Hors ligneTopvision Le 17/08/2014 à 15:09 Profil de Topvision Configuration de Topvision

bonjour; 

je voudrai lorsque je sélectionne une classe et une matière qu'il le recherche dans la base de donne la liste des élèves de cette classe et vérifie selon la matière s'il a déjà present dans la table note si oui qu'il puisse le mettre a jour sinon d’insérer


if(isset($_GET['ok'])  isset($_GET['id']) AND $_isset(GET['matiere']) )

            {

$sql= mysql_query( "SELECT * FROM note WHERE idelevenote ='".$_GET['id']."' AND  matiere ='".$_GET['matiere'])."'  ");
if(mysql_num_rows($sql)==0)
                    {

$sql="INSERT INTO note VALUE( idelevenote='".$_GET['id_note']."' , matiere='".$_GET['id_matiere']."', note1='".$_GET['note1']."', note2='".$_GET['note2']."', note3='".$_GET['note3']."', compo1='".$_GET['compo1']."', ");
                     }
    else
                    {

$sql2="UPDATE note SET
note1='".$_GET['note1']."', note2='".$_GET['note2']."', note3='".$_GET['note3']."', compo1='".$_GET['compo1']."',
WHERE idnoteleve='".$_GET['id_idelevenote']."' AND matiere='".$_GET['matiere']."' ";

if($result=mysql_query($sql))
{
echo "<script type=\"text/javascript\">
alert('note modifiee')</script>";
header('location:note.php');
}
else
{
echo "<script type=\"text/javascript\">
alert('erreur verrifier vos parametre')</script>";

        }


BASE DE DONNEES

-- phpMyAdmin SQL Dump
-- version 4.1.4
-- http://www.phpmyadmin.net
--
-- Client : 127.0.0.1
-- Généré le : Dim 17 Août 2014 à 15:06
-- 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 : `scool`
--

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

--
-- Structure de la table `classe`
--

CREATE TABLE `classe` (
`classe` varchar(20) NOT NULL,
PRIMARY KEY (`classe`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Contenu de la table `classe`
--

INSERT INTO `classe` (`classe`) VALUES
('3ieme'),
('4ieme'),
('5iem'),
('6iem');

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

--
-- Structure de la table `eleves`
--

CREATE TABLE `eleves` (
`ideleve` int(11) NOT NULL AUTO_INCREMENT,
`nomEl` varchar(15) NOT NULL,
`prenomEl` varchar(25) NOT NULL,
`classeEl` varchar(20) NOT NULL,
`serieEl` varchar(5) NOT NULL,
`sessionEl` varchar(9) NOT NULL,
PRIMARY KEY (`ideleve`),
KEY `classeEl` (`classeEl`,`serieEl`,`sessionEl`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;

--
-- Contenu de la table `eleves`
--

INSERT INTO `eleves` (`ideleve`, `nomEl`, `prenomEl`, `classeEl`, `serieEl`, `sessionEl`) VALUES
(1, 'SALL', 'Elimane', '3ieme', 'L1', '2012/2013'),
(2, 'FALL', 'Fatou', '3ieme', 'L1', '2012/2013'),
(3, 'Diame', 'Ousmane', '4ieme', 'L2', '2012/2013'),
(4, 'Tall', 'Lamine', '4ieme', 'L2', '2012/2013'),
(5, 'Ball', 'Mamdou', '5iem', 'S1', '2012/2013'),
(6, 'Ndour', 'Amadou', '6iem', 'S1', '2012/2013');

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

--
-- Structure de la table `matiere`
--

CREATE TABLE `matiere` (
`matiere` varchar(25) NOT NULL,
PRIMARY KEY (`matiere`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Contenu de la table `matiere`
--

INSERT INTO `matiere` (`matiere`) VALUES
('Anglais'),
('Français'),
('Mathematique'),
('Philo');

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

--
-- Structure de la table `note`
--

CREATE TABLE `note` (
`idnote` int(11) NOT NULL AUTO_INCREMENT,
`idelevenote` int(11) NOT NULL,
`matierenote` varchar(25) NOT NULL,
`note1` float NOT NULL,
`note2` float NOT NULL,
`note3` float NOT NULL,
`compo1` float NOT NULL,
PRIMARY KEY (`idnote`),
KEY `idelevenote` (`idelevenote`,`matierenote`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=16 ;

--
-- Contenu de la table `note`
--

INSERT INTO `note` (`idnote`, `idelevenote`, `matierenote`, `note1`, `note2`, `note3`, `compo1`) VALUES
(1, 1, 'Anglais', 11, 13, 10, 12),
(2, 1, 'Français', 9, 11, 9, 9),
(3, 1, 'Mathematique', 12, 0, 12, 0),
(4, 1, 'Philo', 0, 15, 0, 18),
(5, 2, 'Anglais', 11, 12, 13, 12),
(6, 2, 'Français', 0, 0, 12, 12),
(7, 2, 'Mathematique', 12, 2, 12, 12),
(8, 2, 'Philo', 15, 14, 15, 14),
(9, 3, 'Anglais', 11, 0, 13, 14),
(10, 3, 'Français', 12, 14, 0, 14),
(11, 3, 'Mathematique', 0, 14, 12, 13),
(12, 3, 'Philo', 14, 0, 14, 12),
(13, 4, 'Anglais', 16, 15, 12, 11),
(14, 4, 'Français', 14, 0, 13, 0),
(15, 4, 'Mathematique', 7, 6, 0, 0);

/*!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 */;


Vous avez résolu votre problème avec VIC ? Faites-le savoir sur les réseaux sociaux !
Vulgarisation-informatique.com
Cours en informatique & tutoriels