PDA

View Full Version : مبتدی: کار نکردن کدها



css-man
چهارشنبه 30 شهریور 1390, 23:50 عصر
دوستان یه لطفی بکنن این کد ها رو ببینن اگه میشه بگین چرا هر یوزر و پسوردی وارد میکنم قبول نمیکنه



<?php
$host="localhost";//Host name
$username="root";//mysql username
$password="";//mysql password
$db_name="test";//Data base name
$tbl_name="members";//Table name

//connect to server and select database.
mysql_connect("$host","$username","$password")or die("cannot connect");
mysql_select_db("$db_name")or die ("cannot select DB");
//username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

//to protect 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:login_success.php");
}
else{
echo "wrong username or password";
}
?>





<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="checklogin.php" method="post" name="form1">
<div bgcolor="#ffffff">
<div align="center" >
username:
<input name="myusername" type="text" id="myusername" />
<br>
<br>
password:
<input name="mypassword" type="password" id="mypassword" />
<br>
<br>
<input name="myusername" type="submit" value="Login" />

</div>
</div>


</form>
</body>
</html>






<?php

session_start();
if(!session_is_registered(myusername)){
header("location:main_login.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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
login successful
</body>
</html>





<?php
//put this code in first line of web page
session_start();
session_destroy();
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

</body>
</html>

Arthas1990
پنج شنبه 31 شهریور 1390, 00:09 صبح
$sql="SELECT * FROM $tbl_name WHERE username='".$myusername."'and password='".$mypassword."'";

1- با کوری بالا کار کن
اگه نشد :
2- $myuser.. و $mypass.. رو قبل از کوری die کن ببین درسته یا نه.


در مجموع کدت درسته

nadi_1368
پنج شنبه 31 شهریور 1390, 00:14 صبح
علامت های تک کوتیشن $myusername و $mypassword رو بردار شاید ایراد از این باشه