Probleme guillemet qui disparaisse

Fermé
stefanelle - 1 mars 2009 à 13:14
 stefanelle - 1 mars 2009 à 13:34
Bonjour,

J ai deux fichiers php un qui m affiche un tableau avec les entrées de ma base avec une option pour modifier cette entrée et un autre qui affiche la ligne choisie et qui me permet de modifier cette ligne le problème est que quand je clique sur modifier sur l autre page il m enlève les guillemets les 7" devient 7 je sais qu il faut mettre un \ devant mes guillemets ou utiliser addslahes mais je ne sais pas ou ... j ai essayé avec htmlspecialschar mais ca ne marche pas

pouvez-vous m aider

<?php

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


if (isset($_POST['btOk']))


{
$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());


}

?>


<!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-cat.css">
</head>
<body link="#000000" vlink="#555555" alink="#dddddd">
<div id="body">
<div id="menu-container"><b>
<a href="label.php?lettre=[0-9]" class="active"><span class="text">0-9</span></a> |
<a href="label.php?lettre=A" target="_self"><span class="text">A</span></a> |
<a href="label.php?lettre=B" target="_self"><span class="text">B</span></a> |
<a href="label.php?lettre=C" target="_self"><span class="text">C</span></a> |
<a href="label.php?lettre=D" target="_self"><span class="text">D</span></a> |
<a href="label.php?lettre=E" target="_self"><span class="text">E</span></a> |
<a href="label.php?lettre=F" target="_self"><span class="text">F</span></a> |
<a href="label.php?lettre=G" target="_self"><span class="text">G</span></a> |
<a href="label.php?lettre=H" target="_self"><span class="text">H</span></a> |
<a href="label.php?lettre=I" target="_self"><span class="text">I</span></a> |
<a href="label.php?lettre=J" target="_self"><span class="text">J</span></a> |
<a href="label.php?lettre=K" target="_self"><span class="text">K</span></a> |
<a href="label.php?lettre=L" target="_self"><span class="text">L</span></a> |
<a href="label.php?lettre=M" target="_self"><span class="text">M</span></a> |
<a href="label.php?lettre=N" target="_self"><span class="text">N</span></a> |
<a href="label.php?lettre=O" target="_self"><span class="text">O</span></a> |
<a href="label.php?lettre=P" target="_self"><span class="text">P</span></a> |
<a href="label.php?lettre=Q" target="_self"><span class="text">Q</span></a> |
<a href="label.php?lettre=R" target="_self"><span class="text">R</span></a> |
<a href="label.php?lettre=S" target="_self"><span class="text">S</span></a> |
<a href="label.php?lettre=T" target="_self"><span class="text">T</span></a> |
<a href="label.php?lettre=U" target="_self"><span class="text">U</span></a> |
<a href="label.php?lettre=V" target="_self"><span class="text">V</span></a> |
<a href="label.php?lettre=W" target="_self"><span class="text">W</span></a> |
<a href="label.php?lettre=X" target="_self"><span class="text">X</span></a> |
<a href="label.php?lettre=Y" target="_self"><span class="text">Y</span></a> |
<a href="label.php?lettre=Z" target="_self"><span class="text">Z</span></a></b>
</div>

<?php


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

$new = htmlspecialchars('<td><a href="m.php?id='.$resultat['id'].'">Modifier</a></td>';, ENT_QUOTES);

if(isset($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>';
}




echo '<table>

<tr>
<th>id</th>
<th>Label</th>
<th>Référence</th>
<th>Artiste</th>
<th>Album</th>
<th>Format</th>
<th>Modifier</th>


</tr>';

// paramètre reçu désignant le critère du nom du label recherché
$param1 = mysql_real_escape_string($_GET['lettre']);


//
$sql = "SELECT * FROM label
INNER JOIN contenu ON contenu.id_label = label.id_label
Where nom_label REGEXP '^$param1' order by nom_label, reference;
";
$req = mysql_query($sql);
while ($resultat = mysql_fetch_array($req))


{
echo '<tr>';

echo '<td>'.$resultat['id'].'</td>';
echo '<td>'.$resultat['nom_label'].'</td>';
echo '<td>'.$resultat['reference'].'</td>';
echo '<td>'.$resultat['artiste'].'</td>';
echo '<td>'.$resultat['album'].'</td>';
echo '<td>'.$resultat['format'].'</td>';
echo $new;





echo '</tr>';
}

echo '</table>';

$var = $resultat;

if($var == null){


echo "Aucune référence trouvée";


}



?>

</body></html>

<?php
mysql_close();
?>

le deuxieme 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-cat.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);

{
echo '<form method ="post" action="lm.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="hidden" name="id" value="'.$_GET['id'].'" /><input

type="submit" name="btOk" value="Modifier"/>';
echo '</form>';


}


?>

</body></html>

<?php
mysql_close();
?>

2 réponses

doctormad Messages postés 430 Date d'inscription mercredi 28 novembre 2007 Statut Membre Dernière intervention 2 avril 2015 100
1 mars 2009 à 13:17
Salut,

Quand tu fais une requête a partir d'une donnée inconnue (utilisateur) il faut utiliser mysql_real_escape_string() pour la bdd.
0
merci mais ou dois je le placer ?

Merci
0
doctormad Messages postés 430 Date d'inscription mercredi 28 novembre 2007 Statut Membre Dernière intervention 2 avril 2015 100
1 mars 2009 à 13:31
Dans toutes tes requetes, ex "select * from table where champ='".mysql_real_escape_string($champ)"'."";
0
ok merci beaucoup je vais tester :-)
0