这是我的插入查询:
<?php
require_once "config.php";
if(isset($_POST['submit'])){
$email = mysql_escape_string($_POST['txtemail']);
$str = "insert into subscribe(email,datetime) values ('$email',current_timestamp)";
$result = mysql_query($str);
print '<script type="text/javascript">';
print 'alert("Thank you for subscribing with us. We will be in touch with you very soon.")';
print '</script>';
}
这是上面的代码是完全有效的,但是当我在表单操作上放置一个值以重定向到这样的另一个页面时,查询不会插入。
<form action="/?sender=nopopup" method="POST">
我尝试使用标题(位置:&#39; url&#39;),但它也不起作用。 任何帮助将不胜感激,谢谢。
这是我的全部代码:
<html>
<head>
<title>Chill PH</title>
<link rel="stylesheet" type="text/css" href="style/style.css" media="screen">
<link rel="stylesheet" type="text/css" href="style/main.css" media="screen">
<link rel="stylesheet" href="images/default/default.css" type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" href="style/popup.css" media="screen">
<script type="text/javascript" src="jQuery/popup.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<div id="overlay"></div>
<center>
<div id="popup">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?sender=nopopup" method="POST">
<table style="background-color:#FFFFFF;">
<tr>
<a href="#" onclick="closePopUp()"><img src="images/popup/chill_closebtn.png" style="width:30px; height:30px; vertical-align: top;
margin-left: 583px; margin-top: -12px; position:fixed;"/></a>
<img src="images/popup/chill_popup.jpg"/>
</tr>
<tr>
<td style="width: 594px; height: 111px;">
<input id="txtemail" type="email" font-size= "12px" name="txtemail" placeholder="E-mail Address"
style="background-color:#f1c4c0; border-style:none; height:40px; width:270px; margin-left:60px; border-style:none; font-size: 15px;" required/>
<input type="submit" id="subcribe_button" name="submit" value="Subscribe" />
</td>
</tr>
</table>
</form>
</div>
</center>
<body onload="showPopUp()">
<center>
<div id="container">
<table id="header">
<tr>
<td>
<center>
<div id="logo" style="color: #ff0000;">
<a href="/?sender=nopopup"><img src="images/logo.png" alt="Chill" style="width: 130px;" /></a>
</div>
</center>
</td>
<td style="float: left; width: 15px; padding-right: 15px;">
<div id="searchbox">
<form name="frmsearch" method="POST" action="/?sender=result">
<input type="text" id="search" name="search" size=20 placeholder="Search" style="background-color: white; float: right; color: black; border: 1px solid #000;"/>
<input type="submit" id="submit" name="submit" value="Search" style="display: none;visibility: hidden;" />
</form>
</div>
</td>
</tr>
<tr>
<td align='center'>
<div id="main-nav">
<ul>
<li style="padding-left: 50px; padding-right: 40px;"><a href="#">WHAT'S HOT<span class="drop-down"></span></a>
<ul>
<li class="shopitems"><a href="/?sender=shop&category=newarrivals">New Arrivals</a></li>
<li class="shopitems"><a href="/?sender=shop&category=sale">Sale Items</a></li>
</ul>
</li>
<li style="padding-left: 40px; padding-right: 40px;"><a href="#">COLLECTION<span class="drop-down"></span></a>
<ul>
<li class="shopitems"><a href="/?sender=shop&category=DRESS">Dresses</a></li>
<li class="shopitems"><a href="/?sender=shop&category=TOPS">Tops</a></li>
<li class="shopitems"><a href="/?sender=shop&category=SKIRTS">Skirts</a></li>
</ul>
</li>
<li style="padding-left: 30px; padding-right: 30px;"><a href="/?sender=lookbook" class="lookbook">LOOKBOOK</a></li>
<li style="padding-left: 30px; padding-right: 30px;"><a href="/?sender=news">NEWS</a></li>
<li style="padding-left: 40px; padding-right: 30px;"><a href="/?sender=store">STORES</a></li>
</ul>
</div>
</td>
</tr>
</table>
<?php
require_once "config.php";
if(isset($_POST['submit'])){
$email = mysql_escape_string($_POST['txtemail']);
$str = "insert into subscribe(email,datetime) values ('$email',current_timestamp)";
$result = mysql_query($str);
print '<script type="text/javascript">';
print 'alert("Thank you for subscribing with us. We will be in touch with you very soon.")';
print '</script>';
}
?>
答案 0 :(得分:0)
应该是:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?sender=nopopup" method="POST">
/
正在将其发布到您网站的根目录,而不是当前的网址。 $_SERVER['PHP_SELF']
包含当前脚本相对于文档根目录的路径。