Probleme update

stefanelle -  
 stefanelle -
Bonjour,

a tous voila un fichier php qui me permet de récupérer une ligne d un tableau avec mes entrées dans ma base afin de la supprimer ou modifier, j ai deux soucis

- j arrive a modifier le champ artiste, album et format mais pas le champ reference (qui n est pas une clé primaire)

[code]<!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="#444444" alink="#888888">
<div id="body">

<?php

include ('config.php');
include ('connexion.php');

$id = $_GET["id"];

$sql = "SELECT id, reference, artiste, album, format FROM contenu WHERE id='".$_GET['id']."'" ;

$req = mysql_query($sql) or die( mysql_error() ) ;

$total = mysql_num_rows($req);

$sql2= "UPDATE contenu SET reference='".$_POST['reference']."', artiste='".$_POST['artiste']."',album='".$_POST['album']."',format='".$_POST['format']."'
WHERE id ='".$_POST['id']."'" ;

$req2= mysql_query($sql2) or die('Erreur SQL !'.$sql2.'<br>'.mysql_error());

{
echo '<form method ="post" action="modifier.php">';
echo '<table>'."\n";
echo '<tr>';
echo '<td ><b><u>ID</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($req))

{
echo '<tr>';
echo '<td>'.$id.'</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']))

{

if($req2)

{
echo ("L'insertion a été correctement effectuée") ;
echo '<br><a href="http://arm-info.hd.free.fr/handsandarms/label_modif.php">Retour sur les labels</a></br>';
}

else

{
echo("L'insertion à échouée") ;
}

}
}

?>

</body></html>

<?php
mysql_close();
?>
A voir également:

1 réponse

vincent.jerem Messages postés 30 Statut Membre 2
 
Moi je serais toi j'utiliserais plutot 2 fichiers et j'utiliserais des variables :
Le premire fichier contenant le tableau avec les valeurs de la première requete :
<!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="#444444" alink="#888888">
<div id="body">

<?php
include ('config.php');
include ('connexion.php');

$id = $_GET["id"];

$sql = "SELECT id, reference, artiste, album, format FROM contenu WHERE id='".$id."'" ;

$req = mysql_query($sql) or die( mysql_error() ) ;

//$sql2= "UPDATE contenu SET reference='".$_POST['reference']."', artiste='".$_POST['artiste']."',album='".$_POST['album']."',format='".$_POST['format']."'
//WHERE id ='".$_POST['id']."'" ;

//$req2= mysql_query($sql2) or die('Erreur SQL !'.$sql2.'<br>'.mysql_error());

?><form method ="POST" action="modifier.php">
<table>
<tr>
<td ><b><u>ID</u></b></td>
<td><b><u>reference</u></b></td>
<td><b><u>artiste</u></b></td>
<td><b><u>album</u></b></td>
<td><b><u>format</u></b></td>
</tr>
<?php
while($ligne = mysql_fetch_array($req);)

{
echo '<tr>';
echo '<td><input readonly type="text" name="id" value="'.$ligne["id"].'"/></td>';
echo '<td><input type="text" name="reference" value="'.$ligne["reference"].'"/></td>';
echo '<td><input type="text" name="artiste" value="'.$ligne["artiste"].'"/></td>';
echo '<td><input type="text" name="album" value="'.$ligne["album"].'"/></td>';
echo '<td><input type="text" name="format" value="'.$ligne["format"].'"/></td>';
echo '</tr>'."\n";

}
echo '</table>'."\n";
echo '<input type="submit" name="btOk" value="Modifier"/>';
echo '</form>';

?>

</body></html>

<?php
mysql_close();
?>

Et ensuite le second fichier (modifier.php) :
<?php
include ('config.php');
include ('connexion.php');

$Ref=$_POST['reference'];
$Art=$_POST['artiste'];
$Format=$_POST['format'];
$Album=$_POST['album'];
$Id=$_POST['id'];

$sql= "UPDATE contenu SET reference='".$Ref."', artiste='".$Art."',album='".$Album."',format='".$Format."' WHERE id ='".$Id."'" ;

$req= mysql_query($sql2) or die('Erreur SQL !'.$sql2.'<br>'.mysql_error());

if($req)
{
echo ("La modification a été correctement effectuée") ;
header("Location:http://arm-info.hd.free.fr/handsandarms/label_modif.php");
}
else
{
echo("L'insertion à échouée") ;
}

?>

Bonne continuation ...
0
stefanelle
 
bonjour

ca ne marche pas :-(
0