PHP开发企业网站教程之添加联系我们的信息
首先我们来看以下添加页面的html 代码:
<!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="addcontact.php">
公司地址:<input type="text" name="site" class="ipt"></br></br>
公司电话:<input type="text" name="tel" class="ipt"></br></br>
技术支持:<input type="text" name="suppot" class="ipt"></br></br>
售后电话:<input type="text" name="nexttel" class="ipt"></br></br>
公司传真:<input type="text" name="fax" class="ipt"></br></br>
公司主页:<input type="text" name="home" class="ipt"></br></br>
电子邮件:<input type="text" name="email" class="ipt"></br></br>
<input type="submit" value="添加" class="sub">
</form>
</body>
</html>看如上代码,表单提交到 addcontact.php 这个文件,该文件接收表单提交的参数,然后根据sql语句添加到数据库
我们来看下 addcontact.php 部分代码:
<?php
//添加联系我们信息部分代码
require_once('conn.php');
$site = $_POST['site']; //地址
$tel = $_POST['tel']; //电话
$suppot = $_POST['suppot'];//技术支持
$nexttel = $_POST['nexttel'];//售后电话
$fax = $_POST['fax']; //公司传真
$home = $_POST['home']; //公司首页
$email = $_POST['email']; //电子邮件
if(empty($site)){
echo "<script>alert('请填写地址');history.go(-1);</script>";
}else if(empty($tel)){
echo "<script>alert('请填写电话');history.go(-1);</script>";
}else if(empty($suppot)){
echo "<script>alert('请填写技术支持');history.go(-1);</script>";
}else if(empty($nexttel)){
echo "<script>alert('请填写售后电话');history.go(-1);</script>";
}else if(empty($fax)){
echo "<script>alert('请填写公司传真');history.go(-1);</script>";
}else if(empty($home)){
echo "<script>alert('请填写公司首页');history.go(-1);</script>";
}else if(empty($email)){
echo "<script>alert('请填写电子邮件');history.go(-1);</script>";
}else{
$sql = "insert into `contact`(site,tel,suppot,nexttel,fax,home,email) values('$site','$tel','$suppot','$nexttel','$fax','$home','$email')";
$res = mysql_query($sql);
if($res){
echo "<script>alert('添加公司信息成功');location.href='contact.php';</script>";
}else{
echo "<script>alert('添加公司信息失败');history.go(-1);</script>";
}
}
?>如上代码,我们给表单的信息做了一个简单的验证,不能为空,当为空点提交了之后,会给出提示信息
neue Datei
<!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="addcontact.php">
公司地址:<input type="text" name="site" class="ipt"></br></br>
公司电话:<input type="text" name="tel" class="ipt"></br></br>
技术支持:<input type="text" name="suppot" class="ipt"></br></br>
售后电话:<input type="text" name="nexttel" class="ipt"></br></br>
公司传真:<input type="text" name="fax" class="ipt"></br></br>
公司主页:<input type="text" name="home" class="ipt"></br></br>
电子邮件:<input type="text" name="email" class="ipt"></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)
















