我的这个php代码片段有什么问题
尝试从以下内容更改:我的这个php代码片段有什么问题,php,mysql,Php,Mysql,尝试从以下内容更改: <?php $connection = mysql_connect("localhost","*******","******"); if (!$connection) { die('PHP Mysql database connection could not connect : ' . mysql_error()); } else{ $db_name = "*****"; mysql_select_db($db_name, $connection); $re
<?php
$connection = mysql_connect("localhost","*******","******");
if (!$connection) {
die('PHP Mysql database connection could not connect : ' . mysql_error());
}
else{
$db_name = "*****";
mysql_select_db($db_name, $connection);
$result = mysql_query("SELECT email FROM subscribers WHERE email = '".$_POST['email']."'";);
$num_rows = mysql_num_rows($result);
if(isset($_POST['submit'])){
if($_POST['email']!=""){
if ($num_rows > 0) {
echo "email already unsubscribed";
}
else {
$update_sql = "UPDATE subscribers SET unsubscribed = '1' WHERE email = '".$_POST['email']."'";
mysql_query($update_sql, $connection);
echo "<div id='notify' style ='margin-left: auto; margin-right: auto; width: 330px; height: 40px; text-align: center; background-color: #9BFFCD; font-weight: bold; font-family: Verdana, Geneva, sans-serif; padding-top:18px; border: solid #060 thin;'> YOU'RE UNSUBSCRIBED</div>";
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Unsubscribe Page</title>
<script>
setTimeout(function(){
document.getElementById('notify').style.display = 'none';
/* or
var item = document.getElementById('notify')
item.parentNode.removeChild(item);
*/
}, 3000);
</script>
</head>
<body>
<div style="margin-left: auto; margin-right: auto; width: 330px; height: 80px; text-align: center; margin-top:100px;">
<div style="height: 30px; margin-bottom: 12px; padding-top: 9px; font-family: Verdana, Geneva, sans-serif; font-size: 11px; text-align: center; background-color:#FBDACE"><strong>CONFIRM UR EMAIL-ID BELOW TO UNSUBSCRIBE</strong><span style="text-align: center"></span></div>
<div style="height: 30px; margin-bottom: 12px; padding-top: 9px; font-family: Verdana, Geneva, sans-serif; font-size: 11px; text-align: center; background-color:#FBDACE">
<form method="post" name="update" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input name="email" type="text" size="33" /></td>
<td><input name="submit" type="submit" value="Unsubscribe" /></td>
</tr>
</table>
</form>
</div>
</div>
</html>
$result=mysql\u query(“选择来自订阅服务器的电子邮件,其中电子邮件=”。$\u POST['email']。“”;);
$num\u rows=mysql\u num\u rows($result);
如果(isset($_POST['submit'])){
如果($_POST['email']!=“”){
如果($num_rows>0){
回显“已取消订阅的电子邮件”;
}
否则{
$update_sql=“更新订阅者集unsubscribed='1'其中email='”$\u POST['email']。“”;
mysql\u查询($update\u sql,$connection);
回音“你被取消订阅”;
}
到
if(isset($\u POST['submit'])){
如果($_POST['email']!=“”){
$result=mysql\u query(“选择来自订阅服务器的电子邮件,其中
电子邮件=“$_POST['email']”和取消订阅='1'”;
$num\u rows=mysql\u num\u rows($result);
如果($num_rows>0){
回显“已取消订阅的电子邮件”;
}
否则{
$update\u sql=“更新订阅服务器集取消订阅='1'其中
电子邮件=“$_POST['email']。”;
mysql\u查询($update\u sql,$connection);
回音“你被取消订阅”;
}
变化:
寻求调试帮助的问题(“此代码为什么不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现这些问题所需的最短代码。没有明确问题说明的问题对其他读者没有用。请参阅:它现在做错了什么?在我看来,逻辑是错误的。你检查是否有现有电子邮件,然后如果有,你说你已经取消订阅,这没有意义。我想用select查询检查输入的电子邮件id是否存在于表中,如果是,则显示消息“您已取消订阅”否则,如果表中不存在用户电子邮件id,则使用更新查询记录更新,然后显示消息“您已取消订阅”“更改代码后,页面上没有显示任何内容……这意味着在复制粘贴过程中,某些内容被错误复制。能否打开错误报告以查看错误原因。1.2。
$result = mysql_query("SELECT email FROM subscribers WHERE email = '".$_POST['email']."'";);
$num_rows = mysql_num_rows($result);
if(isset($_POST['submit'])){
if($_POST['email']!=""){
if ($num_rows > 0) {
echo "email already unsubscribed";
}
else {
$update_sql = "UPDATE subscribers SET unsubscribed = '1' WHERE email = '".$_POST['email']."'";
mysql_query($update_sql, $connection);
echo "<div id='notify' style ='margin-left: auto; margin-right: auto; width: 330px; height: 40px; text-align: center; background-color: #9BFFCD; font-weight: bold; font-family: Verdana, Geneva, sans-serif; padding-top:18px; border: solid #060 thin;'> YOU'RE UNSUBSCRIBED</div>";
}
if(isset($_POST['submit'])){
if($_POST['email']!=""){
$result = mysql_query("SELECT email FROM subscribers WHERE
email = '".$_POST['email']."' AND unsubscribed ='1'";);
$num_rows = mysql_num_rows($result);
if ($num_rows > 0) {
echo "email already unsubscribed";
}
else {
$update_sql = "UPDATE subscribers SET unsubscribed = '1' WHERE
email = '".$_POST['email']."'";
mysql_query($update_sql, $connection);
echo "<div id='notify' style ='margin-left: auto; margin-right: auto; width: 330px; height: 40px; text-align: center; background-color: #9BFFCD; font-weight: bold; font-family: Verdana, Geneva, sans-serif; padding-top:18px; border: solid #060 thin;'> YOU'RE UNSUBSCRIBED</div>";
}