我如何使我的表单工作.我是用bootstrap设计的.我不懂php


How do I make my form work. I designed it using bootstrap. I don't know php.

我使用html bootstrap设计了一个联系人表单,但我不知道如何使其工作。我有以下代码。我在网上看到一些使用php获得联系人表单的教程,但我对php没有任何了解。有人能帮我一下吗?如果有人能帮我做作业,我会很感激的。以下是我到目前为止写的

<form method="POST" action="contact-form-submission.php" class="form-horizontal">
<div class="control-group">
    <label class="control-label" for="name">Name</label>
    <div class="controls">
        <input type="text" class="input-medium" id="name">
    </div>
</div>
<div class="control-group">
    <label class="control-label" for="email">Email</label>
    <div class="controls">
        <input type="text" class="input-medium" id="email">
    </div>
</div>
<div class="control-group">
    <label class="control-label" for="website">Website</label>
    <div class="controls">
        <input type="text" class="input-medium" id="website">
    </div>
</div>
<div class="control-group">
    <label class="control-label" for="comment">Comment</label>
    <div class="controls">
        <textarea class="input-medium" id="comment" rows="5"></textarea>
    </div>
</div>
<div class="form-actions">
    <button type="submit" class="btn btn-danger">Submit</button>
    <button type="reset" class="btn">Reset</button>
    <input type="hidden" name="thankyou_url" value="#">
</div>
</form>

使用下面的页面并将其命名为contact.php。创建另一个名为"thank.html"的html。它将在用户提交表单

后显示
<?php
    $from ="xyz@gmail.com";
    if(isset($_POST) && count($_POST)){
        $name = (isset($_POST['name'])) : trim($_POST['name']) : "";
        $email = (isset($_POST['email'])) : trim($_POST['email']) : "";
        $website = (isset($_POST['website'])) : trim($_POST['website']) : "";
        $comment = (isset($_POST['comment'])) : trim($_POST['comment']) : "";
        if(!empty($email)){
            $subject = "new mail";
            $content ="A user has send email<br />
            name: $name<br />
            email: $email<br />
            website: $website<br />
            comment: $comment<br />";
            $headers  = "From: $from'r'n";
            $headers .= "Content-type: text/html'r'n"; 
            mail($email, $subject, $content, $headers); 
            header("location:thanks.html");
        }
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="POST" action="" class="form-horizontal">
  <div class="control-group">
    <label class="control-label" for="name">Name</label>
    <div class="controls">
      <input type="text" class="input-medium" id="name" name="name">
    </div>
  </div>
  <div class="control-group">
    <label class="control-label" for="email">Email</label>
    <div class="controls">
      <input type="text" class="input-medium" id="email" name="email">
    </div>
  </div>
  <div class="control-group">
    <label class="control-label" for="website">Website</label>
    <div class="controls">
      <input type="text" class="input-medium" id="website" name="website">
    </div>
  </div>
  <div class="control-group">
    <label class="control-label" for="comment">Comment</label>
    <div class="controls">
      <textarea class="input-medium" id="comment" name="comment" rows="5"></textarea>
    </div>
  </div>
  <div class="form-actions">
    <button type="submit" class="btn btn-danger">Submit</button>
    <button type="reset" class="btn">Reset</button>
    <input type="hidden" name="thankyou_url" value="">
  </div>
</form>
</body>
</html>

请按照以下步骤操作:

1。在数据库示例Data

中创建一个表
CREATE TABLE IF NOT EXISTS `user_data` (
  `userid` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `email` varchar(255) NOT NULL,
  `comment` varchar(255) NOT NULL,
  `website` varchar(255) NOT NULL,
  PRIMARY KEY (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

2。现在按如下方式修改你的HTML代码:

 <form method="POST" action="contact-form-submission.php" class="form-horizontal">
     <div class="control-group">
       <label class="control-label" for="name">Name</label>
       <div class="controls">
         <input type="text" class="input-medium" id="name" name="name">
       </div>
     </div>
     <div class="control-group">
       <label class="control-label" for="email">Email</label>
       <div class="controls">
         <input type="text" class="input-medium" id="email" name="email">
       </div>
     </div>
     <div class="control-group">
       <label class="control-label" for="website">Website</label>
       <div class="controls">
         <input type="text" class="input-medium" id="website" name="website">
       </div>
     </div>
     <div class="control-group">
       <label class="control-label" for="comment">Comment</label>
       <div class="controls">
         <textarea class="input-medium" id="comment" rows="5" name="comment"></textarea>
       </div>
     </div>
     <div class="form-actions">
       <button type="submit" class="btn btn-danger">Submit</button>
       <button type="reset" class="btn">Reset</button>
       <input type="hidden" name="thankyou_url" value="http://www.sarahmustafa.com/contact.html">
    </div>
 </form>

3。您的contact-form- submit .php如下所示,如果您愿意,可以在其中更改表名:

$dbhost='localhost';//you can change to your host (www.google/fff/fff')
$dbuser='root';//you can change to your Username of DB (ex. root)
$dbpass='';//you can change to your Password (ex. '')
$dbname='Data';//you can change to your Database created on DB   (ex.user_data)

db_connect($dbhost,$dbuser,$dbpass,$dbname);
$name=$_POST["name"];
$email=$_POST["email"];
$website=$_POST["website"];
$comment=$_POST["comment"];
//change the field to actual Databse fields 
$sql="INSERT INTO `user_data` (`name`,`email`,`comment`,`website`) VALUES ('$name','$email','$comment','$website')";
$result=mysql_query($sql);

function db_connect($dbhost,$dbuser,$dbpass,$dbname)
{
    $conn = mysql_pconnect($dbhost,$dbuser,$dbpass);
    if (!$conn)
        return "connect_failed";
    if (!mysql_select_db($dbname))
        return "db_select_failed";
    return "succes";
}