Ajoutez une variable de plus a mon code php
Résolu
dadou9101
Messages postés
107
Date d'inscription
Statut
Membre
Dernière intervention
-
Mimiste Messages postés 1149 Date d'inscription Statut Membre Dernière intervention -
Mimiste Messages postés 1149 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
j'aimerais mettre une variable qui sera id_mag mais je n'arrive pas a la mettre pouvez vous me dire ou ya une ereur sur mon code merci
j aimerais utilise cette variable pour la page suivante apeller PROCEDURE.PHP
je voudrais utiliser la variable id_mag pour pouvoir afficher mes nom techniciens
la premiere page apele home.php permet de choisir un magasin a ki on a attribuer un technicien kan je clik sur afficher je voudrais voir afficher le nom du technicien qui s'occupe du magasin
premiere page "home.php"
<?php
include('connexion.php');
echo '<p>Choisissez un Magasin:</p>';
echo"<form action='procedure.php' action=",$_SERVER['PHP_SELF']," method='POST'>";
echo '<select name="nom_mag" id="nom_mag">';
$resultat=mysql_query("SELECT nom_mag, id_mag FROM magasin") or die ("Requête non executée.");
while ($ligne=mysql_fetch_array($resultat))
{
echo '<option>'.$ligne["nom_mag"].'</option>';
}
echo '</select>';
echo '<input type="submit" value="Afficher" name="go">';
echo '</form>';
?>
Seconde page quand on clik sur AFFICHER apele 'procedure.php'
<?php
$id_mag = $_POST["id_mag"];
include('connexion.php');
$resultat=mysql_query("SELECT nom_tec, prenom_tec FROM technicien, magasin WHERE technicien_id_tec = id_tec
AND id_mag = $id_mag") or die ("Requête non executée.");
while ($ligne=mysql_fetch_array($resultat))
//echo '<div align="center"><strong>'.$ligne[0].' '.$ligne[1].'</strong></div>';
echo '<div align="center"><strong>'.$id_mag.' '.$ligne[1].'</strong></div>';
?>
sa me met erreur ligne 22 a savoir $id_mag = $_POST["id_mag"];
Notice: Undefined index: id_mag in C:\Program Files\EasyPHP 2.0b1\www\CheckList\page\procedure.php on line 22
Requête non executée.
j'aimerais mettre une variable qui sera id_mag mais je n'arrive pas a la mettre pouvez vous me dire ou ya une ereur sur mon code merci
j aimerais utilise cette variable pour la page suivante apeller PROCEDURE.PHP
je voudrais utiliser la variable id_mag pour pouvoir afficher mes nom techniciens
la premiere page apele home.php permet de choisir un magasin a ki on a attribuer un technicien kan je clik sur afficher je voudrais voir afficher le nom du technicien qui s'occupe du magasin
premiere page "home.php"
<?php
include('connexion.php');
echo '<p>Choisissez un Magasin:</p>';
echo"<form action='procedure.php' action=",$_SERVER['PHP_SELF']," method='POST'>";
echo '<select name="nom_mag" id="nom_mag">';
$resultat=mysql_query("SELECT nom_mag, id_mag FROM magasin") or die ("Requête non executée.");
while ($ligne=mysql_fetch_array($resultat))
{
echo '<option>'.$ligne["nom_mag"].'</option>';
}
echo '</select>';
echo '<input type="submit" value="Afficher" name="go">';
echo '</form>';
?>
Seconde page quand on clik sur AFFICHER apele 'procedure.php'
<?php
$id_mag = $_POST["id_mag"];
include('connexion.php');
$resultat=mysql_query("SELECT nom_tec, prenom_tec FROM technicien, magasin WHERE technicien_id_tec = id_tec
AND id_mag = $id_mag") or die ("Requête non executée.");
while ($ligne=mysql_fetch_array($resultat))
//echo '<div align="center"><strong>'.$ligne[0].' '.$ligne[1].'</strong></div>';
echo '<div align="center"><strong>'.$id_mag.' '.$ligne[1].'</strong></div>';
?>
sa me met erreur ligne 22 a savoir $id_mag = $_POST["id_mag"];
Notice: Undefined index: id_mag in C:\Program Files\EasyPHP 2.0b1\www\CheckList\page\procedure.php on line 22
Requête non executée.
A voir également:
- Ajoutez une variable de plus a mon code php
- Code ascii - Guide
- Comment déverrouiller un téléphone quand on a oublié le code - Guide
- Code puk bloqué - Guide
- Code activation windows 10 - Guide
- Code blocks - Télécharger - Langages
12 réponses
Bonjour
dans ton formulaire tu appelle cette variable "nom_mag" (attribut name)
<select name="nom_mag" id="nom_mag">';
dans ton php tu essai d'appeller la variable id_mag
$id_mag = $_POST["id_mag"];
D'ou l'erreur "undefined index"
ensuite pour recuperer l'id il faut a chaque fois que tu ajoute une option, lui ajouter une valeur
echo '<option value="'.$ligne["id_mag"].'">'.$ligne["nom_mag"].'</option>';
dans ton formulaire tu appelle cette variable "nom_mag" (attribut name)
<select name="nom_mag" id="nom_mag">';
dans ton php tu essai d'appeller la variable id_mag
$id_mag = $_POST["id_mag"];
D'ou l'erreur "undefined index"
ensuite pour recuperer l'id il faut a chaque fois que tu ajoute une option, lui ajouter une valeur
echo '<option value="'.$ligne["id_mag"].'">'.$ligne["nom_mag"].'</option>';
oui mais la variable nom_mag je lutilise elle aussi :) c pour sa
y a til moyen de rajouter une variable en plus en faite
y a til moyen de rajouter une variable en plus en faite
Oui mais la ton nom_mag tu ne l'utilise a aucun moment o_O
pourquoi tu fais pas $id_mag = $_POST["nom_mag"]; ?
pourquoi tu fais pas $id_mag = $_POST["nom_mag"]; ?
en faite jai pas marquer la suite de mon code sur ma page procedure.php il y a aussi nom_mag regarde
<?php
// if($_POST["nom_mag"] != "") pas besoin de faire cette vérification
$nom_mag = $_POST["nom_mag"];
include('connexion.php');
echo '<div align="center"><strong>'.$nom_mag.'</strong></div>';
?>
</td>
<td width="50%">
<?php
$id_mag = $_POST["id_mag"];
include('connexion.php');
$resultat=mysql_query("SELECT nom_tec, prenom_tec FROM technicien, magasin WHERE technicien_id_tec = id_tec
AND id_mag = $id_mag") or die ("Requête non executée.");
while ($ligne=mysql_fetch_array($resultat))
//echo '<div align="center"><strong>'.$ligne[0].' '.$ligne[1].'</strong></div>';
echo '<div align="center"><strong>'.$id_mag.' '.$ligne[1].'</strong></div>';
?>
<?php
// if($_POST["nom_mag"] != "") pas besoin de faire cette vérification
$nom_mag = $_POST["nom_mag"];
include('connexion.php');
echo '<div align="center"><strong>'.$nom_mag.'</strong></div>';
?>
</td>
<td width="50%">
<?php
$id_mag = $_POST["id_mag"];
include('connexion.php');
$resultat=mysql_query("SELECT nom_tec, prenom_tec FROM technicien, magasin WHERE technicien_id_tec = id_tec
AND id_mag = $id_mag") or die ("Requête non executée.");
while ($ligne=mysql_fetch_array($resultat))
//echo '<div align="center"><strong>'.$ligne[0].' '.$ligne[1].'</strong></div>';
echo '<div align="center"><strong>'.$id_mag.' '.$ligne[1].'</strong></div>';
?>
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
oui je vois mais le problème c que tu ne peu pas récupérer ton nom_mag comme ça dans ton sélect
il faut que tu récupère l'id comme je t'ai dis au dessus et qu avec une requête tu aille chercher le nom_mag dans ta bdd
il faut que tu récupère l'id comme je t'ai dis au dessus et qu avec une requête tu aille chercher le nom_mag dans ta bdd
oui je vois mais le problème c que tu ne peu pas récupérer ton nom_mag comme ça dans ton sélect
il faut que tu récupère l'id comme je t'ai dis au dessus et qu avec une requête tu aille chercher le nom_mag dans ta bdd
il faut que tu récupère l'id comme je t'ai dis au dessus et qu avec une requête tu aille chercher le nom_mag dans ta bdd
oki jai compris se ke tu voulais dire donc je met sa
<?php
// if($_POST["nom_mag"] != "") pas besoin de faire cette vérification
$nom_mag = $_POST["nom_mag"];
include('connexion.php');
echo '<div align="center"><strong>'.$nom_mag.'</strong></div>';
?>
</td>
<td width="50%">
<?php
$id_mag = $_POST["nom_mag"];
include('connexion.php');
$resultat=mysql_query("SELECT nom_tec, prenom_tec FROM technicien, magasin WHERE technicien_id_tec = id_tec
AND id_mag = $nom_mag") or die ("Requête non executée.");
while ($ligne=mysql_fetch_array($resultat))
//echo '<div align="center"><strong>'.$ligne[0].' '.$ligne[1].'</strong></div>';
echo '<div align="center"><strong>'.$id_mag.' '.$ligne[1].'</strong></div>';
?>
le souci c'est que sa me met requete non execute mtn
<?php
// if($_POST["nom_mag"] != "") pas besoin de faire cette vérification
$nom_mag = $_POST["nom_mag"];
include('connexion.php');
echo '<div align="center"><strong>'.$nom_mag.'</strong></div>';
?>
</td>
<td width="50%">
<?php
$id_mag = $_POST["nom_mag"];
include('connexion.php');
$resultat=mysql_query("SELECT nom_tec, prenom_tec FROM technicien, magasin WHERE technicien_id_tec = id_tec
AND id_mag = $nom_mag") or die ("Requête non executée.");
while ($ligne=mysql_fetch_array($resultat))
//echo '<div align="center"><strong>'.$ligne[0].' '.$ligne[1].'</strong></div>';
echo '<div align="center"><strong>'.$id_mag.' '.$ligne[1].'</strong></div>';
?>
le souci c'est que sa me met requete non execute mtn
met
or die(mysql_error());
pour avoir l'erreur SQL, tu a bien refais le select comme je t'ai dis ? avec l'attribu value car c'est ça qui est envoyé en POST
echo '<option value="'.$ligne["id_mag"].'">'.$ligne["nom_mag"].'</option>';
or die(mysql_error());
pour avoir l'erreur SQL, tu a bien refais le select comme je t'ai dis ? avec l'attribu value car c'est ça qui est envoyé en POST
echo '<option value="'.$ligne["id_mag"].'">'.$ligne["nom_mag"].'</option>';
Ma page home.php jai mis sa
<?php
include('connexion.php');
echo '<p>Choisissez un Magasin:</p>';
echo"<form action='procedure.php' action=",$_SERVER['PHP_SELF']," method='POST'>";
echo '<select name="nom_mag" id="nom_mag">';
$resultat=mysql_query("SELECT nom_mag, id_mag FROM magasin") or die ("Requête non executée.");
while ($ligne=mysql_fetch_array($resultat))
{
echo '<option>'.$ligne["nom_mag"].'</option>';
}
echo '</select>';
echo '<input type="submit" value="Afficher" name="go">';
echo '</form>';
?>
Ma page procedure.php
<?php
$id_mag = $_POST["nom_mag"];
include('connexion.php');
$resultat=mysql_query("SELECT nom_tec, prenom_tec FROM technicien, magasin WHERE technicien_id_tec = id_tec
AND id_mag = $nom_mag") or die (mysql_error));
while ($ligne=mysql_fetch_array($resultat))
//echo '<div align="center"><strong>'.$ligne[0].' '.$ligne[1].'</strong></div>';
echo '<option value="'.$ligne["id_mag"].'">'.$ligne["nom_mag"].'</option>';
?>
<?php
include('connexion.php');
echo '<p>Choisissez un Magasin:</p>';
echo"<form action='procedure.php' action=",$_SERVER['PHP_SELF']," method='POST'>";
echo '<select name="nom_mag" id="nom_mag">';
$resultat=mysql_query("SELECT nom_mag, id_mag FROM magasin") or die ("Requête non executée.");
while ($ligne=mysql_fetch_array($resultat))
{
echo '<option>'.$ligne["nom_mag"].'</option>';
}
echo '</select>';
echo '<input type="submit" value="Afficher" name="go">';
echo '</form>';
?>
Ma page procedure.php
<?php
$id_mag = $_POST["nom_mag"];
include('connexion.php');
$resultat=mysql_query("SELECT nom_tec, prenom_tec FROM technicien, magasin WHERE technicien_id_tec = id_tec
AND id_mag = $nom_mag") or die (mysql_error));
while ($ligne=mysql_fetch_array($resultat))
//echo '<div align="center"><strong>'.$ligne[0].' '.$ligne[1].'</strong></div>';
echo '<option value="'.$ligne["id_mag"].'">'.$ligne["nom_mag"].'</option>';
?>
<?php
include('connexion.php');
echo '<p>Choisissez un Magasin:</p>';
echo"<form action='procedure.php' action=",$_SERVER['PHP_SELF']," method='POST'>";
echo '<select name="nom_mag" id="nom_mag">';
$resultat=mysql_query("SELECT nom_mag, id_mag FROM magasin") or die ("Requête non executée.");
while ($ligne=mysql_fetch_array($resultat))
{
echo '<option value="'.$ligne["id_mag"].'" >'.$ligne["nom_mag"].'</option>';
}
echo '</select>';
echo '<input type="submit" value="Afficher" name="go">';
echo '</form>';
?>
procedure.php
<?php
$id_mag = $_POST["nom_mag"];
include('connexion.php');
$resultat=mysql_query("SELECT nom_tec, prenom_tec FROM technicien, magasin WHERE technicien_id_tec = id_tec
AND id_mag = $nom_mag") or die (mysql_error());
while ($ligne=mysql_fetch_array($resultat))
{
echo '<div align="center"><strong>'.$ligne[0].' '.$ligne[1].'</strong></div>';
}
?>
include('connexion.php');
echo '<p>Choisissez un Magasin:</p>';
echo"<form action='procedure.php' action=",$_SERVER['PHP_SELF']," method='POST'>";
echo '<select name="nom_mag" id="nom_mag">';
$resultat=mysql_query("SELECT nom_mag, id_mag FROM magasin") or die ("Requête non executée.");
while ($ligne=mysql_fetch_array($resultat))
{
echo '<option value="'.$ligne["id_mag"].'" >'.$ligne["nom_mag"].'</option>';
}
echo '</select>';
echo '<input type="submit" value="Afficher" name="go">';
echo '</form>';
?>
procedure.php
<?php
$id_mag = $_POST["nom_mag"];
include('connexion.php');
$resultat=mysql_query("SELECT nom_tec, prenom_tec FROM technicien, magasin WHERE technicien_id_tec = id_tec
AND id_mag = $nom_mag") or die (mysql_error());
while ($ligne=mysql_fetch_array($resultat))
{
echo '<div align="center"><strong>'.$ligne[0].' '.$ligne[1].'</strong></div>';
}
?>