PHP通知我代码?

时间:2014-04-28 08:55:37

标签: php

我创建了一个名为aware的数据库和一个名为email的表,该表在phpmyadmin中有一个名为email的字段。我想在用户输入电子邮件地址后存储该电子邮件地址并点击通知我。这是一个网站即将推出的页面。

如果我连接到数据库,我该怎么做?我需要做什么?

这是我的代码到目前为止,请指导我正确的方向。我不是在找人帮这个。

                     <div id="main">
                 <div class="header"><a href="#"><img src="images/logo.png" alt="" /></a></div>
                <div class="details_holder">
                    <div class="main_content">
                   <div class="common_container">
                        <h2>We know its taking a long time but</h2>
                          <h1>SIT TIGHT!</h1>
                           <div class="notify_me">
                         <div class="text_holder">Fill in your e-mail address and we will  let you know when we launch</div>
                <div class="textbox"><input name="" type="text" value="email" /></div>
                 <div class="btn_holder"><input name="" type="submit" value="Notify me!"         /></div>
                  </div>
                     <div class="follow_me">
                <h3>Follow us on </h3>
                <a href=""><img src="images/ico1.jpg" alt="" /></a> 
                 <a href=""><img src="images/ico2.jpg" alt="" /></a> 
                       </div>
                    <br clear="all" />
                </div>
                  </div>
                </div>
                <div class="footer"><span>A project by <a href="#"></a></span></div>
            </div>
              </body></html>
               <?php 
            $host="xxxxx";
            $dbs="xxxxxxx";
             $username="xxxxxx";
             $password="xxxxxx";
            $con = mysql_connect($host,$username,$password);


             ?>

2 个答案:

答案 0 :(得分:2)

我在msyqli中实现了你的代码。使用它。

只需$sql="INSERT INTO email (email) VALUES ('$email')";完成所有工作。

代码:

 <div id="main">
 <div class="header"><a href="#"><img src="images/logo.png" alt="" /></a></div>
 <div class="details_holder">
 <div class="main_content">
 <div class="common_container">
 <h2>We know its taking a long time but</h2>
 <h1>SIT TIGHT!</h1>
 <div class="notify_me">
 <div class="text_holder">Fill in your e-mail address and we will  let you know when we launch</div>
 <div class="textbox"><input name="" type="text" value="email" /></div>
 <div class="btn_holder"><input name="" type="submit" value="Notify me!"/></div>
 </div>
 <div class="follow_me">
            <h3>Follow us on </h3>
            <a href=""><img src="images/ico1.jpg" alt="" /></a> 
             <a href=""><img src="images/ico2.jpg" alt="" /></a> 
                   </div>
                <br clear="all" />
            </div>
              </div>
            </div>
            <div class="footer"><span>A project by <a href="#"></a></span></div>
  </div>
  </body></html>
  <?php
  if(isset($_POST['add']))
 {
  $con=mysqli_connect("localhost","usernamer","password","your_db");
// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// escape variables for security
$email = mysqli_real_escape_string($con, $_POST['email']);

$sql="INSERT INTO email (email) VALUES ('$email')";

if (!mysqli_query($con,$sql)) {
  die('Error: ' . mysqli_error($con));
}
echo "Email id wasadded";
}
mysqli_close($con);
?>

答案 1 :(得分:1)

点击“INSERT INTO”语句:

http://www.w3schools.com/sql/sql_insert.asp

如果你做得对,你的代码可能看起来像这样:

<?php

if($_POST['submit']) {
    // INSERT INTO 'your_table' ('column','column') VALUES ('your_field','your_other_field')...
}

?>