ziedinjsh Posted April 1, 2010 Report Share Posted April 1, 2010 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? Quote Link to comment Share on other sites More sharing options...
kraistaps Posted April 1, 2010 Report Share Posted April 1, 2010 (edited) 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 April 1, 2010 by kraistaps Quote Link to comment Share on other sites More sharing options...
php newbie Posted April 1, 2010 Report Share Posted April 1, 2010 un ja kads no laukiem nav aizpildīts, un ja paroles nesakrīt, tad arī piereģistrē. Tā tas skripts uztaisīts :D pie inserta tak nav nekādas pārbaudes Quote Link to comment Share on other sites More sharing options...
kraistaps Posted April 1, 2010 Report Share Posted April 1, 2010 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>"; ?> Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted April 1, 2010 Author Report Share Posted April 1, 2010 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[]=""; ?? Quote Link to comment Share on other sites More sharing options...
kraistaps Posted April 1, 2010 Report Share Posted April 1, 2010 Vari arī nelikt echo, bet tad lietotājs netiks paziņot par pieļautko kļūdu. Ja vieīgi pašās beigās, kur tiek izvadīts, ka nesanāca piereģistrēties arī tiek izvadīti visi masīva ieraksti. Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted April 1, 2010 Author Report Share Posted April 1, 2010 (edited) 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 April 1, 2010 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
php newbie Posted April 1, 2010 Report Share Posted April 1, 2010 omg Quote Link to comment Share on other sites More sharing options...
kraistaps Posted April 1, 2010 Report Share Posted April 1, 2010 Iekš else operatora izvadi visu masīvu. echo"Nesanaca registreties"; foreach($errors as $kluda) { echo $kluda."<br>"; } Quote Link to comment Share on other sites More sharing options...
Kemito Posted April 1, 2010 Report Share Posted April 1, 2010 Ak kungs! Tu arī pie ārsta saki - Esmu vesels, bet viņš špricēs tev zāles? :D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.