Mise à jour des données à partir d'un formulaire
Bonjour,
J'essaie de mettre en place un livre d'or sur mon site en local, mais j'ai quelque petits soucis
Dans l' entête de ma page je gère un lien conditionnel pour acceder au formulaire du livre d'or (Si la personne est connecter alors il a le lien du formulaire sinon rien)
Code du haut de ma page qui est inclut sur tout les autre
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
<?php
@session_start()
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<?php
/**********Vérification du titre...*************/
include_once ('config.php');
include_once ('constants.php');
/*include_once ('configs.php');*/
include_once ('securite.php');
include_once ('function.php');
include_once ('identifiants.php');
include_once ('bbcode.php');
if(isset($titre) && trim($titre) != '')
$titre = $titre.' : '.TITRESITE;
else
$titre = TITRESITE;
/***********Fin vérification titre...************/
?>
<title><?php echo $titre; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="language" content="fr" />
<link rel="stylesheet" title="Design" href="<?php echo ROOTPATH; ?>/css/arabica.css" type="text/css" media="screen" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--[if lte IE 7]>
<link rel="stylesheet" href="./css/style_ie.css" />
<![endif]-->
<script>
function bbcode(bbdebut, bbfin)
{
var input = window.document.formulaire.message;
input.focus();
if(typeof document.selection != 'undefined')
{
var range = document.selection.createRange();
var insText = range.text;
range.text = bbdebut + insText + bbfin;
range = document.selection.createRange();
if (insText.length == 0)
{
range.move('character', -bbfin.length);
}
else
{
range.moveStart('character', bbdebut.length + insText.length + bbfin.length);
}
range.select();
}
else if(typeof input.selectionStart != 'undefined')
{
var start = input.selectionStart;
var end = input.selectionEnd;
var insText = input.value.substring(start, end);
input.value = input.value.substr(0, start) + bbdebut + insText + bbfin + input.value.substr(end);
var pos;
if (insText.length == 0)
{
pos = start + bbdebut.length;
}
else
{
pos = start + bbdebut.length + insText.length + bbfin.length;
}
input.selectionStart = pos;
input.selectionEnd = pos;
}
else
{
var pos;
var re = new RegExp('^[0-9]{0,3}$');
while(!re.test(pos))
{
pos = prompt("insertion (0.." + input.value.length + "):", "0");
}
if(pos > input.value.length)
{
pos = input.value.length;
}
var insText = prompt("Veuillez taper le texte");
input.value = input.value.substr(0, pos) + bbdebut + insText + bbfin + input.value.substr(pos);
}
}
function smilies(img)
{
window.document.formulaire.message.value += '' + img + '';
}
</script>
</head>
<?php
//Attribution des variables de session
$lvl=(isset($_SESSION['level']))?(int) $_SESSION['level']:1;
$id=(isset($_SESSION['id']))?(int) $_SESSION['id']:0;
$pseudo=(isset($_SESSION['pseudo']))?$_SESSION['pseudo']:'';
?>
<body>
<div id="imagemap">
<nav>
<ul>
<li><a href="<?php echo ROOTPATH; ?>/cafres/acceuil.php" class="zone">Accueil</a></li>
<li><a href="<?php echo ROOTPATH; ?>/actualite/index.php" class="zone">Quoi de neuf</a></li>
<li><a href="<?php echo ROOTPATH; ?>/phototheque/index.php" class="zone">Album</a></li>
<li><a href="<?php echo ROOTPATH; ?>/dictionnaire/index.php" class="zone">Dico</a></li>
<li><a href="<?php echo ROOTPATH; ?>/detente/index.php" class="zone">Jeux</a></li>
<li><a href="<?php echo ROOTPATH; ?>/biographie/index.php" class="zone">Biographie</a></li>
<li><a href="<?php echo ROOTPATH; ?>/forum/index.php" class="zone">Forum</a></li>
<li><a href="<?php echo ROOTPATH; ?>/forum/admin.php" class="zone">Administration du forum</a></li>
<li><a href="<?php echo ROOTPATH; ?>/inc/contact.php" class="zone">Contact</a></li>
<li><a href="#" class="zone">index A</a></li>
<li><a href="#" class="zone">index B</a></li>
<li><a href="#" class="zone">index C</a></li>
</ul>
</nav>
<div id="banniere_description">
<h3><a href="<?php echo ROOTPATH; ?>/membre/connexion.php" class="zone">Connexion </a>
<a href="<?php echo ROOTPATH; ?>/membre/deconnexion.php" class="zone"> Se deconnecter</a>
<?php if (isset($_SESSION['membre_id'])<0);
{
echo "<a href='../livreor/nouveau.php?membre_id=$id' class='zone'> Ajouté un commentaire</a>";
}
?>
</h3>
<a href="<?php echo ROOTPATH; ?>/livreor/index.php" class="bouton_rouge">Livre d'or <img src="../css/images/flecheblanchedroite.png" alt="" /></a>
</div>
</div>
</div>
</body> |
Lorsque je clique sur le lien pour accéder au formulaire une ligne est créée dans ma base avec l'id de la personne a chaque fois et lors de l'envoi du formulaire une seconde ligne est crée mais sans l'id de la personne
Le code de mon formulaire
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
<?php
session_start ();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<?php
include_once ('../inc/haut.php');
// Si le membre n'est pas connecté, il est arrivé ici par erreur
if ($id==0) erreur(ERR_IS_CO);
//On récupère la valeur de la variable a partir du lien du haut de la page
$id = (isset($_GET['membre_id']))?htmlspecialchars($_GET['membre_id']):'';
echo '<h1>Vos commentaires</h1><br /><br />';
?>
<form method="post" action="nouveau.php" name="formulaire">
<input name="membre_id" type="hidden" value="<?php echo $GET["membre_id"];?>"/>
<input type="button" id="gras" name="gras" value="Gras" onClick="javascript:bbcode('[g]', '[/g]');return(false)" />
<input type="button" id="italic" name="italic" value="Italic" onClick="javascript:bbcode('', '');return(false)" />
<input type="button" id="souligné" name="souligné" value="Souligné" onClick="javascript:bbcode('', '');return(false)" />
<input type="button" id="lien" name="lien" value="Lien" onClick="javascript:bbcode('', '');return(false)" />
<br /><br />
<img src="../images/smileys/heureux.gif" title="heureux" alt="heureux" onClick="javascript:smilies(':D');return(false)" />
<img src="../images/smileys/lol.gif" title="lol" alt="lol" onClick="javascript:smilies(':lol:');return(false)" />
<img src="../images/smileys/triste.gif" title="triste" alt="triste" onClick="javascript:smilies(':triste:');return(false)" />
<img src="../images/smileys/cool.gif" title="cool" alt="cool" onClick="javascript:smilies(':frime:');return(false)" />
<img src="../images/smileys/rire.gif" title="rire" alt="rire" onClick="javascript:smilies('XD');return(false)" />
<img src="../images/smileys/confus.gif" title="confus" alt="confus" onClick="javascript:smilies(':s');return(false)" />
<img src="../images/smileys/choc.gif" title="choc" alt="choc" onClick="javascript:smilies(':O');return(false)" />
<img src="../images/smileys/question.gif" title="?" alt="?" onClick="javascript:smilies(':interrogation:');return(false)" />
<img src="../images/smileys/exclamation.gif" title="!" alt="!" onClick="javascript:smilies(':exclamation:');return(false)" />
<textarea cols="80" rows="8" id="message" name="message"></textarea>
<br />
<input type="submit" name="submit" value="Envoyer" />
<input type="reset" name="Effacer" value="Effacer" /></p>
</form>
<?php
if (isset($_POST['message']))
{
$liv_message = securite_bdd(code($_POST["message"]));
}
$id=$_GET['membre_id'];
$date = time();
//Enfin on peut envoyer le message
$sql="INSERT INTO livreor (message,membre_id) VALUES ('$message','$id')";
$req= mysql_query($sql) or die ('Erreur : '.mysql_error());
echo $req;
?> |
Structure de ma base de donnée
Code:
1 2 3 4 5 6 7 8 9
|
CREATE TABLE IF NOT EXISTS `livreor` (
`liv_id` int(11) NOT NULL AUTO_INCREMENT,
`message` mediumtext NOT NULL,
`liv_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`membre_id` int(11) NOT NULL,
PRIMARY KEY (`liv_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; |
j'ai aussi ces deux message d'erreurs dans ma page du formulaire, les variable je les aient bien déclaré
Code:
1 2 3 4 5
|
Notice: Undefined index: membre_id in E:\wamp\www\couleurcafre\livreor\nouveau.php on line 46
Notice: Undefined variable: message in E:\wamp\www\couleurcafre\livreor\nouveau.php on line 52 |
je vous remerci de votre aide
Runcafre91