Page 1 sur 1

Problème écriture base de donnée

Posté : 28 janv. 2015, 20:56
par iibeast
Bonjour, je suis débutant en php, et j'ai voulu tester d'intégrer un système d'inscription à mon site en local.
Lors de l'envoi du formulaire, rien ne se passe ni sur la page, ni au niveau de la base de donnée. Je viens de passer en MySqli mais le problème était le même en MySql.

Si quelqu'un peut m'aider à trouver d'où cela peut venir ..
<?php
session_start();
include_once 'config.php';
?><!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 charset="utf-8" />
        <link rel="stylesheet" href="register.css" />
        <!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <title>Iibeast54 on Crystal</title>
        <style type="text/css">
		input[type=text]{
			border:dotted 1px orange;
		}
		
		textarea{
			border:dotted 1px orange;
			width:880px;
			height:200px;
		}
		
		input[type=submit]{
			font-size:20px;
			color:orange;
			width:120px;
			border:solid 1px orange;
			border-radius:5px;
			background:rgba(0, 0, 0, 0);
		}
		input[type=submit]:hover{
			cursor:pointer;
		}
		.error-message{
			font-style:italic;
			color:red;
		}
		</style>
    </head>
    
    <!--[if IE 6 ]><body class="ie6 old_ie"><![endif]-->
    <!--[if IE 7 ]><body class="ie7 old_ie"><![endif]-->
    <!--[if IE 8 ]><body class="ie8"><![endif]-->
    <!--[if IE 9 ]><body class="ie9"><![endif]-->
    <!--[if !IE]><!--><body><!--<![endif]-->
	<header>
		<div id="main_title">
			<h1><a href="index.php" title="Index">####</a></h1>
			<h2><a href="#" title="#####" target="_blank"><strong>#####</strong></a></h2>
		</div>
	</header>

	<nav>
		<ul>
			<li><a href="#" title="">#</a></li>
			<li><a href="#" title="">#</a></li>
			<li><a href="#" title="">#</a></li>
			<li><a href="#" title="">#</a></li>
			<li><a href="#" title="">#</a></li>
			<li><a href="#" title="">#</a></li>
			<li><a href="#" title="">#</a></li>
			<li><a href="#" title="">#</a></li>
		</ul>
	</nav>
    
    <center><div id="block_principal">
    Welcome to the register page. You will be able to register here by following this form.
    </div></center>
    <div id="block_intro">
    <form method="POST" action="register.php">
    <label for="username">Username :</label> <br />
	<input type="text" name="username" id="username" /> <br />
    
    <label for="pass1">Password :</label> <br />
	<input type="text" name="password" id="password" /> <br />

	<label for="pass2">Repeat it :</label> <br />
	<input type="text" name="repeatpassword" id="repeatpassword" /> <br />
    
    <center><input type="submit" value="Register" /> <br />
    </center>
    </form>
    <?php
	    if(isset($_POST['submit'])) // Création des variable suite à l'appui sur le bouton.
	    {
	    	$username = htmlentities(trim($_POST['username'])); // Sécurisation des variables.
	    	$password = htmlentities(trim($_POST['password'])); // 
	    	$repeatpassword = htmlentities(trim($_POST['repeatpassword'])); // 

	    	if($username&&$password&&$repeatpassword) // Vérification des longueurs appropriées.
	    	{
	    		$login = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM users WHERE username='$username'");
	    		$rows = mysqli_num_rows($login);
	    		if($rows == 0)
	    		{

		    		if(strlen($username) > 4)
		    		{
		    			if(strlen($password) > 4)
		    			{
		    				if($password == $repeatpassword)
		    				{
		    					$password = md5($password);
		    					$req = "INSERT INTO users(login,pass) VALUES('','$username','$password')";
		    					$exec = mysqli_query($GLOBALS["___mysqli_ston"], $req);
		    					echo "Successfully registered.";
		    					header('Location:index.php');

		    				}else echo "Same passwords please.";
		    			}else echo "Password length too low.";
		    		}else echo "Username length too low.";
		    	}else echo "Username already used.";
	    	}else echo "Anything is missing.";
	    }
	?>
    </div>
</body>
</html>
Et voici mon code de la config appelée dans la page ...
<?php
$connexion = ($GLOBALS["___mysqli_ston"] = mysqli_connect('localhost',  'root',  ''));
((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE test"));
((is_null($___mysqli_res = mysqli_close($connexion))) ? false : $___mysqli_res);
?>
En vous remerciant par avance,

iibeast

Re: Problème écriture base de donnée

Posté : 28 janv. 2015, 21:00
par Incognito
Bonjour,
C'est normal que l'action de ton formulaire renvoie vers registre.PHP ?
Cordialement.

Re: Problème écriture base de donnée

Posté : 28 janv. 2015, 21:05
par iibeast
Oui, car c'est sur la même page que je veux que l'utilisateur soit informé que le compte a été créé. D'où le code en dessous du formulaire.

Re: Problème écriture base de donnée

Posté : 28 janv. 2015, 21:09
par Incognito
Dans ce cas tu peux aussi mettre action="#" dans la balise form.

Re: Problème écriture base de donnée

Posté : 28 janv. 2015, 21:14
par Incognito
 if($username&&$password&&$repeatpassword)
cette ligne me gêne un peu ,non ? Tu n'as pas oublié isset ?

Re: Problème écriture base de donnée

Posté : 28 janv. 2015, 21:16
par tof73
if(isset($_POST['submit']))
par
if($_SERVER['REQUEST_METHOD'] == "POST"){

Re: Problème écriture base de donnée

Posté : 28 janv. 2015, 21:19
par Incognito
Non regarde ta ligne de code que j'ai cité

Re: Problème écriture base de donnée

Posté : 28 janv. 2015, 21:24
par iibeast
Inco, si j'ajoute un isset, ca ne fonctionne pas. Et tof, avec ton changement, le formulaire part enfin, mais aucune écriture dans la base, et ces messages :

mysqli_query(): Couldn't fetch mysqli in C:\wamp\www\register.php on line 93

mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\wamp\www\register.php on line 94

mysqli_query(): Couldn't fetch mysqli in C:\wamp\www\register.php on line 106

Cannot modify header information - headers already sent by (output started at C:\wamp\www\register.php:94) in C:\wamp\www\register.php on line 108

Re: Problème écriture base de donnée

Posté : 29 janv. 2015, 19:57
par sirakawa
C'est ta connexion qui ne fonctionne pas correctement
include_once 'config.php';
var_dump($connexion); die(); et renvoie-nous le résultat

Re: Problème écriture base de donnée

Posté : 30 janv. 2015, 02:00
par iibeast
Bonjour,

J'obtiens ca sur page blanche à l'arrivée sur la page de register :

object(mysqli)[1]
public 'affected_rows' => null
public 'client_info' => null
public 'client_version' => null
public 'connect_errno' => null
public 'connect_error' => null
public 'errno' => null
public 'error' => null
public 'error_list' => null
public 'field_count' => null
public 'host_info' => null
public 'info' => null
public 'insert_id' => null
public 'server_info' => null
public 'server_version' => null
public 'stat' => null
public 'sqlstate' => null
public 'protocol_version' => null
public 'thread_id' => null
public 'warning_count' => null

Re: Problème écriture base de donnée

Posté : 30 janv. 2015, 02:44
par iibeast
Problème résolu, j'ai totalement changé de code en m'inspirant des tutos proposés. Mon code n'était ni clair, ni propre. Merci à vous.

Cordialement,

iibeast