Jump to content
php.lv forumi

registrācija


ziedinjsh

Recommended Posts

kods ir šāds

<?php
include "misc/db.php";

if (isset($_POST['register'])){

session_start();


$username = htmlspecialchars(addslashes($_POST['username']));
$email = htmlspecialchars(addslashes($_POST['email']));
$password = md5($_POST['password']);
$password2 = md5($_POST['password2']);
$location = htmlspecialchars(addslashes($_POST['location']));
$genre = htmlspecialchars(addslashes($_POST['genre']));
$date = date('Y-m-d H:i:s', time());


if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$usercheck = $_POST['email'];
$check = mysql_query("SELECT email FROM users WHERE email = '".$usercheck."'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

if ($check2 != 0) {
echo "Piedod, bet e-pasts ".$_POST['email']." ir jau aiznemts.";
}

if (!$username | !$email | !$password | !$password2 | !$genre | !$location){
echo "Kaads no laukiem nav aizpildiits. ";
}	

if ($_POST['password'] != $_POST['password2']) {
echo "Paroles nesakrit.";
}

$insert = "INSERT INTO users (username, email, password, genre, location, date)
VALUES ('$username', '$email', '$password', '$location', '$genre', '$date')";
$add_member = mysql_query($insert);
echo "Esi registrets!";


}


echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>";
echo "pseidonim:<input type='text' name='username'><br>";
echo "email:<input type='text' name='email'><br>";
echo "password:<input type='password' name='password' id='password'><br>";
echo "repeat password:<input type='password' name='password2' id='password2'><br>";
echo "genre:<input type='text' name='genre'><br>";
echo "location:<input type='text' name='location'><br>";
echo "<input type='submit' name='register' value='register'>";
echo "</form>";

?>

 

Ja ievadu e-pastu kas jau eksistē izmet kļūdu, tā tam ir jābūt, bet lietotājs vienalga tiek piereģistrēts, kapēc ta?

Link to comment
Share on other sites

Tapēc, ka tām rindiņām, kuras veic ieraksut datubāzē, nav piešūts neviens IF.

 

$insert = "INSERT INTO users (username, email, password, genre, location, date)
VALUES ('$username', '$email', '$password', '$location', '$genre', '$date')";
$add_member = mysql_query($insert);
echo "Esi registrets!";

 

Tie daudzie ifi paši par sevi secībā izpildās un aizveras. Un šī koda daļa paliek neatkarīga.

Edited by kraistaps
Link to comment
Share on other sites

Es darītu apmēram šādi.

<?php

if (isset($_POST['register'])){

session_start();
$errors = array(); //izveido kludu masivu

$username = htmlspecialchars(addslashes($_POST['username']));
$email = htmlspecialchars(addslashes($_POST['email']));
$password = md5($_POST['password']);
$password2 = md5($_POST['password2']);
$location = htmlspecialchars(addslashes($_POST['location']));
$genre = htmlspecialchars(addslashes($_POST['genre']));
$date = date('Y-m-d H:i:s', time());


if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$usercheck = $_POST['email'];
$check = mysql_query("SELECT email FROM users WHERE email = '".$usercheck."'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

if ($check2 != 0) {
echo "Piedod, bet e-pasts ".$_POST['email']." ir jau aiznemts.";
$error[]="Epasta kluda"; //aizpilda masivu vienalga ar kadu info, ja kluda
}

if (!$username | !$email | !$password | !$password2 | !$genre | !$location){
       echo "Kaads no laukiem nav aizpildiits. ";
       $error[]="Kads tuks lauks"; //aizpilda masivu vienalga ar kadu info, ja kluda
}

if ($_POST['password'] != $_POST['password2']) {
echo "Paroles nesakrit.";
$error[]="paroles nesakrit"; //aizpilda masivu vienalga ar kadu info, ja kluda
}
if(empty($error)){   // ja masivs ir tuks, tatad nav kludu tad ieraksta datubazē
$insert = "INSERT INTO users (username, email, password, genre, location, date)
VALUES ('$username', '$email', '$password', '$location', '$genre', '$date')";
$add_member = mysql_query($insert);
echo "Esi registrets!";
} else { // ja ir kads ieraksts masivaa, tad izvada kludu
   echo"nesanaca registreties";}

}


echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>";
echo "pseidonim:<input type='text' name='username'><br>";
echo "email:<input type='text' name='email'><br>";
echo "password:<input type='password' name='password' id='password'><br>";
echo "repeat password:<input type='password' name='password2' id='password2'><br>";
echo "genre:<input type='text' name='genre'><br>";
echo "location:<input type='text' name='location'><br>";
echo "<input type='submit' name='register' value='register'>";
echo "</form>";

?>

Link to comment
Share on other sites

tā tas būtu taka skaidrs :) Bet ir vēl viens jautājums.

 

echo "Piedod, bet e-pasts ".$_POST['email']." ir jau aiznemts.";
$error[]="Epasta kluda"; //aizpilda masivu vienalga ar kadu info, ja kluda

 

tas echo ""; nav vajadzīgs, jāatstā tikai $error[]=""; ??

Link to comment
Share on other sites

ahā, ja gribu lai lietotājs ieraug uzreiz savu kļūdu tad es echo atstāju :)

 

paprovēju tagad viss iet.. izmetās errors Piedod, bet e-pasts kkas@kkas.lv ir jau aiznemts.nesanaca registreties

 

Ka varētu uztaisīt šādi: Nesanāca reģistrēties - piedod, bet e-pasts bla bla bla ir aizņemts? :?

Edited by ziedinjsh
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...