PHP Development...LOGIN

PHP Development Enterprise Website Tutorial Modification Contact Us Information

Let’s implement the modification function below

Query the information in the database through id , then display the information in the form, then modify the content of the form, click Modify, and implement the modification function

Let’s take a look at the code:

<?php
    require_once('conn.php');
    $id = $_GET['id'];
    $sql = "SELECT * from contact where id='$id'";
    $res = mysql_query($sql);
    $row = mysql_fetch_array($res);
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改公司信息</title>
    <style type="text/css">
        .ipt{width:180px;height:30px;border-radius:5px;
            outline:none;border:1px solid #eee;box-sizing:border-box;padding-left:15px;}
        .txt{width:250px;height:200px;}
        .sub{width:50px;height:20px;border:1px solid #eee;background:#eee;color:#ff7575;}
    </style>
</head>
<body>
    <form method="post" action="modifyontact.php?id=<?php echo $id;?>">
        公司地址:<input type="text" name="site" class="ipt" value="<?php echo $row['site'];?>">
        </br></br>
        公司电话:<input type="text" name="tel" class="ipt" value="<?php echo $row['tel'];?>">
        </br></br>
        技术支持:<input type="text" name="suppot" class="ipt" value="<?php echo $row['suppot'];?>">
        </br></br>
        售后电话:<input type="text" name="nexttel" class="ipt" value="<?php echo $row['nexttel'];?>">
        </br></br>
        公司传真:<input type="text" name="fax" class="ipt" value="<?php echo $row['fax'];?>">
        </br></br>
        公司主页:<input type="text" name="home" class="ipt" value="<?php echo $row['home'];?>">
        </br></br>
        电子邮件:<input type="text" name="email" class="ipt" value="<?php echo $row['email'];?>">
        </br></br>
        <input type="submit" value="修改" class="sub">
    </form>
</body>
</html>

As shown in the above code, click the modify button to pass the id, receive it on this page, query and display the information in the database based on the id

Modified After the content, the form is submitted to the modifyontact.php page

Let’s look at the code of the following modifyontact.php page:

<?php
    require_once('conn.php');
    $id = $_GET['id'];
    $site    = $_POST['site']; //地址
    $tel     = $_POST['tel'];    //电话
    $suppot  = $_POST['suppot'];//技术支持
    $nexttel = $_POST['nexttel'];//售后电话
    $fax     = $_POST['fax'];        //公司传真
    $home    = $_POST['home'];        //公司首页
    $email   = $_POST['email'];    //电子邮件
    $sql = "UPDATE contact set site='$site',tel='$tel',suppot='$suppot',nexttel='$nexttel',fax='$fax',home='$home',email='$email' where id='$id'";

    // echo $sql;die;
    $res = mysql_query($sql);
    if($res){
        echo "<script>alert('修改公司信息成功');location.href='contact.php'</script>";
    }else{
        echo "<script>alert('修改公司信息失败');history.go(-1);</script>";
    }
?>

Get the form information, then write the updated statement and execute the sql statement Determine whether it is successful. If successful, we will complete the modification and jump to the display page. If the modification fails, we will return to the previous page

Next Section
<?php require_once('conn.php'); $id = $_GET['id']; $sql = "SELECT * from contact where id='$id'"; $res = mysql_query($sql); $row = mysql_fetch_array($res); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>修改公司信息</title> <style type="text/css"> .ipt{width:180px;height:30px;border-radius:5px; outline:none;border:1px solid #eee;box-sizing:border-box;padding-left:15px;} .txt{width:250px;height:200px;} .sub{width:50px;height:20px;border:1px solid #eee;background:#eee;color:#ff7575;} </style> </head> <body> <form method="post" action="modifyontact.php?id=<?php echo $id;?>"> 公司地址:<input type="text" name="site" class="ipt" value="<?php echo $row['site'];?>"> </br></br> 公司电话:<input type="text" name="tel" class="ipt" value="<?php echo $row['tel'];?>"> </br></br> 技术支持:<input type="text" name="suppot" class="ipt" value="<?php echo $row['suppot'];?>"> </br></br> 售后电话:<input type="text" name="nexttel" class="ipt" value="<?php echo $row['nexttel'];?>"> </br></br> 公司传真:<input type="text" name="fax" class="ipt" value="<?php echo $row['fax'];?>"> </br></br> 公司主页:<input type="text" name="home" class="ipt" value="<?php echo $row['home'];?>"> </br></br> 电子邮件:<input type="text" name="email" class="ipt" value="<?php echo $row['email'];?>"> </br></br> <input type="submit" value="修改" class="sub"> </form> </body> </html>
submitReset Code
ChapterCourseware