html - impossible to retrieve the values of my form php mysql
344
Here is my code:
<?php
session_start();
header('Content-type: text/html; charset=utf-8');
/********Actualisation de la session...**********/
include('../includes/fonctions.php');
connexionbdd();
actualiser_session();
/********Fin actualisation de session...**********/
if(!isset($_SESSION['membre_admin'])) {
header ('Location: index.php');
exit();
}
?>
<!DOCTYPE html>
...
<script language="javascript">
function confirmeee( identifiant )
{
var confirmation = confirm( "Voulez vous vraiment éditercet enregistrement ?" ) ;
if( confirmation )
{
document.location = "edition1.php?idNews="+identifiant ;
}
else(confirmation)
{
alert("erreur");
}
}
</script>
...
and my form
<?php
//récupération de la variable d'URL,
//qui va nous permettre de savoir quel enregistrement éditer:
$id = $_GET["idNews"] ;
//requête SQL:
$sql = "SELECT *
FROM news
WHERE id = ".$id ;
$requete=mysql_query($sql);
//echo "$sql" ;
//exécution de la requête:
while($row = mysql_fetch_array( $requete ))
{
if($row["text"] != NULL)
{
echo '<form method="post" onsubmit="return confirmeee('.$row["id"].')">
<tr><td>Id article : '.$row["id"].'</label></td></br></br>
<tr><td><label for="textarea" >Titre :</label></td>
<td><TEXTAREA name="title" cols="90" >'.$row["title"].'</TEXTAREA></td></tr></br></br>
<tr><td><label for="title" >Contenu :</label></td>
<td><TEXTAREA name="text" WRAP=VIRTUAL rows="30" cols="100" >'.$row["text"].'</TEXTAREA></td></tr></br>
<input type="submit" value="Mise à jour" ></br></br>
</form>';
}
}
?>
and my page edition1.php which it is impossible to retrieve information :
<?php
$id = $_GET["idNews"] ;
//récupération du formulaire
$text=formulaires($_POST['text']);
$title=formulaires($_POST['title']);
$text = nl2br($text);
mysql_query("UPDATE news SET text='$text' , title='$title' WHERE id='".$_GET['idNews']."' ") or die ('Erreur : '.mysql_error());
echo'L\'article a été modifié<br/><a href="admin.php">Retour</a></br>';
?>
I can t retrieve the informations in edition1.php, when i try my update, this remove my data in "text" and "title".
where is my mistake?
Answer
Solution:
I would change the form tag :
Then put an onclick event on the button with your JS function :
You don't need the id in the JS script anymore.
Then finally call
instead of