Re: Bug étrange avec les formulaires ... [Résolu]

Petit nouveau ! | 4 Messages

17 déc. 2010, 00:13

Bonsoir à tous,

Je viens vous demander de l'aide car j'ai un bug très étrange. Je suis en train de faire un jeu par navigateur (oui oui, je sais c'est très original comme idée...) et j'ai fais une formulaire d'inscription (fonctionne) , la connexion à notre compte avec des variables de sessions (ok) et la je suis en train de réaliser le création d'un personnage depuis le compte crée lorsque l'on est connecté.

Mais, dès que je me connecte, aucun formulaire n'est traité et pire encore mes variables de sessions sont modifiés... En gros je suis connecté au site ($_SESSION['co'] passe à 1 et mon menu pour les membres connectés s'affiche) , et dès que je veux créer un perso via la formulaire, ma page se réactualise et la variable de session 'co' passe à 0 et quelque soit le nom que j'ai mis dans le "action" du formulaire, j'ai tout simplement l'impression que le formulaire n'est pas lu...

Je vous met les liens de mon site pour que vous puissiez tester:

http://magic9110.free.fr/SiteDeDieu/index.php (vous pouvez créer un compte bidon il n'y a pas de test de validité sur les e-mails ou autres pour le moment)

formulaire de création:
<!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" lang="fr">

   <head>
   <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
   </head>

   <body>
		<table class="normal">
			<tr >
				<td align="center">
					<br/>
					
					<form action="index.php" method="post" enctype="multipart/form-data">
						<legend><b>Entrer le nom du perso et choisissez son sexe et sa race.<br/>Le choix de la race aura un impact direct sur ses caract&eacute;ristiques !<br/><br/></b></legend>
						<span>Pseudo du personnage :</span>
						<div class="menu_bar"><input  class="menu_imput2" type="login" name="perso"/></div><br/>
						<span>Sexe :</span>
						<select name="choix_sexe">
							<option value="Homme">Homme</option>
							<option value="Femme">Femme</option>
						</select><br/><br/>
						<span>Race :</span>
						<select name="choix_race">
							<option value="Humain">Humain</option>
							<option value="Elfe">Elfe</option>
							<option value="DarkElfe">Dark Elfe</option>
							<option value="Orc">Orc</option>
							<option value="Nain">Nain</option>
						</select>
						<br/><br/>
						<input class="menu_submit3"  type="submit" value="OK" />
						
					</form>
					
				</td>
			</tr>
		</table>
	</body>

</html>
index.php:
<?php
session_start();

include("nomspages.php"); 






$link = mysql_connect("sql.free.fr", "******", "******");
mysql_select_db("magic9110");



$retour = mysql_query('SELECT COUNT(*) AS nbre_entrees FROM online WHERE ip=\'' . $_SERVER['REMOTE_ADDR'] . '\'');
$donnees = mysql_fetch_array($retour);
#
 
#
if ($donnees['nbre_entrees'] == 0) // L'ip ne se trouve pas dans la table, on va l'ajouter
#
{
#
    mysql_query('INSERT INTO online (ip, timestamp) VALUES(\'' . $_SERVER['REMOTE_ADDR'] . '\', ' . time() . ')');
#
}
#
else // L'ip se trouve déjà dans la table, on met juste à jour le timestamp
#
{
#
    mysql_query('UPDATE online SET timestamp=' . time() . ' WHERE ip=\'' . $_SERVER['REMOTE_ADDR'] . '\'');
#
}

// -------
#
// ETAPE 2 : on supprime toutes les entrées dont le timestamp est plus vieux que 5 minutes
#
 
#
// On stocke dans une variable le timestamp qu'il était il y a 5 minutes :
#
$timestamp_5min = time() - (60 * 2); // 60 * 2 = nombre de secondes écoulées en 2 minutes
#
mysql_query('DELETE FROM online WHERE timestamp < ' . $timestamp_5min);
#
 
#
// -------
#
// ETAPE 3 : on compte le nombre d'ip stockées dans la table. C'est le nombre de visiteurs connectés
#
$retour = mysql_query('SELECT COUNT(*) AS nbre_entrees FROM online');
#
$donnees = mysql_fetch_array($retour);

$result = mysql_query("SELECT * FROM table_users");
$i_nbLigne = mysql_num_rows($result);

if ( (isset($_POST['perso'])) && (isset($_POST['choix_race'])) && (isset($_POST['choix_sexe'])) )
{
	if ( !(empty($_POST['identifiant'])) && !(empty($_POST['mot_de_passe'])) && !(empty($_POST['e_mail'])) )
	{
 

		mysql_query("UPDATE table_users SET perso = '" . $_SESSION['perso'] . "' , race = '" . $_SESSION['choix_race'] . "' , sexe = '" . $_SESSION['choix_sexe'] . "' WHERE pseudo = '" . $_SESSION['pseudo'] ."' ");
			
	

 

	if($_POST['choix_race'] == 'Humain')

	{
		
		mysql_query('UPDATE table_users SET vie = 100, vie_max = 100, mana = 500, mana_max = 500, cp = 50, cp_max = 50 WHERE pseudo =\'' . $_SESSION['pseudo'] . '\'');

	}

	if($_POST['choix_race'] == 'Elfe')

	{

	mysql_query('UPDATE table_users SET vie = 90, vie_max = 90, mana = 600, mana_max = 600, cp = 45, cp_max = 45, adena = 0, ancient_adena = 0, force = 100 WHERE pseudo =\'' . $_SESSION['pseudo'] . '\'');

	}

	if($_POST['choix_race'] == 'DarkElfe')

	{

	mysql_query('UPDATE table_users SET vie = 80, vie_max = 80, mana = 600, mana_max = 600, cp = 40, cp_max = 40 WHERE pseudo =\'' . $_SESSION['pseudo'] . '\'');

	}

	if($_POST['choix_race'] == 'Orc')

	{

	mysql_query('UPDATE table_users SET vie = 110, vie_max = 110, mana = 400, mana_max = 400, cp = 55, cp_max = 55 WHERE pseudo =\'' . $_SESSION['pseudo'] . '\'');

	}

	if($_POST['choix_race'] == 'Nain')

	{

	mysql_query('UPDATE table_users SET vie = 120, vie_max = 120, mana = 300, mana_max = 300, cp = 60, cp_max = 60 WHERE pseudo =\'' . $_SESSION['pseudo'] . '\'');

	}

 

	$req = $bdd->exec('UPDATE table_users SET creation = 1 WHERE pseudo =\'' . $_SESSION['pseudo'] . '\'');

	$_SESSION['co']=0;



	echo "Personnage Créé, veuillez vous reconnecter";
	
	}
}


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">

<head> 
<title>Lineage ][ Fan Game</title><meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> 
<meta NAME="description" CONTENT="Lineage 2, Gracia epilogue, la2, illicitegames, mmorpg, game, online, serveur"> 
<meta name="robots" content="index, follow">
<meta HTTP-EQUIV="Content-Language" CONTENT="FR">
<meta HTTP-EQUIV="Content-Language" CONTENT="EN">
<LINK rel="SHORTCUT ICON" href="img/favicon.png">
<link href="css/style.css" type=text/css rel=StyleSheet>
</head>

<body>

<table width="100%" height="100%" align="center" class="normal" valign="top" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td height="421" colspan="2" style="background: #b3ffe3 url(img/head1.jpg) no-repeat; background-position: top right;">&nbsp;</td>
		<td height="421" width="510" style="background-image: url(img/head2.jpg); background-repeat: no-repeat; background-position: top center;" nowrap>&nbsp;</td>
		<td height="421" colspan="2" style="background: #48a7c0 url(img/head3.jpg) no-repeat; background-position: top left;" align="right" valign="top"><div style="padding: 8px"><a href="../l2top.ru/vote/11315/default.htm" target="_blank"></a></div></td>
	</tr>
	
	<tr>
		<td height="421" style="background: #b3ffe3 url(img/left2.jpg) no-repeat; background-position: top right;">
			<table width="100%" height="100%" align="center" class="normal" valign="top" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td height="100%" style="background: url(img/left3.jpg) no-repeat; background-position: bottom right;">&nbsp;</td>
				</tr>
			</table>
		</td>
		
		<td width="268" style="background: #b3ffe3 url(img/left1.jpg) no-repeat; background-position: top right;" valign="top"> 

		<table width="268" height="100%" align="center" class="normal" valign="top" cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td valign="top" height="176" style="padding-top: 50px; padding-left: 25px;">
					<?php
						if ( isset($_SESSION['co'] ))
						{
								echo " session_co = " ; 
								echo $_SESSION['co'];
								echo "<br/><br/>";
								
							if ($_SESSION['co'] == 1 )
							{
								include("ol.php");
							}
							else
							{
								include("hl.php");
							}
						}
						else
						{
							include("hl.php");
						}
	
					?>
				</td>
			</tr>
				
	
			<tr>
				<td valign="top" height="160" style="background: #efe3ac url(img/menubg1.jpg) repeat-y; background-position: top right;">
					<table width="100%" height="160" align="center" class="normal" valign="top" cellpadding="0" cellspacing="0" border="0" style="background-image: url(img/menubg2.jpg); background-repeat: no-repeat; background-position: bottom right;">
					<tr>
						<td valign="top" style="padding-left: 13px; padding-bottom: 12px;">
							<table width="100%" height="100%" align=center class=normal valign=top cellpadding=0 cellspacing=0 border=0>
						
								<tr>
									<td height="24" style="background: url(img/menu1.jpg) no-repeat;">&nbsp;</td>
								</tr>

								<tr>
									<td height="20" style="background: url(img/menut.jpg) no-repeat;"><a href="index.php" class="mlink"> Accueil </a></td>
								</tr>
					
								<tr>
									<td height="20" style="background: url(img/menut.jpg) no-repeat;"><a href="index.php?page=histoire" class="mlink"> L'Histoire </a></td>
								</tr>
					
								<tr>
									<td height="20" style="background: url(img/menut.jpg) no-repeat;"><a href="index.php?page=races" class="mlink"> Les Races </a></td>
								</tr>
					
								<tr>
									<td height="20" style="background: url(img/menut.jpg) no-repeat;"><a href="index.php?page=formulaire" class="mlink"> Cr&eacute;er un compte </a></td>
								</tr>

								<tr>
									<td height="20" style="background: url(img/menut.jpg) no-repeat;"><a href="" class="mlink"> Comment jouer? </a></td>
								</tr>
					
								<tr>
									<td height="20" style="background: url(img/menut.jpg) no-repeat;"><a href="index.php?page=contact" class="mlink"> Nous contacter</a></td>
								</tr>

								<?php
								if ( isset($_SESSION['co']))
								{
									if ($_SESSION['co'] == 1 )
									{
										echo $test = "<tr><td height=20 style='background: url(img/menut.jpg) no-repeat;'><a href='index.php?page=choix' class='mlink'> Cr&eacute;er un perso </a></td></tr>";
										if (isset($_SESSION['existe']))
										{
											if($_SESSION['existe'] == 1)
											{
												include("finmenu.php");
											}
										}
									}
								}			
								?>
								

							</table>
						</td>
					</tr>
					</table>
				</td>
			</tr>
			
			<tr>
			
				<td valign="top" style="height: 100%; background: #b3ffe3 url(img/menubg3.jpg) repeat-y; background-position: top right; border:0px solid #F00;">&nbsp;</td>
			</tr>
			
			<tr>
				<td height="270" valign="top" style="background-image: url(img/left1b.jpg); background-repeat: no-repeat; background-position: bottom right;">&nbsp;</td>
			</tr>
			
		</table>
	

		<td width="510" style="background: #f7f1e3 url(img/bodytop.jpg) no-repeat; background-position: top; " valign="top" class="normal">
			<div style="padding: 10px; padding-top: 12px;"><center></div>
		
			<table width="484" cellpadding="0" cellspacing="0" class="normal" align="center">
				<tr>
					<td style="background:  url(img/div1.png) no-repeat top; padding-left: 100px; padding-right: 250px; padding-top: 6px;" height="37" align="center" class="caption"><?php if ( (isset($_GET['page']))){echo $mesTitres[$_GET['page']];}else{echo ("Presentation");}?></td>
				</tr>

				<tr>
					<td style="background: #ede0ca url(img/div2.jpg) repeat-y top; padding: 16px;" height="37">
						<div id="survol1">
						<?php 
						$pageOK = array('inscription'=>'inscription.php','accueil'=>'accueil.php','connexion'=>'connexion.php','formulaire'=>'formulaire.php','choix'=>'choix.php','perso'=>'perso.php','races'=>'races.php','histoire'=>'histoire.php','histoire2'=>'histoire2.php','contact'=>'contact.php','remerciement'=>'remerciement.php','mdp'=>'mdp.php');
						if ( (isset($_GET['page'])) && (isset($pageOK[$_GET['page']])) )
						{
							include($pageOK[$_GET['page']]);   // Nous appelons le contenu central de la page
						}
						else
						{
							include('pre.php');   // Page par défaut quant elle n'existe pas dans le tableau
						}
						?>
						</div>
					</td>
				</tr>
				
				<tr>
					<td style="background: #ede0ca url(img/div3.jpg) no-repeat top;" height="21">&nbsp;</td>
				</tr>
			</table>
			<br/>
			<br/>
			<br/>
			<br/>
		</td>
		
		<td width="268" style="height:100%; background: #48a7c0 url(img/banerbarlower.jpg) repeat-y; background-position: left; border: lime 0px solid;" valign="top">
		
			<table class="normal" cellpadding="0" cellspacing="0" border="0" style="width:100%; height: 100%; background-image: url(img/banerbarlower.jpg); background-repeat: repeat-y; background-position: top left; border:0px solid #00F;">
			<tr>
				<td valign="top">
					<table width="100%" height="409" align="center" class="normal" valign="top" cellpadding="0" cellspacing="0" border="0" style="background: #1c3a39 url(img/right1b.jpg) no-repeat; background-position: bottom;">
					<tr>
						<td valign="top" height="203" style="background: #1c3a39 url(img/banerbar1.jpg) no-repeat; background-position: top left; padding-left: 30px; padding-top: 45px;"><!--<a href="vote.php"><img src="img/banner_start.jpg" border="0"></a>--></td>
					</tr>
					<tr>	
						<td height="203" valign="top" class="status" style="background: #1c3a39 url(img/banerbar2.jpg) no-repeat; background-position: top left; padding-left: 30px; padding-top: 34px;"><p align="center"><br>
							<strong><span class="Style3"><u>STATISTIQUES</u> :</span><br/><br/>
							<span>Comptes cr&eacute;&eacute;s : </span><span class="Style1"><?php echo $i_nbLigne;?></span><br/>
							<span>En Ligne : </span><span class="Style1"><?php echo $donnees['nbre_entrees'];?></span><br/></strong>
				
					    </td>
					</tr>
					<tr>
						<td valign="top" height="203" style="background: #1c3a39 url(img/banerbar3.jpg) no-repeat; background-position: top left;" class="status">
						</td>
					</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td style="height: 100%; border:0px solid #F00;">&nbsp;</td>
			</tr>
			<tr>
				<td valign="top" style="height: 270px; background: #48a7c0 url(img/right1b.jpg) no-repeat; background-position: left bottom; ">&nbsp;</td>
			</tr>
			</table>
		</td>
		
		<td height="421" style="background: #48a7c0 url(img/right2.jpg) no-repeat; background-position: top left;">
		
			<table width="100%" height="100%" align="center" class="normal" valign="top" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td height="100%" style="background: url(img/right3.jpg) no-repeat; background-position: bottom left;">&nbsp;</td>
				</tr>
			</table>
		</td>
		
	</tr>
	
	<tr>
	<td height="274" colspan="2" style="background: #b3ffe3 url(img/foot1.jpg) no-repeat; background-position: top right;">&nbsp;  </td>
	<td height="274" width="510" style="background: #48a7c0 url(img/foot2.jpg) no-repeat; background-position: top center;" class="footer"><div style="padding: 50px; padding-left: 250px; "><br><br><br><br>
	<br/>
	<td height="274" colspan="2" style="background: #48a7c0 url(img/foot3.jpg) no-repeat; background-position: top left;">&nbsp;  </td>
	</tr>

</table>

</body>

</html>
Modifié en dernier par magic9110 le 24 déc. 2010, 19:49, modifié 1 fois.

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

17 déc. 2010, 01:07

b'soir,

hum ajoute un var_dump($_SESSION); juste après le session_start() histoire de voir ce que ça donne.

sinon a tu une variable qui se nomme $co dans l'un des scripts appelés ?

enlève les entêtes htmls des scripts inclus ça met un merdier monstre dans le source :)

la balise du formulaire de déconnexion n'est pas fermée.

@+
Il en faut peu pour être heureux ......

devlop78
Invité n'ayant pas de compte PHPfrance

17 déc. 2010, 01:20

Le code est très dense et les responsabilités non séparés. Pourrais-tu mettre juste le code pour l'identification. je me demande si tu ne repasses pas par une vérification des champs du formulaire d'identification une fois identifié.

Eléphant du PHP | 209 Messages

17 déc. 2010, 08:00

[HS] C'est toi qui as fait l'illustration ?
--
Eric

Petit nouveau ! | 4 Messages

17 déc. 2010, 11:24

je viens de rajouter var_dump($_SESSION) et rien ne change...

Quand je parlais de 'co' je parlais de $_SESSION['co']

Le code pour l'identification:
<?php
	

		mysql_connect("sql.free.fr", "******", "*****");
		mysql_select_db("magic9110");
		

	

	$retour = mysql_query('SELECT * FROM table_users WHERE pseudo = \'' . $_POST['identifiant'] . '\'');

	$poss = 0;
	while ($donnees = mysql_fetch_array($retour))
	{
		if( $_POST['mot_de_passe'] == $donnees['pass'] )
		{
				$poss = 1;
				$_SESSION['pseudo'] = $_POST['identifiant'];
				$_SESSION['perso'] = $donnees['perso'];
				$_SESSION['co'] = 1;
				$_SESSION['existe'] = $donnees['creation'];
				$_SESSION['vie'] = $donnees['vie'];
				$_SESSION['vie_max'] = $donnees['vie_max'];
				$_SESSION['mana'] = $donnees ['mana'];
				$_SESSION['mana_max'] = $donnees ['mana_max'];
				$_SESSION['cp'] = $donnees ['cp'];
				$_SESSION['cp_max'] = $donnees ['cp_max'];
				$_SESSION['creation'] = $donnees ['creation'];
				$_SESSION['race'] = $donnees ['race'];
				$_SESSION['sexe'] = $donnees ['sexe'];

				echo "<center>Vous &ecirc;tes connect&eacute;s<br/><br/><a href='index.php'><span class='menu_submit4'>Ok</span></a></center>";
			
				
				
		
		}
	}
	
	if ($poss == 0)
	{
		echo "pseudo ou mot de passe incorrect";
	}
?>

Avatar du membre
Modérateur PHPfrance
Modérateur PHPfrance | 8758 Messages

17 déc. 2010, 23:04

s'il y a auto déclaration des variables $co peut être aussi $_SESSION['co'] ou $_GET['co'] ou $_POST['co'] ou $_COOKIE['co'] suivant l'ordre de variables_order qui par défaut est GPCS (get, post, cookie, session).

Ceci est une source d'erreur genante c'est pour cela que le register globals c'ets mieux a off.

ensuite cela peut venir tu code qui test la connexion, peut être y a t 'il une boulette dans le test !


@+
Il en faut peu pour être heureux ......

Petit nouveau ! | 4 Messages

19 déc. 2010, 20:07

Merci de vos réponses mais j'ai toujours le même problème je vais essayer de simplifier mes pages au maximum.

Petit nouveau ! | 4 Messages

24 déc. 2010, 19:48

Le problème est résolu après deux semaines à galérer dessus...

En fait, il y avait un conflit entre deux formulaires d'une même page (celui pour se déconnecter et celui de la création d'un personnage) et il me traiter le formulaire de creation comme si je voulais me déconnecter...

Je ne comprends toujours pas pourquoi cela pose problème enfin bon les mystères du html sont des fois impénétrables...

Je remercie tout le monde pour l'aide qu'ils m'ont apporter.

Bon réveillon et bon noël à tous !!!