Jump to content
php.lv forumi

Php+mysql


FT3

Recommended Posts

Labdien.

Krč ir tada lieta uzkodeju kodu bet ir viena problema kad ienak caur login systemu rada tik pirma lietotaja datus ka lai izlabot ?

<?php
include("db_connect.php");

$query = "SELECT * FROM members";

$result = mysql_query($query) or die(mysql_error());


$row = mysql_fetch_array($result) or die(mysql_error());
echo "Username:";
echo $row['username'];
echo "<br />";
echo "Your password:";
echo $row['password'];
echo "<br />";
echo "Your E-mail:";
echo $row['email'];
echo "<br />";
echo "Your name:";
echo $row['name'];

?>
<br>
[<a href="logout.php">Logout</a>]

 

 

Ierriekš paldies ;]]

Link to comment
Share on other sites

<?php
include("db_connect.php");

$query = "SELECT * FROM members";

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
echo "Username:";
echo $row['username'];
echo "<br />";
echo "Your password:";
echo $row['password'];
echo "<br />";
echo "Your E-mail:";
echo $row['email'];
echo "<br />";
echo "Your name:";
echo $row['name'];
}
?>
<br>
[<a href="logout.php">Logout</a>]

Link to comment
Share on other sites

zinatnieks , nepareiz taja ko tu iedevi kodu rada visus userus, bet man vjg lai raditu tikai ta ar ko tu ienaici :/

bet ir viens variants kuru man iedeva "daviskrex"

$_SESSION['user_id'] = $row['id'];

$id = $_SESSION['user_id'];
SELECT * FROM users WHERE id=$id

bet es viņu nevaru savienot ar savu kodu ;/

Edited by FT3
Link to comment
Share on other sites

Nu pēc pirmā posta es tā arī sapratu, ka tu gribi lai rāda visus, ja jau selectē visus.

 

Tādā ga'dijumā kāpēc tev ir

$query = "SELECT * FROM members";

 

Nav nekādas nepieciešamības selectēt visus lietotājus.. Kad logojas iekšā sistēmā, pēc veiksmīgas autorizācijas iemet $_SESSION['user_id'] = $row['id'], kur $row['id'] satur konkrētā lietotāja id.

 

Tālāk jau tu varēsi to $_SESSION izmantot lai selectētu tikai tā lietotāja datus kurš ir ielogojies, respektīvi:

 

$query = "SELECT * FROM members WHERE id=".$_SESSION['user_id']."";

 

Link to comment
Share on other sites

mans checklogin.php fails

<?php
include("db_connect.php");

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:index_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

 

mans user_info.php fails

<?php
include("db_connect.php");

$query = "SELECT * FROM members WHERE id=".$_SESSION['member_id']."";

$result = mysql_query($query) or die(mysql_error());


$row = mysql_fetch_array($result) or die(mysql_error());
echo "Username:";
echo $row['username'];
echo "<br />";
echo "Your password:";
echo $row['password'];
echo "<br />";
echo "Your E-mail:";
echo $row['email'];
echo "<br />";
echo "Your name:";
echo $row['name'];

?>
<br>
[<a href="logout.php">Logout</a>]

un ka lai tos kodus apvieno ;/

Link to comment
Share on other sites

<?
include("db_connect.php");
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title></title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id=border>
<div id=content>
<div id=logo></div>
<div id=navigation>
<ul>
<li><a href="index_success.php">Главная</a></li>
<li><a href="index_success.php">Информация</a></li>
<li><a href="index_success.php">Файловы Архив</a></li>
</ul>
</div>
<div id=line> </div>

<div id=page>
   <td class="row1" align="left" width="100%">
     <font size="2px">
<?php include("allusers.php"); ?>
     <span class="gensmall">
<div class="hrr">
</div><div style="background-color: #888;"><font size="1px">
</div>
</font>
:D
     </span>
   </td>
 </tr>
<BR /></div>

<div id=panel-l>

<style>
.img_border {
  padding:1px;
  border:1px solid #021a40;
  background-color:#fffff;
 } 

 table.center {margin-left:auto; margin-right:auto;}

</style>
<table class='center' border='0' cellspacing='0' cellpadding='0'>
<h2>Сервер</h2>
:D
</table> 
<h2>ПУСТО</h2>
:D
</div>

<div id=panel-r>
<h2>Вход | Инфо</h2>
<?php include("user_info.php"); ?>
       <br>
<h2>Чят</h2>
:D
<br>
<h2>Статистика</h2>
:D
</div>
</div>
</div>
<br>
<center>
<img src="http://www.lighttpd.net/images/xcache.png" />  <img src="http://www.lighttpd.net/php_power.png" />
<br>
:D
</center>
<br>
</body>
</html>

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