hello I would like to read an excel file and insert its contents in the database given in my web
<form class="form-analyste" method="POST" action="{{ path('Importer_dark_cell')}}" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="2097152000000">
Fichier : <input type="file" name="avatar">
<li class="li">
<input type="submit" name="envoyer" value="Envoyer le fichier">
</li>
</ul>
</h5>
`
web but I when I click send I'll always File not found!
© e import stopped. I tried to find on the internet but I found the same answer that can help me please I'm stuck in this point: (I can not move on before setting (
public function importer_dark_cellAction(){
$session =$this->get('request')->getSession() ;
$user_name = $session->get('user_name');
$fichier=$_FILES["avatar"]["name"];
/* On ouvre le fichier à importer en lecture seulement */
if (file_exists($fichier))
$fp = fopen("$fichier", "r");
else
{ /* le fichier n'existe pas */
echo "Fichier introuvable !<br>Importation stoppée.";
exit();
} $host = "172.25.5.227";
$user = "stgzouaoui";
$password = "stg";
$bdd = "stg_zouaoui_dev";
mysql_connect($host, $user, $password) or die ("impossible de se connecter au serveur" );
mysql_select_db($bdd) or die ("impossible de se connecter a la base de donnees" );
while (!feof($fp)) /* Et Hop on importe */
{ /* Tant qu'on n'atteint pas la fin du fichier */
$ligne = fgets($fp,4096); /* On lit une ligne */
/* On récupère les champs séparés par ; dans liste*/
$liste = explode( ";",$ligne);
/* On assigne les variables */
$Nom_cell = $liste[0];
$cmts = $liste[1];
/* Ajouter un nouvel enregistrement dans la table */
$query = "INSERT INTO dark_cell VALUES('$Nom_cell','$cmts')";
$result= MYSQL_QUERY($query);
if(mysql_error())
{ /* Erreur dans la base de donnees, surement la table qu'il faut créer */
print "Erreur dans la base de données : ".mysql_error();
print "<br>Importation stoppée.";
exit();
}
else /* Tout va bien */
print "$Nom_cell $cmts <br>";
}
echo "<br>Importation terminée, avec succès.";
/* Fermeture */
fclose($fp);
MYSQL_CLOSE();
break;
Please edit in your code
$fichier=$_FILES["avatar"]["tmp_name"];
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 days ago.
Improve this question
here is my issue.
I made a login page with a variable that counts the number of attempts. This variable increments itself each time the user credentials are wrong.
I use this variable to disable the account if the user tries more than 5 times. Everything works but, if the user goes back to the previous page, he goes back to the last submit and the variable is decremented. With this issue, he can have unlimited attempts if he goes back everytime to the last page.
Can you help me please?
Here is my code.
<?php
// Le nombre de tentatives est placé dans le formulaire en renvoyé en post
if(isset($_POST['failurecount'])) {
$failcount = $_POST['failurecount'];
} else {
$failcount = 1;
}
if(isset($_POST['login_email']) && isset($_POST['mdp'])) {
$login_email = $_POST['login_email'];
$mdp = $_POST['mdp'];
$result = $wpdb->get_results("SELECT login, email, mdp FROM `wp_clients_user` WHERE (`login` = '$login_email' OR `email` = '$login_email') AND actif = 1", ARRAY_A);
if($wpdb->last_error) {
echo 'wpdb error: ' . $wpdb->last_error;
}
if($failcount < 5) {
if(empty($result)) {
$failure = "Erreur, le nom d'utilisateur ou le mot de passe est incorrect, vérifiez les données saisies! Nombre de tentatives : ". $failcount;
$failcount++;
} else {
foreach($result as $row) {
if(password_verify($mdp, $row['mdp'])) {
$_SESSION['login'] = $row['login'];
} else {
$failure = "Erreur, le mot de passe est incorrect, veuillez vérifier le mot de passe saisi! Nombre de tentatives : " . $failcount;
$failcount++;
}
}
}
} else {
// On ne bloque que si le nombre de tentatives est = 5 car sinon, il bloquera tous les comptes qe l'utilisateur entrera après avoir été bloqué
if ($failcount == 5) {
// Si l'utilisateur s'est trompé trop de fois
$failure = "Erreur! Votre compte a été bloqué suite à un trop grand nombre d'échecs!";
$wpdb->query("UPDATE wp_clients_user SET actif = 0 WHERE `login` = '$login_email' OR `email` = '$login_email'", ARRAY_A);
blocked_account($login_email);
$failcount++;
} else { // Si l'utilisateur continue d'essayer de se connecter, on ne fait plus rien (pas de connexion ou de bloquge)
$failure = "Toutes vos prochaines tentatives de connexion ne seront pas prises en compte! Nombre de tentatives : " . $failcount;
$failcount++;
}
?>
<form id="login_form" method="post" onsubmit="return false">
<input type="hidden" name="failurecount" value="<?php if(isset($failcount)){echo $failcount;}else{echo 1;} ?>">
<input id="login_email" name="login_email" type="text" value="<?php echo $login_email; ?>" placeholder="Nom d'utilisateur ou adresse e-mail *">
<input id="mdp" name="mdp" type="password" value="<?php echo $mdp; ?>" placeholder="Mot de passe *">
<p>Mot de passe oublié?</p>
<div>
<input id="showpwd" type="checkbox" onclick="show_password()"><label for="showpwd">Afficher le mot de passe</label>
</div>
<?php
if($failure !== false) {
echo('<p style="color: red;">'.htmlentities($failure)."</p>\n");
}
?>
<div>
<input id="souvenir" type="checkbox"><label for="souvenir">Se souvenir de moi</label>
</div>
<button class="bouton_submit" id="user_send_login" style="background-color:#3498db; color:white; width:100px; height:35px;" onclick="verif_login_form()">Se connecter</button>
</form>
I'm getting troubles with my sign/login phpsystem. I use password_verify() and password_hash() with PASSWORD_BCRYPT option.
I'm probably going wrong in my system.
All that I want is to be able to connect to the member space with a first name, last name and password.
Here is my SQL Table COMPTE
id
nom
prenom
motDePasse
email
telephone
typeUtilisateur
cleMDP
1
uno
test
12345678
1#m.c
012345678
1
$2Ydzn
Here is my php code for my signing system
<?php
/* Connexion à la base de données et gestion des erreurs */
try{
$dbc = new PDO("mysql:host=ckdhjqodomiform.mysql.db;dbname=ckdhjqodomiform;charset=UTF8", "ckdhjqodomiform", "D0miform01");
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Échec lors de la connexion : ' . $e->getMessage();
}
/* Déclaration des variables pour la création du compte dans la table COMPTE de la base de données*/
$id += 1;
$nom = $_GET['nom'];
$prenom = $_GET['prenom'];
$motDePasse = $_GET['mdp'];
if(!empty($_GET['email'])) {
$email = $_GET['email'];
} else {
$email = "NULL";
}
$telephone = $_GET['tel'];
switch ($_GET['typeCompte']) {
case "S":
$typeUtilisateur = '1';
break;
case "P":
$typeUtilisateur = '2';
break;
case "E":
$typeUtilisateur = '3';
break;
}
$cryptMDP = password_hash($motDePasse, PASSWORD_BCRYPT);
/* Préparation de la requête pour éviter les injections SQL dans la base de données via les champs de textes des formulaire*/
$requete = $dbc->prepare("INSERT INTO COMPTE(id, nom, prenom, motDePasse, email, telephone, typeUtilisateur, cleMDP) VALUES (:id, :nom, :prenom, :motDePasse, :email, :telephone, :typeUtilisateur, :cleMDP)");
$requete->bindParam(':id', $id);
$requete->bindParam(':nom', $nom);
$requete->bindParam('prenom', $prenom);
$requete->bindParam('motDePasse', $motDePasse);
$requete->bindParam('email', $email);
$requete->bindParam('telephone', $telephone);
$requete->bindParam('typeUtilisateur', $typeUtilisateur);
$requete->bindParam('cleMDP', $cryptMDP);
/*Execution du code et creation du compte dans la table COMPTE */
$requete->execute();
?>
And my php code for the logging system
<?php
/* Connexion à la base de données et gestion des erreurs */
try{
$dbc = new PDO("mysql:host=ckdhjqodomiform.mysql.db;dbname=ckdhjqodomiform;charset=UTF8", "ckdhjqodomiform", "D0miform01");
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Échec lors de la connexion : '.$e->getMessage();
}
$sql = "SELECT nom, prenom FROM COMPTE";
$user = $dbc->query($sql);
$username = $user->fetch();
$motDePasse = $_GET['motDePasse'];
$cryptMDP = $dbc->query("SELECT cleMDP FROM COMPTE WHERE nom=".$username['nom']." AND prenom=".$username['prenom']);
$data = $cryptMDP->fetch();
if (password_verify($motDePasse, $data['cleMDP']) == true) {
$loginMessage = "Connexion réussie";
} else {
$loginMessage = "Connexion impossible. Vérifiez vos informations";
}
?>
If you can help/show me how to fix my problem, I'd thank you.
(Sorry for my english)
EDIT:
I'll show my form and my logging system.
loginForm.php
<div class="formulaire">
<form action="./loginCheck.php" method="GET">
<h3>Connectez-vous</h3>
<div class="ligne">
<div class="col25">
<label for="email"><i class="fas fa-at"></i> Adresse email</label>
</div>
<div class="col75">
<input type="text" id="email" name="email" placeholder="ex: monadressemail#mail.com">
</div>
</div>
<div class="ligne">
<div class="col25">
<label for="motDePasse"><i class="fas fa-unlock-alt"></i> Mot de Passe</label>
</div>
<div class="col75">
<input type="password" id="mdp" name="mdp" placeholder="ex: motdepasse123">
</div>
</div>
<div class="ligne">
<div class="col25">
<label for="remember" style="font-size: 80%"><i class="fas fa-user-check"></i> Se souvenir de moi</label>
</div>
<div class="col75">
<label class="switch">
<input type="checkbox"><span class="slider"></span>
</label>
</div>
<div class="ligne">
<button class="valider" type="submit" formaction="./loginCheck.php" formmethod="post"><i class="fas fa-sign-in-alt"></i> Se connecter</button>
</div>
</div>
</form>
<div style="font-size: 50%">Pas encore de compte ? Inscrivez-vous</div>
</div>
loginCheck.php
<?php
/* Connexion à la base de données et gestion des erreurs */
try{
$dbc = new PDO("mysql:host=ckdhjqodomiform.mysql.db;dbname=ckdhjqodomiform;charset=UTF8", "ckdhjqodomiform", "D0miform01");
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Échec lors de la connexion : '.$e->getMessage();
}
$requete = $dbc->prepare("SELECT cleMDP FROM COMPTE WHERE email = :email");
$requete->bindParam(':email', $_POST['email']);
$requete->execute();
$ligne = $requete->fetch(PDO::FETCH_ASSOC);
$cryptMDP = $ligne['cleMDP'];
if (password_verify($_POST['motDePasse'], $cryptMDP) == true) {
$loginMessage = "Connexion réussie";
} else {
$loginMessage = "Connexion impossible. Vérifiez vos informations";
}
?>
Okay so i have this form that is supposed to fill multiple tables but when i click on the send button, the page just refreshes, and when i check phpmyadmin the tables are empty.
i have a code that is supposed to tell me if the data got succesfully registered in the database, but i cant get it to work either, it doesn't show up at all, not even to tell me the registration was not succesful.
I've been struggling with this code for 3 days, im pretty new to coding but i tried every change i could an i still can't get it to work.
Here's the code:
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Registro empleado</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css">
</head>
<body>
<form>
<h1>Ingresar Datos</h1>
<h3>Cliente</h3>
<input type="number" name="id_cliente" placeholder="id_local"><!--ingreso del id-->
<input type="text" name="nombre" placeholder="nombre"><!--ingreso del nombre del cliente-->
<input type="text" name="domicilio" placeholder="domicilio"><!--ingreso del domicilio-->
<input type="text" name="telefono" placeholder="telefono"><!--ingreso del numero de telefono-->
<input type="text" name="edad" placeholder="edad"><!--ingreso de la edad del cliente-->
<h3>Ganancias</h3>
<input type="number" name="id_ganancias" placeholder="id_ganancias"><!--ingreso del id-->
<input type="number" name="diarios1" placeholder="diarios"><!--ingreso de ganancias diarias-->
<input type="number" name="mensuales1" placeholder="mensuales"><!--ingreso de ganancias mensuales-->
<input type="number" name="anuales1" placeholder="anuales"><!--ingreso de ganancias anuales-->
<h3>Gastos</h3>
<input type="number" name="id_gastos" placeholder="id_gastos"><!--ingreso del id-->
<input type="number" name="diarios2" placeholder="diarios"><!--ingreso de gastos diarios-->
<input type="number" name="mensuales2" placeholder="mensuales"><!--ingreso de gastos mensuales-->
<input type="number" name="anuales2" placeholder="anuales"><!--ingreso de gastos anuales-->
<input type="submit" name="enviar"><!--botton de enviar-->
</form>
<form action="http://localhost/consulta_cliente.php"><!--link para phpadmin-->
<input type="submit" value="consulta_cliente"><!--boton que te lleva phpadmin-->
<form action="http://localhost/consulta_ganancias.php"><!--link para phpadmin-->
<input type="submit" value="consulta_ganancias"><!--boton que te lleva phpadmin-->
<form action="http://localhost/consulta_gastos.php"><!--link para phpadmin-->
<input type="submit" value="consulta_gastos"><!--boton que te lleva phpadmin-->
</form>
<?php
include("registrar_empleado.php");/*Llamado a el archivo php de registro*/
?>
</body>
</html>
PHP:
<?php
//Llamada a código de conexión
include("conexion_empleado.php");
//validación de variables que recibirán cada campo de la tabla
//cliente
if (isset($_POST['enviar'])) {
if (strlen($_POST['id_cliente']) >=1 && strlen($_POST['nombre']) >= 1 && strlen($_POST['domicilio']) >= 1 && strlen($_POST['edad']) >= 1 && strlen($_POST['telefono']) >= 1) {
$id_cliente = trim($_POST['id_cliente']);
$nombre = trim($_POST['nombre']);
$domicilio = trim($_POST['domicilio']);
$telefono = trim($_POST['telefono']);
$edad = trim($_POST['edad']);
//inserción de registros en la tabla datos
$consulta1 = "INSERT INTO cliente(id_cliente, nombre, domicilio, telefono, edad) VALUES ('$id_cliente', '$nombre', '$domicilio', '$edad', '$telefono')";
$resultado1 = mysqli_query($conecta,$consulta1);
//ganancias
if (strlen($_POST['id_ganancias']) >=1 && strlen($_POST['diarios1']) >= 1 && strlen($_POST['mensuales1']) >= 1 && strlen($_POST['anuales1']) >= 1) {
$id_ganancias = trim($_POST['id_ganancias']);
$diarios1 = trim($_POST['diarios1']);
$mensuales1 = trim($_POST['mensuales1']);
$anuales1 = trim($_POST['anuales1']);
$consulta2 = "INSERT INTO ganancias(id_ganancias, diarios, mensuales, anuales) VALUES ('$id_ganancias', '$diarios1', '$mensuales1', '$anuales1')";
$resultado2 = mysqli_query($conecta,$consulta2);
//gastos
if (strlen($_POST['id_gastos']) >=1 && strlen($_POST['diarios2']) >= 1 && strlen($_POST['mensuales2']) >= 1 && strlen($_POST['anuales2']) >= 1) {
$id_gastos = trim($_POST['id_gastos']);
$diarios2 = trim($_POST['diarios2']);
$mensuales2 = trim($_POST['mensuales2']);
$anuales2 = trim($_POST['anuales2']);
$consulta3 = "INSERT INTO gastos(id_gastos, diarios, mensuales, anuales) VALUES ('$id_gastos', '$diarios2', '$mensuales2', '$anuales2')";
$resultado3 = mysqli_query($conecta,$consulta3);
if ($resultado1 && $resultado2 && $resultado3) {
?>
<h3 class="completo">Registro exitoso</h3>
<?php
} else {
?>
<h3 class="incompleto">Error de registro</h3>
<?php
}
} else {
?>
<h3 class="incompleto">Por favor completa el registro</h3>
<?php
}
}
}
}
?>
PHP code to connect to the database:
<?php
//código para asignar las variables para la conexión: localhost = nombre servido, usuario = root, nombre_BD = registro
$conecta = mysqli_connect("localhost","root","","locales");
?>
I have some code to show the last rows that were filled by the form, i can't test if it works yet since i can't get data to even get send to the database, anyways here it is just it case:
Query1:
<?php
include("conexion_cliente.php");//Llamado a el documento php
$consulta1_1 = "select * from pago";//se muestra la tabla pago
$resultado1_1 = mysqli_query($conecta,$consulta1_1);
$cuenta = mysqli_num_rows ($resultado);
$cuenta = $cuenta - 1;
$resultado1 = mysqli_query($conecta, "SELECT * FROM cliente LIMIT $cuenta, 1"); //consulta de tabla empleando
//limit para obtener solo una fila
echo "<h1>ULTIMO CAMPO</h1>"; //titulo
echo "<pre>"; //atributo pre para poder realizar el salto de línea
while($row1 = mysqli_fetch_array($resultado1)) { //se obtienen los arrays de la consulta
echo print_r($row1); //se imprimen los resultados de la consulta
echo "\n"; //salto de linea
}
echo "</pre>";
?>
Query2:
<?php
include("conexion_cliente.php");//Llamado a el documento php
$consulta2_1 = "select * from pago";//se muestra la tabla pago
$resultado2_1 = mysqli_query($conecta,$consulta2_1);
$cuenta = mysqli_num_rows ($resultado);
$cuenta = $cuenta - 1;
$resultado2 = mysqli_query($conecta, "SELECT * FROM ganancias LIMIT $cuenta, 1"); //consulta de tabla empleando
//limit para obtener solo una fila
echo "<h1>ULTIMO CAMPO</h1>"; //titulo
echo "<pre>"; //atributo pre para poder realizar el salto de línea
while($row2 = mysqli_fetch_array($resultado2)) { //se obtienen los arrays de la consulta
echo print_r($row2); //se imprimen los resultados de la consulta
echo "\n"; //salto de linea
}
echo "</pre>";
?>
Query3:
<?php
include("conexion_cliente.php");//Llamado a el documento php
$consulta3_1 = "select * from gastos";//se muestra la tabla gastos
$resultado3_1 = mysqli_query($conecta,$consulta3_1);
$cuenta = mysqli_num_rows ($resultado);
$cuenta = $cuenta - 1;
$resultado3 = mysqli_query($conecta, "SELECT * FROM gastos LIMIT $cuenta, 1"); //consulta de tabla empleando
//limit para obtener solo una fila
echo "<h1>ULTIMO CAMPO</h1>"; //titulo
echo "<pre>"; //atributo pre para poder realizar el salto de línea
while($row3 = mysqli_fetch_array($resultado3)) { //se obtienen los arrays de la consulta
echo print_r($row3); //se imprimen los resultados de la consulta
echo "\n"; //salto de linea
}
echo "</pre>";
?>
Sorry it's written in spanish, im from mexico but i noticed that this "us" page was more active than the "es" one. Any help it's greatly appreciated and if you have any language related question i'll be glad to answer.
I have his index.php code:
<?php
session_start();
session_destroy();
?>
<!DOCTYPE html>
<html lang="es">
<meta charset="utf-8">
<head>
<title>Login</title>
<link rel="stylesheet" type="text/css" href="css/estilos.css">
</head>
<body>
<center>
<div class="caja_login">
<form method="POST" action="validar.php">
<label>Nombre de usuario:</label><input type="text" name="nombre" placeholder="Usuario" required/><br><br>
<label>Contraseña:</label><input type="password" name="contraseña" placeholder="Contraseña" required /><br><br>
<input type="submit" value="Entrar" class="enviar" placeholder="Entrar"/><br>
</form>
</div>
<div class ="caja_registro">
<form method="POST">
<label>¿Aún no estás registrado?</label><br>
<label>Nombre de usuario:</label><input type="text" name="nombrerg" placeholder="Nombre de usuario" required><br>
<label>Contraseña:</label><input type="password" name="contrarg" placeholder="Contraseña" required>
<input type="submit" name="registro" value="Crear Cuenta"><br>
</form>
</div>
<h1><?php include("conexion.php");?></h1>
</center>
<?php//para el registro
include("conexion.php");
if(isset($_POST['registro'])){
$sql = 'SELECT FROM cuenta';
$rec = mysqli_query($conexion, $sql);
$verificar =0;
while ($resultado = mysql_fetch_array($rec)) {
if ($resultado->nombre == _POST['nombrerg']) {//verificamos que el nombre de usuario no existe
$verificar = 1;//si verificar es 1 es que el usuario esta repetido
}
}
if ($verificar == 0) {//si varificar es 0 entonces el nombre no esta repetido
$nom = _POST['nombrerg'];
$pw = _POST['contrarg'];
$conexion->query("INSERT INTO cuenta (usuario, contraseña) VALUES ('$nom','$pw')";
mysqli_query($conexion, $sql);
echo 'Te has registrado con exito';
}else{
echo "El nombre de usuario ya existe!";
}
}
?>
</body>
</html>
When I go to the page, it shows everything right, but below everything it shows the PHP code, and when I click the button "registro" it doesn't insert the data into the DB.
The page's is a simple login and register, but as I said the register button (registro) isn't working.
EDIT:
This is what is showing in the bottom of the page:
nombre == _POST['nombrerg']) {//verificamos que el nombre de usuario no existe $verificar = 1;//si verificar es 1 es que el usuario esta repetido } } if ($verificar == 0) {//si varificar es 0 entonces el nombre no esta repetido $nom = _POST['nombrerg']; $pw = _POST['contrarg']; $conexion->query("INSERT INTO cuenta (usuario, contraseña) VALUES ('$nom','$pw')"; mysqli_query($conexion, $sql); echo 'Te has registrado con exito'; }else{ echo "El nombre de usuario ya existe!"; } } ?>
It's due to your code-formatting.
Change this:
<?php//para el registro
To:
<?php //para el registro
And this:
$conexion->query("INSERT INTO cuenta (usuario, contraseña) VALUES ('$nom','$pw')";
To:
$conexion->query("INSERT INTO cuenta (usuario, contraseña) VALUES ('$nom','$pw')");
The last one you're missing and ending ) after the last "
For the other ones, having the //-comment without space from the start-tag <?php prevents it from being interpreted correctly.
As a side-note, you have two includes right after eachother, for the same file, one of them inside a <h1> for no reason.
Also, your code is horribly prone to SQL injection attacks.
On the code below, I put a line break to separate where the PHP started from your comment, after that, I notied you were using both mysqli and mysql functions and changed to mysqli only and insert $ where it was missing in $_POST. Your last query had a column named contraseña, do not use especial characters in column names, I've changed it to contrasena.
<?php
//para el registro
include("conexion.php");
if(isset($_POST['registro'])){
$sql = 'SELECT FROM cuenta';
$rec = mysqli_query($conexion, $sql);
$verificar =0;
while ($resultado = mysqli_fetch_array($rec)) {
if ($resultado->nombre == $_POST['nombrerg']) {//verificamos que el nombre de usuario no existe
$verificar = 1;//si verificar es 1 es que el usuario esta repetido
}
}
if ($verificar == 0) {//si varificar es 0 entonces el nombre no esta repetido
$nom = $_POST['nombrerg'];
$pw = $_POST['contrarg'];
$conexion->query("INSERT INTO cuenta (usuario, contrasena) VALUES ('$nom','$pw') )";
mysqli_query($conexion, $sql);
echo 'Te has registrado con exito';
}else{
echo "El nombre de usuario ya existe!";
}
}
?>
</body>
</html>
<?php//para el registro is probably causing problems. Change it to <?php //para el registro (notice the space)
If the rest of the php renders, then it's unlikely a server issue.
Also, the variable for post is $_POST not _POST
Just to reiterate. Please don't store passwords in clear text. Here's a good article explaining why. For more questions related to that, feel free to checkout other StackExchange sites like security
I do a form in html for a little website, i want users to subscribe themselves but my PHP control seems to not work and i don't know why!
My javascript control works but PHP doesn't...
Source:
<!-- HTML -->
<form action="InscriptionSucces.html" method="POST" name="Inscription" onSubmit="return verif(this);">
<h2>Identifiants</h2>
<ul>
<li>Pseudo* : <input type="text" name="pseudo" id="pseudo" size="30" /></li>
<li>Mot de passe* : <input type="password" name="pass" id="pass" size="30" /></li>
<li>Veuillez retaper votre mot de passe* : <input type="password" name="pass2" id="pass2" size="30" /></li>
<li>Adresse mail (valide)* : <input type="text" name="mail" id="mail" size="30" value="" />#
<select name="groupe1" id="groupe1">
<option value="0">Selectionnez votre adresse...</option>
<optgroup label="">
<option value="1">hotmail.fr
<option value="2">hotmail.com
<option value="3">gmail.com
<option value="4">laposte.net
</optgroup>
</select>
</li>
<li>Veuillez retaper votre adresse mail* : <input type="text" name="mail_verif" id="mail_verif" size="30" value="" />#
<select name="groupe2" id="groupe2">
<option value="0">Selectionnez votre adresse...</option>
<optgroup label="">
<option value="1">hotmail.fr
<option value="2">hotmail.com
<option value="3">gmail.com
<option value="4">laposte.net
</optgroup>
</select>
</li>
<li>Date de naissance : <input type="text" name="date_naissance" id="date_naissance" size="30" value="" /> <em>(JJ/MM/AAAA)</em></li>
<h5>Les champs signales par * sont obligatoires.</h5>
<li>
<td id="envoyer">
<input type="submit" name="Submit" value="M'inscrire">
</td>
<td id="effacer">
<input type="reset" name="Effacer" >
</td>
</td>
</li>
</form>
Here is my javascript which works:
<script type="text/javascript">
function verif(f)
{
var regnm = /^[a-zàâäéèêëîïôöùûüç0123456789]+((( |-)[a-zàâäéèêëîïôöùûüç]+$)|$)/i;
var regmail = /^[a-z]/i;
if(!regnm.test(f.pseudo.value)) {
alert("Erreur dans la saisie de votre pseudo");
return false;
}
if(!regnm.test(f.pass.value)) {
alert("Erreur dans la saisie de votre mot de passe");
return false;
}
if(f.pass.value != f.pass2.value){
alert("Les mots de passe sont differents");
return false;
}
if(!regmail.test(f.mail.value)){
alert("adresse mail incorrecte");
return false;
}
if(f.mail.value != f.mail_verif.value){
alert("adresses mail differentes");
return false;
}
if (document.getElementById('groupe1').options[0].selected){
alert("Vous avez oublie de mentionner votre adresse mail");
return false;
}
if (document.getElementById('groupe1').value != document.getElementById('groupe2').value){
alert("adresses mail differentes");
return false;
}
return confirm("Vous confirmez l'envoi des donnees?");
}
</script>
PHP Code:
<?php
if(!empty($_POST)) {
$errors = array();
$pseudo=$_POST['pseudo'];
echo $pseudo; // Pseudo
if(!isset($pseudo)){
$errors[] = 'Erreur dans la saisie de votre pseudo';
return false;
} elseif($pseudo == '') {
$errors[] = 'Erreur dans la saisie de votre pseudo';
return false;
}
// Mot de passe
if(!isset($_POST['pass'])){
$errors[] = 'Erreur dans la saisie de votre mot de passe';
} elseif($_POST['pass'] == ''){
$errors[] = 'Erreur dans la saisie de votre mot de passe';
}
// Verif mot de passe
if($_POST['pass2'] =! $_POST['pass']){
$errors[] = 'Les mots de passe sont differents';
} elseif($_POST['mdp_verif'] == ''){
$errors[] = 'Les mots de passe sont differents';
} else if(!isset($_POST['mdp_verif'])){
$errors[] = 'Les mots de passe sont differents';
}
// Adresse mail
if(!isset($_POST['mail'])){
$errors[] = 'Erreur dans la saisie de votre adresse mail';
} elseif($_POST['mail'] == ''){
$errors[] = 'Erreur dans la saisie de votre adresse mail';
}
// Verif adresse mail
if($_POST['mail_verif'] != $_POST['mail']){
$errors[] = 'Les adresses mail sont differentes';
} elseif($_POST['mail_verif'] == ''){
$errors[] = 'Les adresses mail sont differentes';
} else if(!isset($_POST['mail_verif'])){
$errors[] = 'Les adresses mail sont differentes';
}
// Compte les erreurs
if(count($errors) > 0)
{
echo '<ul>' . PHP_EOL;
for($i=0; $i < count($errors); $i++)
echo '<li>'. $errors[$i] .'.</li>' . PHP_EOL;
echo '<ul>';
}
}
?>
Is it an error in my variables?
with $_POST ?
Thx to help :)
I do this and it works fine. Here i give my edited code for your convenience.
<html>
<head>
<title>form</title>
</head>
<body>
<form action="" method="POST" name="Inscription" onSubmit="return verif(this);">
<h2>Identifiants</h2>
<ul>
<li>Pseudo* : <input type="text" name="pseudo" id="pseudo" size="30" /></li>
<li>Mot de passe* : <input type="password" name="pass" id="pass" size="30" /></li>
<li>Veuillez retaper votre mot de passe* : <input type="password" name="pass2" id="pass2" size="30" /></li>
<li>Adresse mail (valide)* : <input type="text" name="mail" id="mail" size="30" value="" />#
<select name="groupe1" id="groupe1">
<option value="0">Selectionnez votre adresse...
<optgroup label="">
<option value="1">hotmail.fr
<option value="2">hotmail.com
<option value="3">gmail.com
<option value="4">laposte.net
</optgroup>
</select>
</li>
<li>Veuillez retaper votre adresse mail* : <input type="text" name="mail_verif" id="mail_verif" size="30" value="" />#
<select name="groupe2" id="groupe2">
<option value="0">Selectionnez votre adresse...
<optgroup label="">
<option value="1">hotmail.fr
<option value="2">hotmail.com
<option value="3">gmail.com
<option value="4">laposte.net
</optgroup>
</select>
</li>
<li>Date de naissance : <input type="text" name="date_naissance" id="date_naissance" size="30" value="" /> <em>(JJ/MM/AAAA)</em></li>
<h5>Les champs signales par * sont obligatoires.</h5>
<li><td id="envoyer">
<input type="submit" name="Submit" value="M'inscrire">
</td>
<td id="effacer">
<input type="reset" name="Effacer" >
</td>
</td></li>
</form>
</body>
<!-- Here is my javascript which works
<script type="text/javascript">
function verif(f)
{
var regnm = /^[a-zàâäéèêëîïôöùûüç0123456789]+((( |-)[a-zàâäéèêëîïôöùûüç]+$)|$)/i;
var regmail = /^[a-z]/i;
if(!regnm.test(f.pseudo.value))
{
alert("Erreur dans la saisie de votre pseudo");
return false;
}
if(!regnm.test(f.pass.value))
{
alert("Erreur dans la saisie de votre mot de passe");
return false;
}
if(f.pass.value != f.pass2.value){
alert("Les mots de passe sont differents");
return false;
}
if(!regmail.test(f.mail.value)){
alert("adresse mail incorrecte");
return false;
}
if(f.mail.value != f.mail_verif.value){
alert("adresses mail differentes");
return false;
}
if (document.getElementById('groupe1').options[0].selected){
alert("Vous avez oublie de mentionner votre adresse mail");
return false;
}
if (document.getElementById('groupe1').value != document.getElementById('groupe2').value){
alert("adresses mail differentes");
return false;
}
return confirm("Vous confirmez l'envoi des donnees?");
}
</script>
-->
<?php if(!empty($_POST))
{
echo '<pre>';
print_r($_POST);
echo '</pre>';
$errors = array();
$pseudo=$_POST['pseudo'];
echo $pseudo;
if(!isset($pseudo)){
$errors[] = 'Erreur dans la saisie de votre pseudo';
return false;
}
elseif($pseudo == ''){
$errors[] = 'Erreur dans la saisie de votre pseudo';
return false;
}
if(!isset($_POST['pass'])){
$errors[] = 'Erreur dans la saisie de votre mot de passe';
}
elseif($_POST['pass'] == ''){
$errors[] = 'Erreur dans la saisie de votre mot de passe';
}
// Verif mot de passe
if($_POST['pass2'] =! $_POST['pass']){
$errors[] = 'Les mots de passe sont differents';
}
elseif($_POST['mdp_verif'] == ''){
$errors[] = 'Les mots de passe sont differents';
}
else if(!isset($_POST['mdp_verif'])){
$errors[] = 'Les mots de passe sont differents';
}
if(!isset($_POST['mail'])){
$errors[] = 'Erreur dans la saisie de votre adresse mail';
}
elseif($_POST['mail'] == ''){
$errors[] = 'Erreur dans la saisie de votre adresse mail';
}
// Verif adresse mail
if($_POST['mail_verif'] != $_POST['mail']){
$errors[] = 'Les adresses mail sont differentes';
}
elseif($_POST['mail_verif'] == ''){
$errors[] = 'Les adresses mail sont differentes';
}
else if(!isset($_POST['mail_verif'])){
$errors[] = 'Les adresses mail sont differentes';
}
// Compte les erreurs
if(count($errors) > 0)
{
echo '<ul>' . PHP_EOL;
for($i=0; $i < count($errors); $i++)
echo '<li>'. $errors[$i] .'.</li>' . PHP_EOL;
echo '<ul>';
}
}
?>
First: PHP code must be enclosed with <?php .. ?> tags.
Second: seems that file you posted here is *.html file. It either needs to be *.php file or have the webserver configured to parse html files as .php
In the form tag you use InscriptionSucces.html. Instead, you must use the name InscriptionSucces.php, and your filename must be InscriptionSucces.php.
When you use any PHP code, you must use the correct start and end syntax: <?php and ?>.