我希望你们能帮助我。我有一个php文件名login.php,在这个页面有一个提交名字和密码的表单,然后有checklogin.php连接到bd并检查用户是否存在。
问题是,当我输入有关用户的信息然后提交时,什么也没有发生。它停留在同一页面上(login.php)。
这是 login.php 中的代码:
<link rel="stylesheet" type="text/css" href="StyleSheet.css" />
</head>
<style type="text/css">
#Button1
{
width: 120px;
}
#Button2
{
width: 120px;
}
</style>
<body onload="display_ct(),display_ct2();">
<form id="form1" runat="server">
<div id="wrap">
<div id="header">
<div id="Div1">
<div class="row dropdown-container fixed">
<div class="col-220">
<a id="logo" title="Back Home" href="index.htm">
<img width="220" alt="logo" src="Images/logo.jpg"/>
</a>
</div>
<div class="col-701 last">
<p> </p>
<p class="get-in-touch">
<img width="14" height="10" alt="" src="Images/flagpt.jpg"/>
<strong>
<script type="text/javascript">
function display_c() {
var refresh = 1000; // Refresh rate in milli seconds
mytime = setTimeout('display_ct()', refresh)
}
function display_ct() {
var strcount
var x = new Date()
var horas = x.getHours();
var min = x.getMinutes();
var sec = x.getSeconds();
if (horas < 10) {
horas = "0" + horas;
}
if (min < 10) {
min = "0" + min;
}
if (sec < 10) {
sec = "0" + sec;
}
document.getElementById('ct').innerHTML = horas + ":" + min + ":" + sec + " ";
tt = display_c();
}
</script> <span id='ct' ></span>
</strong>
<img width="14" height="10" alt="" src="Images/flagiraque.jpg"/>
<strong>
<script type="text/javascript">
function display_c2() {
var refresh = 1000; // Refresh rate in milli seconds
mytime2 = setTimeout('display_ct2()', refresh)
}
function display_ct2() {
var strcount
var x = new Date()
var horas1 = x.getHours() + 2;
var min1 = x.getMinutes();
var sec1 = x.getSeconds();
if (horas1 < 10) {
horas1 = "0" + horas1;
}
if (horas1 > 24) {
horas1 = "0" + (horas1 - 24);
}
if (min1 < 10) {
min1 = "0" + min1;
}
if (sec1 < 10) {
sec1 = "0" + sec1;
}
document.getElementById('ct2').innerHTML = horas1 + ":" + min1 + ":" + sec1 + " ";
tt1 = display_c2();
}
</script> <span id='ct2' ></span>
</strong>
</p>
<p class="text-right">غرفة التجارة و الصناعة البرتغالية العراقية</p>
<p class="text-right1">Câmara do Comércio e Indústria Portugal-Iraque</p>
<p class="text-right">ژووری بازرگانی عیراق پۆرتگال</p>
</div>
<ul id="nav">
<li><a href="index.htm"><center>Inicio <br /> بداية </center> </a></li>
<li onmouseover=""><center><a href="about2.htm">About Us</a></center> <center> حول الغرفة </center>
<ul class="nav first">
<li><a href="MsgPresidente.htm"><center>Palavra do Presidente</center> <center> كلمة الرئيس </center></a> </li>
<li><a href="DirectionBoard.htm"><center> Direcção</center> <center> كلمة الرئيس </center></a> </li>
<li><a href="ConsultiveBoard.htm"><center>Conselho Superior</center> <center>المجلس الاستشاري </center></a></li>
<li><a href="GeneralAssembly.htm"><center>Assembleia Geral</center> <center>الجمعية العامة</center></a></li>
<li><a href="FinancialCouncil.htm"><center>Conselho Fiscal</center> <center>الهيئة المالية </center></a></li>
<li><a href="FoundingMembers.htm"><center>Membros Fundadores</center> <center> العضاء المؤسسين </center></a></li>
</ul>
</li>
<li><a href="Links.htm"><center>Links</center> <center> روابط</center></a></li>
<li><a href="Protocolos.htm"><center>Protocolos</center> <center> مذكرات تفاهم </center> </a></li>
<li onmouseover=""><center><a href="news2.htm">Noticias/Fotos/Videos</a></center> <center> اخبار و صور </center>
<ul class="nav first">
<li><a href="news2.htm"><center>Noticias</center> <center> اخبار </center> </a></li>
<li><a href="photo1.htm"><center>Fotos</center> <center> صور </center></a> </li>
<li><a href="videos.htm"><center>Videos</center> <center> افلام </center></a> </li>
</ul>
</li>
<li onmouseover=""><center><a href="associados2.htm">Associados</a></center> <center> اعضاء </center>
<ul class="nav first">
<li><a href="HowToJoin.htm"><center>Como entrar</center> <center>كيفية الاشتراك </center></a> </li>
<li><a href="ListOfMembers.htm"><center>Lista de Membros</center> <center> قائمة الاعضاء </center></a> </li>
</ul>
</li>
<li><a href="Contacts.htm"><center>Contactos</center> <center>اتصل بنا </center></a> </li>
</ul>
</div>
</div>
</div>
<div id="content">
<div class="hr">
</div>
<div class="row fixed">
<div class="col-220">
<ul id="news-box">
<p></p>
</ul>
</div>
<div class="col-460 ">
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
<div class="row fixed">
<div class="col-220">
<p >
<img width="130" height="70" alt="emb" src="Images/smartcom.jpg"/><br>
<strong>
© 2012
<a href="http://www.smartcom.pt">Smartcom,
<br/></a>Intelligent Communications
</strong>
</p>
<p >
All rights reserved.
<br/>
</p>
</div>
<div class="col-460 ">
</div>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
检查登录.php:
<?php
//ob_start();
//session_start();
if(isset($_POST['submit']))
{
$host="localhost"; // Host name
$username="ccili_userccili"; // Mysql username
$password="lKUJZhn[{w#e"; // Mysql password
$db_name="ccili_BD"; // Database name
$tbl_name="User"; // Table name
// Connect to server and select databse.
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'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
//$sql="SELECT * FROM $tbl_name WHERE LOGINNAME='$myusername' and LOGINPASS='$mypassword'";
$result=mysql_query("SELECT * FROM $tbl_name WHERE LOGINNAME='$myusername' and LOGINPASS='$mypassword'");
// 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.htm"
session_register("myusername");
session_register("mypassword");
header("Location: login_sucess.php");
//header("Location: http://ccili.org/login_sucess.php");
die();
}
else {
echo "Wrong Username or Password";
}
}
//ob_end_flush();
?>