Conditions dans inscription php

Hacker#1 Messages postés 88 Statut Membre -  
 benj -
Bonjour,
je veux a l'inscription le nom compte s'il existe et le numero s'il ya des chiffres il n y pas d'insertion dans la table
mais ces deux conditions ne marche pas
<html>
<body>
<form action="inscription.php" method="POST">
  <table width="347" height="178" border="0">
    <tr>
      <td height="39">Username </td>
      <td><input type="text" name="user"></td>
    </tr>
    <tr>
      <td height="44">Password </td>
      <td><input type="password" name="pwd"></td>
    </tr>
    <tr>
      <td width="168" height="42"><p>N&deg;carte etudiant 
      </td>
      <td width="169"><input type="text" name="num" ></td>
    </tr>
    <tr>
      <td height="43">Date de naissance </td>
      <td><select name="jour">
        <option></option>
        <script language="javascript">
		for(i=1;i<32;i++)
		document.write("<option value="+i+">"+i+"</option>");
      </script>
      </select>
        <select name="mois">
          <option></option>
          <script language="javascript">
		for(i=1;i<13;i++)
		document.write("<option value="+i+">"+i+"</option>");
        </script>
        </select>
        <select name="annee">
          <option></option>
          <script language="javascript">
		for(i=1900;i<2010;i++)
		document.write("<option value="+i+">"+i+"</option>");
        </script>
        </select></td>
    </tr>
  </table>
  <p><input type="reset" name="Reset" value="annuler" >
    <input type="submit" name="Submit" value="OK" style="width:50px">
</form>
<?php
if(isset($_POST["Submit"]))
{mysql_connect('localhost','root','');
mysql_select_db('compte');
$username=$_POST['user'];
$password=$_POST['pwd'];
$numero=$_POST['num'];
$jour=$_POST["jour"];
$mois=$_POST["mois"];
$annee=$_POST["annee"];
if(!ereg("[0-9]{8}",$numero))  {echo "vous avez inserez des caracteres";}
$sql=mysql_query("select username from  utilisateur");
$data=mysql_fetch_array($sql);
if($data["username"]==$username)
{echo '<script language="javascript">
alert("login existe");
</script>';}
else
{if($username!=""&&$password!=""&&$numero!="")
{$sql="insert into utilisateur values('$username','$password','$numero','$annee-$mois-$jour')";}
mysql_query($sql);
mysql_close();
header("location:index.php");}
}
?>
</body>
</html>

1 réponse

  1. benj
     
    bonsoir,

    si tu étais plus propre dans ton code tu ne rencontrerais surement pas ce genre de problème ,

    le voilà corrigé, les conditions fonctionnes mais il n'est pas comptaible w3c à cause des balises scripts dans le body...

    <!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>
    		<title>TITRE DE LA PAGE</title>
    	</head>
    	<body>
    		<form action="" method="post">
    			<table style="width:347px; height:178px; border:none;">
    				<tr>
    					<td style="height:39px;">Username </td>
    					<td><input type="text" name="user" /></td>
    				</tr>
    				<tr>
    					<td style="height:44px">Password </td>
    					<td><input type="password" name="pwd" /></td>
    				</tr>
    				<tr>
    					<td style="width:168px; height:42px;">N&deg;carte etudiant </td>
    					<td style="width:169px;"><input type="text" name="num" /></td>
    				</tr>
    				<tr>
    					<td style="height:43px;">Date de naissance </td>
    					<td>
    						<select name="jour">
    							<option value=""></option>
    							<script type="text/javascript">
    <!--
    	for(i=1;i<32;i++) document.write("<option value="+i+">"+i+"</option>");
    //-->
    							</script>
    						</select>
    						<select name="mois">
    							<option value=""></option>
    							<script type="text/javascript">
    <!--
    	for(i=1;i<13;i++) document.write("<option value="+i+">"+i+"</option>");
    //-->
    							</script>
    						</select>
    						<select name="annee">
    							<option value=""></option>
    							<script type="text/javascript">
    <!--
    	for(i=1900;i<2010;i++) document.write("<option value="+i+">"+i+"</option>");
    //-->
    							</script>
    						</select>
    					</td>
    				</tr>
    			</table>
    			<p>
    				<input type="reset" name="Reset" value="annuler" />
    				<input type="submit" name="Submit" value="OK" style="width:50px" />
    			</p>
    		</form>
    <?php
    		if(isset($_POST["Submit"])) {
    			
    			$username = $_POST['user'];
    			$password = $_POST['pwd'];
    			$numero = $_POST['num'];
    			$jour = $_POST["jour"];
    			$mois = $_POST["mois"];
    			$annee = $_POST["annee"];
    			if(!ereg("[0-9]{8}",$numero)) echo "<p>vous avez inserez des caracteres</p>";
    			mysql_connect('localhost','root','');
    			mysql_select_db('compte');
    			$sql = mysql_query("select username from  utilisateur");
    			$data = mysql_fetch_array($sql);
    			elseif($data["username"] == $username) echo '<script language="javascript">alert("login existe");</script>';
    			elseif($username != "" && $password != "" && $numero != "") {
    				$sql="insert into utilisateur values('$username','$password','$numero','$annee-$mois-$jour')";
    				mysql_query($sql);
    				mysql_close();
    				header("location:index.php");
    			}
    		}
    ?>
    	</body>
    </html>
    0