Probleme update sql
stefanelle
-
Alain_42 Messages postés 5413 Statut Membre -
Alain_42 Messages postés 5413 Statut Membre -
Bonjour,
ja i deux fichiers php qui me permettent de mettre a jour ma base selon une selection depuis un menu déroulant je sélectionnes mes labels et j affiche mes références artiste album et format selon label choisi mis j ai un problème avec mon update je modifie une valeur et il me modifie toute la table avec la dernière ligne affiché ........
Voila le fichier php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Catalogue</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body link="#000000" vlink="#FFFFFF" alink="#FFFFFF">
<div id="body">
<?php
include ('config.php');
include ('connexion.php');
//nom_label
$nom_label = $_POST["nom_label"] ;
//reference
$reference = $_POST["reference"];
$sql1 = "SELECT contenu.reference, contenu.artiste, contenu.album, contenu.format, label.nom_label FROM contenu, label WHERE label.id_label = contenu.id_label AND label.nom_label = '".$_POST
['nom_label']."' ";
$req1= mysql_query($sql1) or die( mysql_error() ) ;
$total = mysql_num_rows($req1);
if($total!=0)
{
echo '<form method ="post" action="modif2.php">';
echo '<table>'."\n";
echo '<tr>';
echo '<td ><b><u>Label</u></b></td>';
echo '<td ><b><u>reference</u></b></td>';
echo '<td><b><u>artiste</u></b></td>';
echo '<td><b><u>album</u></b></td>';
echo '<td><b><u>format</u></b></td>';
echo '</tr>'."\n";
while($row = mysql_fetch_array($req1))
{
echo '<tr>';
echo '<td><input type="text" name="nom_label" value="'.$row["nom_label"].'"/></td>';
echo '<td><input type="text" name="reference" value="'.$row["reference"].'"/></td>';
echo '<td><input type="text" name="artiste" value="'.$row["artiste"].'"/></td>';
echo '<td><input type="text" name="album" value="'.$row["album"].'"/></td>';
echo '<td><input type="text" name="format" value="'.$row["format"].'"/></td>';
echo '</tr>'."\n";
}
echo '</table>'."\n";
echo '<input type="submit" name="btOk" value="Modifier!"/>';
echo '</form>';
if (isset($_POST['btOk']))
{
$sql3= "UPDATE
label, contenu
SET
nom_label='".$_POST['nom_label']."', reference='".$_POST['reference']."',
artiste='".$_POST['artiste']."',album='".$_POST['album']."',
format='".$_POST['format']."'";
$req3= mysql_query($sql3) or die('Erreur SQL !'.$sql2.'<br>'.mysql_error());
if($req3)
{
echo ("L'insertion a été correctement effectuée") ;
}
else
{
echo("L'insertion à échouée") ;
}
}
}
?>
</body></html>
<?php
mysql_close();
?>
Merci de votre aide
ja i deux fichiers php qui me permettent de mettre a jour ma base selon une selection depuis un menu déroulant je sélectionnes mes labels et j affiche mes références artiste album et format selon label choisi mis j ai un problème avec mon update je modifie une valeur et il me modifie toute la table avec la dernière ligne affiché ........
Voila le fichier php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Catalogue</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body link="#000000" vlink="#FFFFFF" alink="#FFFFFF">
<div id="body">
<?php
include ('config.php');
include ('connexion.php');
//nom_label
$nom_label = $_POST["nom_label"] ;
//reference
$reference = $_POST["reference"];
$sql1 = "SELECT contenu.reference, contenu.artiste, contenu.album, contenu.format, label.nom_label FROM contenu, label WHERE label.id_label = contenu.id_label AND label.nom_label = '".$_POST
['nom_label']."' ";
$req1= mysql_query($sql1) or die( mysql_error() ) ;
$total = mysql_num_rows($req1);
if($total!=0)
{
echo '<form method ="post" action="modif2.php">';
echo '<table>'."\n";
echo '<tr>';
echo '<td ><b><u>Label</u></b></td>';
echo '<td ><b><u>reference</u></b></td>';
echo '<td><b><u>artiste</u></b></td>';
echo '<td><b><u>album</u></b></td>';
echo '<td><b><u>format</u></b></td>';
echo '</tr>'."\n";
while($row = mysql_fetch_array($req1))
{
echo '<tr>';
echo '<td><input type="text" name="nom_label" value="'.$row["nom_label"].'"/></td>';
echo '<td><input type="text" name="reference" value="'.$row["reference"].'"/></td>';
echo '<td><input type="text" name="artiste" value="'.$row["artiste"].'"/></td>';
echo '<td><input type="text" name="album" value="'.$row["album"].'"/></td>';
echo '<td><input type="text" name="format" value="'.$row["format"].'"/></td>';
echo '</tr>'."\n";
}
echo '</table>'."\n";
echo '<input type="submit" name="btOk" value="Modifier!"/>';
echo '</form>';
if (isset($_POST['btOk']))
{
$sql3= "UPDATE
label, contenu
SET
nom_label='".$_POST['nom_label']."', reference='".$_POST['reference']."',
artiste='".$_POST['artiste']."',album='".$_POST['album']."',
format='".$_POST['format']."'";
$req3= mysql_query($sql3) or die('Erreur SQL !'.$sql2.'<br>'.mysql_error());
if($req3)
{
echo ("L'insertion a été correctement effectuée") ;
}
else
{
echo("L'insertion à échouée") ;
}
}
}
?>
</body></html>
<?php
mysql_close();
?>
Merci de votre aide
A voir également:
- Probleme update sql
- Windows update bloqué - Guide
- Winget update - Guide
- Asus live update - Télécharger - Utilitaires
- Windows update windows 10 - Guide
- Wsus offline update - Télécharger - Systèmes d'exploitation
5 réponses
Normal il faut une codition sinon l'update se fait sur tout
<?php $sql3= "UPDATE label,contenu SET nom_label='".$_POST['nom_label']."', reference='".$_POST['reference']."', artiste='".$_POST['artiste']."',album='".$_POST['album']."', format='".$_POST['format']."' WHERE condition" ; condition ce peut être nom_label = '".$_POST['choix_liste_selection']."'
et quand je mets $sql3= "UPDATE
label, contenu
SET
nom_label='".$_POST['nom_label']."', reference='".$_POST['reference']."',
artiste='".$_POST['artiste']."',album='".$_POST['album']."',
format='".$_POST['format']."' where reference = '".$_POST['reference']."' AND nom_label = '".$_POST['nom_label']."'
pas de suppression ou de modification par contre rien ne st modifié ...
label, contenu
SET
nom_label='".$_POST['nom_label']."', reference='".$_POST['reference']."',
artiste='".$_POST['artiste']."',album='".$_POST['album']."',
format='".$_POST['format']."' where reference = '".$_POST['reference']."' AND nom_label = '".$_POST['nom_label']."'
pas de suppression ou de modification par contre rien ne st modifié ...
il faut peut être mettre 2 conditions et comme tu fais l'UPDATE sur 2 tables préciser à quelle table appartiennent les champs
label.nom_champ etc..
à compléter bien sur pour tous les champs
label.nom_champ etc..
$sql3= "UPDATE label,contenu SET label.nom_label='".$_POST['nom_label']."', ?.reference='".$_POST['reference']."', ?.artiste='".$_POST['artiste']."',?.album='".$_POST['album']."', ?.format='".$_POST['format']."' WHERE?. reference = '".$_POST['reference']."' AND label.nom_label'= '".$_POST['nom_label']."'";
à compléter bien sur pour tous les champs
roh lala maintenant il me met ca Erreur SQL !
Query was empty alors que j ai voulu modifier reference qui n est pas une cle primaire dans ma tbale :-(
Query was empty alors que j ai voulu modifier reference qui n est pas une cle primaire dans ma tbale :-(
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question