ziedinjsh Posted October 17, 2009 Report Share Posted October 17, 2009 (edited) Sveiki! Šāds ir reģistrēšanas kods: <?php include "misc/config.php"; $submit = $_POST['register']; //Savāc datus $username = strip_tags($_POST['username']); $email = strip_tags($_POST['email']); $password = strip_tags($_POST['password']); $password2 = strip_tags($_POST['password2']); $date = date("y-m-d"); if ($submit) { //Paarbauda vai nav tuksh if($username&&$email&&$password&&$password2) { if($password==$password2) { //parbaudiis useranme un email garumu if(strlen($username)>50||strlen($email)>50) { echo "Lenght of username or/and email is too long!"; } else { //paarbauda password garumu if (strlen($password)>20||strlen($password)<6) { echo "Password must be between 6 and 20 characters!"; } else { //Registreet lietotaaju // nokodee password ar md5 $password = md5($password); $password2 = md5($password); $query = mysql_query("INSERT INTO users VALUES ('','$username','$email','$password','$date') "); die("You hav been registred!"); } } } else echo "Your password do not match!"; } else echo "Please fill all feilds!"; } /// echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>"; echo "<table>"; echo "<tr>"; echo "<td>username</td><td><input type='text' name='username' value='$username'></td>"; echo "</tr><tr>"; echo "<td>email</td><td><input type='email' name='email' value='$email'></td>"; echo "</tr><tr>"; echo "<td>password</td><td><input type='password' name='password'></td>"; echo "</tr><tr>"; echo "<td>password2</td><td><input type='password' name='password2'></td>"; echo "</tr><tr>"; echo "<td></td><td><input type='submit' name='register' value='register'></td>"; echo "</tr>"; echo "</table>"; echo "</form>"; ?> Kods strādā.. datus ievada iekš mysql.. izvadot datus viss parādās.. Es nevaru ielogotes!! šāds ir ielogošanās kods: <?php session_start(); include "misc/config.php"; $status = (isset($_GET['status'])) ? $_GET['status'] : ''; if(isset($_POST['login'])){ $email = strip_tags($_POST['email']); $password = strip_tags($_POST['password']); $query = sprintf("SELECT ID FROM users WHERE email = '$email' AND password = '$password' LIMIT 1;", mysql_real_escape_string($email), md5($password)); $result = mysql_query($query) or die(mysql_error); if(mysql_num_rows($result) != 1){ header('Location: login.php?status=error'); }else{ $row = mysql_fetch_assoc($result); $_SESSION['user_ID'] = $row['ID']; header('Location: login.php?status=done'); } } if ($status == 'error'){ echo "<span style='color:#ff0000'>bad login</span>"; } echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>"; echo "<table><tr>"; echo "<td>email</td><td><input type='text' name='email'></td>"; echo "</tr><tr>"; echo "<td>password</td><td><input type='password' name='password'></td>"; echo "</tr><tr>"; echo "<td></td><td><input type='submit' name='login' value='Login'>"; echo "</tr></table>"; if($status == 'done'){ echo "Welcome to member eare"; } ?> Kas man nav pareizi? vai kāds lūdzu nevarētu izlabot vai pielabot? Edited October 17, 2009 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
anonīms Posted October 17, 2009 Report Share Posted October 17, 2009 labi būtu zināt arī kādu kļūdu izmet, ne? Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 17, 2009 Author Report Share Posted October 17, 2009 (edited) meoģinot ielogoties izmet error ziņu Bad login Edited October 17, 2009 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted October 17, 2009 Report Share Posted October 17, 2009 Šī rindiņa nedarbojas kā iecerēts: $query = sprintf("SELECT ID FROM users WHERE email = '$email' AND password = '$password' LIMIT 1;", mysql_real_escape_string($email), md5($password)); izlasi par sprintf() un kā tai padod parametrus... Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 18, 2009 Author Report Share Posted October 18, 2009 tad sanāk ka šai rindiņai ir jāizskatās šadi? $query = sprintf("SELECT ID FROM users WHERE email = '$email' '%s' AND password = '$password' '%s' LIMIT 1;", mysql_real_escape_string($email), md5($password)); Quote Link to comment Share on other sites More sharing options...
waplet Posted October 18, 2009 Report Share Posted October 18, 2009 neē $query = sprintf("SELECT ID FROM users WHERE email = '%s' AND password = '%s' LIMIT 1;", mysql_real_escape_string($email), md5($password)); šādi Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 18, 2009 Author Report Share Posted October 18, 2009 (edited) Paldies waplet, aizgāja, bet kā tagad, lai es izdaru tā: ielogojoties man aizmet uz lapu profiles.. tur parādās visi reģistrētie profili, bet kas man jādara lau parādītos tikai tas profils kurā es ielogojos un darbības notiktu tikai ar to profilu.. nu kā lietotājam kurš ir ielogojies? profiles.php: <?php include "misc/config.php"; $result = mysql_query("SELECT * FROM users ORDER BY id DESC"); while($data = mysql_fetch_array($result)) { echo "<table><tr>"; echo "<td>username</td><td>".$data['username']."</td>"; echo "</tr><tr>"; echo "<td>email</td><td>".$data['email']."</td>"; echo "</tr></table>"; echo "".$data['id'].""; echo "<hr>"; } ?> kā varētru izveidot kko šādu: if (member) { echo "te rādās viskautkas tike prekš reģistrētiem"; } else { echo "viesiem"; } //viesiem if (guest){ echo "kkas viesiem tikai, ko neredz reģistreeti"; } Edited October 18, 2009 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
waplet Posted October 18, 2009 Report Share Posted October 18, 2009 Tev uz sesijām vai uz kūkijiem? vai ka? Quote Link to comment Share on other sites More sharing options...
mickys Posted October 18, 2009 Report Share Posted October 18, 2009 SELECT * FROM users ORDER BY id DESC šis izvelk visus lietotājus no DB, bet tev tač vajag tikai to kurš esi tu? Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 18, 2009 Author Report Share Posted October 18, 2009 man uz sesijām.. kas tad man ir jāmaina šajā? SELECT * FROM users ORDER BY id DESC Quote Link to comment Share on other sites More sharing options...
waplet Posted October 18, 2009 Report Share Posted October 18, 2009 SELECT * FROM users WHERE username(vai hz kā username tabula saucas) = '{$_SESSION['usernamesesijasnosaukums']}' Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 18, 2009 Author Report Share Posted October 18, 2009 (edited) login.php <?php session_start(); include "misc/config.php"; $status = (isset($_GET['status'])) ? $_GET['status'] : ''; if(isset($_POST['login'])){ $email = strip_tags($_POST['email']); $password = strip_tags($_POST['password']); $query = sprintf("SELECT ID FROM users WHERE email = '%s' AND password = '%s' LIMIT 1;", mysql_real_escape_string($email), md5($password)); $result = mysql_query($query) or die(mysql_error); if(mysql_num_rows($result) != 1){ header('Location: login.php?status=error'); }else{ $row = mysql_fetch_assoc($result); $_SESSION['user_ID'] = $row['ID']; header('Location: profile.php'); } } if ($status == 'error'){ echo "<span style='color:#ff0000'>bad login</span>"; } echo "<form method='post' action='".$_SERVER['PHP_SELF']."'>"; echo "<table><tr>"; echo "<td>email</td><td><input type='text' name='email'></td>"; echo "</tr><tr>"; echo "<td>password</td><td><input type='password' name='password'></td>"; echo "</tr><tr>"; echo "<td></td><td><input type='submit' name='login' value='Login'>"; echo "</tr></table>"; ?> tātad sanāk ka vajadzētu izskatīties šadi: $_SESSION['user_ID'] jo iekš login.php ir šādi: $_SESSION['user_ID'] = $row['ID']; Šādi man izskatās profiles.php: <?php include "misc/config.php"; $result = mysql_query("SELECT * FROM users WHERE username= '{$_SESSION['user_ID']}'"); while($data = mysql_fetch_array($result)) { echo "<table><tr>"; echo "<td>username</td><td>".$data['username']."</td>"; echo "</tr><tr>"; echo "<td>email</td><td>".$data['email']."</td>"; echo "</tr></table>"; echo "".$data['id'].""; echo "<hr>"; } ?> ielogojoties man parādās tukša lapa Edited October 18, 2009 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
waplet Posted October 18, 2009 Report Share Posted October 18, 2009 ne ne ne... tev ir vispār tāda tabula username? kr4 tev vajag darīt tā $result = mysql_query("SELECT * FROM users WHERE ID = '{$_SESSION['user_ID']}'"); while($data = mysql_fetch_array($result)) { echo "<table><tr>"; echo "<td>username</td><td>".$data['username']."</td>"; echo "</tr><tr>"; echo "<td>email</td><td>".$data['email']."</td>"; echo "</tr></table>"; echo "".$data['id'].""; echo "<hr>"; } Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 18, 2009 Author Report Share Posted October 18, 2009 jā, man ir username tabula.. iekš user man ir username, email. password, date Quote Link to comment Share on other sites More sharing options...
waplet Posted October 18, 2009 Report Share Posted October 18, 2009 Aizgāja mans variants? 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.