PHP开发企业网站教程之修改联系我们的信息
下面我们来实现修改的功能
通过 id 查询数据库中的信息,然后把信息在表单中展示,然后修改表单的内容,点击修改,实现修改的功能
下面我们来一下代码:
<?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>如上代码,通过点击修改按钮,把 id 传过来,在本页面接收,根据id 查询并展示数据库中的信息
修改好了内容之后,表单提交到modifyontact.php这个页面
下面我们来看以下modifyontact.php页面的代码:
<?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>";
}
?>获取表单的信息,然后写更新的语句,执行sql语句判断是否成功,如果成功,我们就修改完成,跳转到展示页面,修改失败返回上一页面
neue Datei
<?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>
Vorschau
Clear
- Kursempfehlungen
- Kursunterlagen herunterladen
Die Kursunterlagen stehen derzeit nicht zum Download zur Verfügung. Die Mitarbeiter organisieren es derzeit. Bitte schenken Sie diesem Kurs in Zukunft mehr Aufmerksamkeit
Auch Studierende, die diesen Kurs gesehen haben, lernen
Lassen Sie uns kurz über die Gründung eines Unternehmens in PHP sprechen
Kurze Einführung in die Web-Frontend-Entwicklung
Umfangreiche, praktische Tianlongbabu-Entwicklung eines Mini-Version-MVC-Frameworks, das die Enzyklopädie-Website mit peinlichen Dingen imitiert
Erste Schritte mit der praktischen PHP-Entwicklung: Schnelle PHP-Erstellung [Small Business Forum]
Anmeldebestätigung und klassisches Message Board
Wissenssammlung über Computernetzwerke
Schnellstart-Node.JS-Vollversion
Der Frontend-Kurs, der Sie am besten versteht: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Schreiben Sie Ihr eigenes PHP-MVC-Framework (40 Kapitel ausführlich/große Details/Muss gelesen werden, damit Neulinge vorankommen)
















