单击提交表单按钮时如何在php中包含类文件

时间:2014-01-05 09:29:03

标签: php

我有2页, add.php 页面和主要页面。

单击主页面中添加的按钮后,主页面将成功显示add.php页面。

这是我为主页试过的代码:

    if(isset($_POST['add']))
    {
       include('add.php');
    }

这是我为 edit.php

尝试过的代码
    <html>
    <head>

    <title>EDIT</title>
    </head>
    <body>
    <form  method='POST' action="o.php">


    <input type='text'  name='username' value='<?php

    $textarea1 = ""; 
$pos="";
    if(isset($_SESSION['use'])){
    $textarea1 = $_SESSION['use'];

    }
echo $textarea1;


    ?>'>

    <input type='hidden'  name='fakename' value='<?php

    $textarea1 = ""; 
    if(isset($_SESSION['use'])){
    $textarea1 = $_SESSION['use'];

    }
echo $textarea1;
    ?>'>
    <input type='password' name='passwordz' value='<?php

    $textarea1 = ""; 
    if(isset($_SESSION['pak'])){
    $textarea1 = $_SESSION['pak'];

    }
echo $textarea1;
    ?>' >
    <input type='submit' name='editit' value='edit'>


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

    <?php

    if(!empty($_POST['editit']))
    {
    $truename=$_POST['fakename'];
    $username=$_POST['username'];
    $password=$_POST['passwordz'];
    mysql_connect("localhost", "root", "");
    mysql_select_db("sad");

    $sql = mysql_query("UPDATE  users SET  username =  '$username', password='$password' where username='$truename'");
echo'CONGRATULATIONS YOU HAVE SUCCESFULLY EDIT YOUR ACCOUNT';

}

?>

问题出在此处, add.php 页面中显示 ,但不会执行仅刷新页面的操作并且什么都不做。我做错了什么?

1 个答案:

答案 0 :(得分:1)

<?php 
session_start();


if( isset($_POST['add']) || isset($_SESSION['USE_ADD']) )
{
    $_SESSION['USE_ADD'] = TRUE;
    include('add.php');
}

?>