0

我正在为新成员构建一个注册页面。填好表格后,会进入确认页面。确认后,它将进入 reg_add.php 将表单中的数据添加到数据库中。

reg_new.php --> reg_confirm.php --> reg_add.php

我正在尝试编辑确认页面 (reg_confirm.php) 中的代码以包含电子邮件可用性检查。似乎它可以在单击确认按钮后自动检测重复的电子邮件。

将显示键“PRIMARY”的重复条目“shop@gmail.com”。

但是,弹出警报并停留在确认页面中并不成功。请帮忙。

<?php

session_start();
$_SESSION['email'] = $_POST['email_reg'];
$_SESSION['password'] = $_POST['password_reg'];
$_SESSION['name_reg'] = $_POST['name_reg'];
$_SESSION['month'] = $_POST['month'];
$_SESSION['telephone_reg'] = $_POST['telephone_reg'];
$_SESSION['room_reg'] = $_POST['room_reg'];
$_SESSION['floor_reg'] = $_POST['floor_reg'];
$_SESSION['block_reg'] = $_POST['block_reg'];
$_SESSION['building_reg'] = $_POST['building_reg'];
$_SESSION['estate_reg'] = $_POST['estate_reg'];
$_SESSION['street_reg'] = $_POST['street_reg'];
$_SESSION['district_reg'] = $_POST['district_reg'];
$_SESSION['region_reg'] = $_POST['region_reg'];


$regemail = $_POST["email_reg"];

$connect = mysql_connect("127.0.0.1","root","") or die("not connecting");
mysql_select_db("shop") or die("no db :'(");

$numrows = mysql_query("SELECT membermail FROM member WHERE memberemail='$regemail'");


if ($numrows!=0)

{
echo "<script>alert('Email has been used by others!');window.location.href= 'reg_new.php';</script>";  

} 
?>




</head>
<body>
<div align="center" class="style1"><span class="style2">Registeration Confirm</span>
<p class="style2">&nbsp;</p>
 <form action="reg_add.php" method="post" enctype="multipart/form-data" name="form1">
<table width="602" height="180" border="1">
  <tr>
    <td colspan="3">Login Information</td>
  </tr>
  <tr>
    <td width="160" class="style6">Email address: </td>
    <td colspan="2"><span class="style7"><?php echo $_SESSION['email']?></span></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3">User information </td>
  </tr>
  <tr>
    <td><span class="style6">Name:</span></td>
    <td colspan="2"><?php echo ($_SESSION['name_reg'])?></td>
  </tr>
  <tr>
    <td><span class="style6">Month of birth :</span></td>
    <td colspan="2"><?php echo ($_SESSION['month'])?>
  </tr>
  <tr>
    <td><span class="style6">Contact telephone:</span></td>
    <td colspan="2"><?php echo ($_SESSION['telephone_reg'])?></td>
  </tr>
  <tr>
    <td rowspan="8"><span class="style6">Contact address:</span></td>
    <td width="153"><p class="style6">Room/ Flat no.: </p>        </td>
    <td width="267"><p class="style6"><?php echo ($_SESSION['room_reg'])?></p>        </td>
  </tr>
  <tr>
    <td><span class="style6">Floor: </span></td>
    <td width="267"><span class="style6"><?php echo ($_SESSION['floor_reg'])?></span></td>
  </tr>
  <tr>
    <td><span class="style6">Block/ Tower:</span></td>
    <td width="267"><span class="style6"><?php echo ($_SESSION['block_reg'])?></span></td>
  </tr>
  <tr>
    <td><span class="style6">Building:</span></td>
    <td width="267"><span class="style6"><?php echo ($_SESSION['building_reg'])?></span></td>
  </tr>
  <tr>
    <td><span class="style6">Estate: </span></td>
    <td width="267"><span class="style6"><?php echo ($_SESSION['estate_reg'])?></span></td>
  </tr>
  <tr>
    <td><span class="style6">Street:</span></td>
    <td width="267"><span class="style6"><?php echo ($_SESSION['street_reg'])?></span></td>
  </tr>
  <tr>
    <td><span class="style6">District:</span></td>
    <td width="267"><span class="style6"><?php echo ($_SESSION['district_reg'])?></span></td>
  </tr>
  <tr>
    <td><span class="style6">Region: </span></td>
    <td width="267"><span class="style6"><?php echo ($_SESSION['region_reg'])?></span></td>
  </tr>
  <tr>
    <td colspan="3" class="style6">&nbsp;</td>
  </tr>
</table>
<p>
  <input name="confirm" type="submit" id="confirm" value="Confirm">
</p>
</form>
<p>
<input name="modifty" type="submit" id="modifty" value="Modify" onClick="history.go(-1)">

</p>
</div>
</body>
</html>
4

1 回答 1

1

您的问题是如何从数据库中检索行数。 mysql_query()不检索行数。它检索结果集。

代替:

$numrows = mysql_query("SELECT membermail FROM member WHERE memberemail='$regemail'");


if ($numrows!=0)
{
    echo "<script>alert('Email has been used by others!');window.location.href= 'reg_new.php';</script>";  
} 

利用:

$email = mysql_real_escape_string($_POST["email_reg"]);

$result = mysql_query("SELECT COUNT(memberemail) AS emailCount FROM member WHERE memberemail='{$email}'");

$row = mysql_fetch_row($result);

if($row[0]>0){
    echo "<script>alert('Email has been used by others!');window.location.href= 'reg_new.php';</script>"; 
}

始终确保在数据库查询中使用数据之前对其进行转义。

于 2013-05-23T07:22:14.913 回答