PHP代码位于顶部,并在其他地方回音

PHP代码位于顶部,并在其他地方回音,php,database,Php,Database,我在页面顶部有以下代码: <?php if(isset($_POST['submit'])) { if(!isset($_SESSION['IS_LOGEDIN'])) { $_SESSION['IS_LOGEDIN'] = 'N'; } // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To pro

我在页面顶部有以下代码:

    <?php
if(isset($_POST['submit']))
{

if(!isset($_SESSION['IS_LOGEDIN']))
{
    $_SESSION['IS_LOGEDIN'] = 'N';
}
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

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

$encrypted_mypassword=md5($mypassword);

$sql="SELECT * FROM administratori WHERE username='$myusername' and password='$encrypted_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['myusername'] = $myusername;
$_SESSION['IS_LOGEDIN'] = 'Y';
//$lastlogin = $_POST['date("d/m/y  H:i:s", time()+25200)'];
header("location:administrare.php");
}
else {
echo '<img src="images/delete.png" width="16" height="16" />' . '&nbsp;' .'User sau Password gresit!';
}
}
?>

只需将测试放在表单中即可:

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['myusername'] = $myusername;
$_SESSION['IS_LOGEDIN'] = 'Y';
//$lastlogin = $_POST['date("d/m/y  H:i:s", time()+25200)'];
header("location:administrare.php"); 
}
else {
echo '<img src="images/delete.png" width="16" height="16" />' . '&nbsp;' .'User sau Password    gresit!';
}
}
if($count==1){
//注册$myusername、$mypassword并重定向到文件“login\u success.php”
$\会话['myusername']=$myusername;
$\会话['IS_LOGEDIN']='Y';
//$lastlogin=$_POST['date(“d/m/y H:i:s”,time()+25200)];
标题(“位置:administrare.php”);
}
否则{
回显“”。“用户sau密码gresit!”;
}
}

只需将其发布到表单区域即可

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['myusername'] = $myusername;
$_SESSION['IS_LOGEDIN'] = 'Y';
//$lastlogin = $_POST['date("d/m/y  H:i:s", time()+25200)'];
header("location:administrare.php");
}
else {
echo '<img src="images/delete.png" width="16" height="16" />' . '&nbsp;' .'User sau Password gresit!';
}
if($count==1){
//注册$myusername、$mypassword并重定向到文件“login\u success.php”
$\会话['myusername']=$myusername;
$\会话['IS_LOGEDIN']='Y';
//$lastlogin=$_POST['date(“d/m/y H:i:s”,time()+25200)];
标题(“位置:administrare.php”);
}
否则{
回显“”。“用户sau密码gresit!”;
}
如果需要,也可以使用jquery 使用下面的php代码

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['myusername'] = $myusername;
$_SESSION['IS_LOGEDIN'] = 'Y';
//$lastlogin = $_POST['date("d/m/y  H:i:s", time()+25200)'];
header("location:administrare.php");
}
else {
echo '<div id="test"><img src="images/delete.png" id="image1" width="16" height="16" /></div>' . '&nbsp;' .'User sau Password gresit!';
}
if($count==1){
//注册$myusername、$mypassword并重定向到文件“login\u success.php”
$\会话['myusername']=$myusername;
$\会话['IS_LOGEDIN']='Y';
//$lastlogin=$_POST['date(“d/m/y H:i:s”,time()+25200)];
标题(“位置:administrare.php”);
}
否则{
回显“”。“用户sau密码gresit!”;
}
将下面的代码用于jquery

<script>
$(document).ready(function(){
var r = $("#test").html();
$("#formid").append(r);
});
</script>

$(文档).ready(函数(){
var r=$(“#test”).html();
$(“#formid”)。追加(r);
});
它很好用,看看这里


希望这对您有所帮助

也是一种选择。ie
,只要在php版本5.3或更低版本的ini\u设置中启用了短打开标记,或者如果php版本为5.4或更高版本,则
条带斜杠(mysql\u real\u escape\u string($myusername))
看起来像是一个错误。也许应该是“mysql\u real\u escape\u string($myusername)`(如果magic\u quotes\u gpc关闭),或者可能是
mysql\u real\u escape\u string(stripslashes($myusername))
(如果magic\u quotes\u gpc打开,这是我强烈反对的)。您也不应该使用
mysql\u
扩展。越早开始使用
mysqli\uuu
PDO
,效果越好(以后需要更改的代码越少)。我强烈建议使用面向对象的方法,在任何生产代码中使用预先准备好的语句,而不是使用
real\u escape\u string
这是从google:php登录教程的第一个发现开始的,时不时会看到它,非常过时。
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['myusername'] = $myusername;
$_SESSION['IS_LOGEDIN'] = 'Y';
//$lastlogin = $_POST['date("d/m/y  H:i:s", time()+25200)'];
header("location:administrare.php");
}
else {
echo '<div id="test"><img src="images/delete.png" id="image1" width="16" height="16" /></div>' . '&nbsp;' .'User sau Password gresit!';
}
<script>
$(document).ready(function(){
var r = $("#test").html();
$("#formid").append(r);
});
</script>