Tout d'abord bonjour à tous

Très content d'être parmis vous

Voici mon probleme : Je prend des cours en php et j'ai decidé de faire un livre d'or (pour le livre no problemo) avec un captcha (c'est la que vient le probleme)
Je n'arrive po a associé les deux

...
voici mon code php :
<?php
session_start();
if(isset($_POST["code"]) && $_POST['submit'] && $_POST['submit']=='Signer') {
if(($_SESSION['captcha_code'] == $_POST['code']) && (!empty($_SESSION['captcha_code'])) ) {
//Passed!
$captcha_msg="Merci";
}else{
// Not passed 8-(
$captcha_msg="Code invalide";
if(isset($_POST["MM_insert"])){
unset($_POST["MM_insert"]);
}
if(isset($_POST["MM_update"])){
unset($_POST["MM_update"]);
}
}
}
class CaptchaImage {
var $font = "./livre/verdana.ttf";
function hex_to_dec($hexcolor){
//convert hex hex values to decimal ones
$dec_color=array('r'=>hexdec(substr($hexcolor,0,2)),'g'=>hexdec(substr($hexcolor,2,2)),'b'=>hexdec(substr($hexcolor,4,2)));
return $dec_color;
}
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaImage($width='120',$height='30',$characters='6',$hex_bg_color='FFFFFF',$hex_text_color="FF0000",$hex_noise_color="CC0000", $img_file='captcha.jpg') {
$rgb_bg_color=$this->hex_to_dec($hex_bg_color);
$rgb_text_color=$this->hex_to_dec($hex_text_color);
$rgb_noise_color=$this->hex_to_dec($hex_noise_color);
$code = $this->generateCode($characters);
/* font size will be 60% of the image height */
$font_size = $height * 0.50;
$image = @imagecreate($width, $height) or die('Cannot Initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, $rgb_bg_color['r'], $rgb_bg_color['g'],$rgb_bg_color['b']);
$text_color = imagecolorallocate($image, $rgb_text_color['r'], $rgb_text_color['g'],$rgb_text_color['b']);
$noise_color = imagecolorallocate($image, $rgb_noise_color['r'], $rgb_noise_color['g'],$rgb_noise_color['b']);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code);
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code);
/* save the image */
imagejpeg($image,$img_file);
imagedestroy($image);
echo "<img src=\"$img_file?".time()."\" width=\"$width\" height=\"$height\" alt=\"security code\" id=\"captchaImg\">";
$_SESSION['captcha_code'] = $code;
if ((isset($_POST['auteur'])) && (isset($_POST['email'])) && (isset($_POST['message']))) {
// si les 3 variables ne sont pas vides, et si l'adresse E-mail est valide, alors, et seulement dans ce cas, on fera notre insertion dans la base
if ((!empty($_POST['auteur'])) && (!empty($_POST['email'])) && (!empty($_POST['message']))) {
// on verifie le format de l'adresse E-mail saisie
$test_mail = eregi ('^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)+$', $_POST['email']);
if ($test_mail) {
// on se connecte à notre base
$base = mysql_connect ('db1472.1and1.fr', 'dbo245399632', 'suzette');
mysql_select_db ('db245399632', $base);
// on prepare notre requête d'insertion des données
$sql = 'INSERT INTO livre_or VALUES("", "'.mysql_escape_string($_POST['auteur']).'", "'.mysql_escape_string($_POST['email']).'", "'.date("Y-m-d H:i:s").'", "'.mysql_escape_string($_POST['message']).'")';
// on lance la requête
mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error());
// on ferme la connexion à la base de données
mysql_close();
// on termine le script courant
exit();
}
else {
$erreur = 'Votre adresse E-mail est invalide.';
}
}
else {
$erreur = 'Au moins un des champs est vide.';
}
}
else {
$erreur = 'Les variables nécessaires au script ne sont pas définies.';
}
}
}
?>
et mon formulaire :
<form name="livreor" id="livreor" action="index1.php?page=id21" method="post">
<table>
<tr><td>
<span class="gras">Auteur :</span>
</td><td>
<input type="text" name="auteur" maxlength="30" size="50" value="<?php if (isset($_POST['auteur'])) echo htmlentities(trim($_POST['auteur'])); ?>">
</td></tr><tr><td>
<span class="gras">Adresse E-mail :</span>
</td><td>
<input type="text" name="email" maxlength="50" size="50" value="<?php if (isset($_POST['email'])) echo htmlentities(trim($_POST['email'])); ?>">
</td></tr>
<tr><td colspan="2"> <p align="right"><a href="javascript: smiley(' c014 ');"><img src="./img/smiley/c014.gif" border="0"></a> <a href="javascript: smiley(' lol ');"><img src="./img/smiley/lol.gif" border="0"></a> <a href="javascript: smiley(' hihihi ');"><img src="./img/smiley/hihihi.gif" border="0"></a> <a href="javascript: smiley(' mdr ');"><img src="./img/smiley/mdr.GIF" width="62" height="53" border="0"></a> <a href="javascript: smiley(' ;) ');"><img src="./img/smiley/wink.gif" width="20" height="20" border="0"></a> <a href="javascript: smiley(' c029 ');"><img src="./img/smiley/c029.gif" border="0"></a> <a href="javascript: smiley(' 8-( ');"><img src="./img/smiley/colere.gif" border="0"></a> <a href="javascript:smiley(' :) ');"><img src="./img/smiley/fou.png" width="19" height="19" border="0"></a> <a href="javascript: smiley(' :-? ');"><img src="./img/smiley/confus.gif" width="20" height="20" border="0"></a> <a href="javascript: smiley(' c066 ');"><img src="./img/smiley/c066.gif" border="0"></a> <a href="javascript: smiley(' ^^ ');"><img src="./img/smiley/fete.gif" width="42" height="34" border="0"></a> </p>
</td></tr>
<tr><td>
<span class="gras">Votre message :</span>
</td><td>
<textarea name="message" id="message" onSelect="storeCaret(this);" onClick="storeCaret(this);" onKeyUp="storeCaret(this);" cols="50" rows="10" value="<?php if (isset($_POST['message'])) echo nl2br(htmlentities(trim($data['message'],ENT_COMPAT , 'utf-8'))); ?>"></textarea>
</td></tr>
<tr>
<td>Code :</td>
<td><?php $captcha = new CaptchaImage(120,50,5,'FF0099','FFFFFF','000000');?></td></tr>
<tr>
<td>
Saisir le code
:
<td><label>
<input type="text" name="code" id="code">
<?php echo $captcha_msg ?></label></td>
</tr>
<tr>
<td>
<td align="right">
<input type="submit" name="submit" value="Signer">
</td></tr></table>
</form><br /></p><?php
if (isset($erreur)) echo '<br /><br />',$erreur;
?>
Merci de votre aide ça serai sympa de m'expliquer mon erreur sinon je recommencerai lol
Merci a tous et super site c'est grâce a vous que je me suis mi a apprendre le php
