Jump to content
php.lv forumi

nesanāk ielogoties


ziedinjsh

Recommended Posts

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 by ziedinjsh
Link to comment
Share on other sites

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 by ziedinjsh
Link to comment
Share on other sites

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 by ziedinjsh
Link to comment
Share on other sites

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>";
}

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...