PHP通知我代码?
我创建了一个名为aware的数据库和一个名为email的表,该表在phpmyadmin中有一个名为email的字段。我想在用户键入电子邮件地址并单击“通知我”后存储它。这是一个网站即将推出的网页 我如何做到这一点,一旦我连接到数据库,我需要做什么 这是到目前为止我的代码,请引导我正确的方向。我不是在找人帮我做这件事PHP通知我代码?,php,Php,我创建了一个名为aware的数据库和一个名为email的表,该表在phpmyadmin中有一个名为email的字段。我想在用户键入电子邮件地址并单击“通知我”后存储它。这是一个网站即将推出的网页 我如何做到这一点,一旦我连接到数据库,我需要做什么 这是到目前为止我的代码,请引导我正确的方向。我不是在找人帮我做这件事 <div id="main"> <div class="header"><a
<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);
?>
选中此处的INSERT INTO语句: 如果操作正确,您的代码可能会如下所示:
<?php
if($_POST['submit']) {
// INSERT INTO 'your_table' ('column','column') VALUES ('your_field','your_other_field')...
}
?>
我已经在msyqli中实现了您的代码。使用它 Just$sql=插入电子邮件值“$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);
?>
如果到目前为止这是您的代码,请帮自己一个忙,使用mysqli或PDO而不是mysql,因为它们已被弃用多年,不再受支持。请检查。你的标题一点也不令人信服。