dsfdfdfd6576578 2015-08-24 17:05
浏览 20

我需要一个帮助,如何检查用户是否存在于mysql中无法再次添加?

Here is my register.php codes

<?php 
include("dbconnection.php");
include("header.php");
include("validation/header.php"); 
include("functions/patient.php");

if(isset($_POST["button"]))
{
//select max value from patient db

    $result = mysql_query("SELECT MAX(patid) FROM patient");
while($row = mysql_fetch_array($result))
  {
$maxpatid = $row[0];
$maxpatid++;
  }



// Insert records to patient table
$sql="INSERT INTO patient(patid,patfname,patlname,emailid,contactno,password)
VALUES
('$maxpatid','$_POST[pfn]','$_POST[pln]','$_POST[email]','$_POST[contact]','$_POST[password]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
}

?>
<!-- ####################################################################################################### -->
<?php include("menu.php"); ?>
<!-- ####################################################################################################### -->
<!-- ####################################################################################################### -->
<div id="container">
  <div class="wrapper">
    <div id="content">
      <h1>Patient Registration</h1>
      <p>&nbsp;</p>

      <?php
      if(isset($_POST["button"]))
{
?>
 <table summary="Summary Here" cellpadding="0" cellspacing="0">
        <thead>
          <tr>
            <th>Patient Registered Successfully</th>
          </tr>
        </thead>
        <tbody>
          <tr class="light">
            <td><b>Your Patient ID is : <?php echo $maxpatid; ?></b></td>
          </tr>
                </tbody>
      </table>
      <form method="post" action="patientaccount.php" id="formID1" class="formular" >
        <input name="btnlogin" type="submit" id="submit" value="Click here to Login"  class="submit"/>

      <p>
&nbsp;<br />&nbsp;
      </p>
      </form>
<?php
}
else
{
?>
<form id="formID" class="formular" method="post">
  <div align="center"><strong><b> Registration Page</b></strong></div>
  <label for="textfield">  First Name</label>
     <input type="text" name="pfn" id="textfield" class="validate[required] text-input" />
     <label for="textfield2">Last Name</label>
      <input type="text" name="pln" id="textfield2" class="validate[required] text-input" />

      <label for="textfield4">Password</label>
        <input type="password" name="password" id="password"  class="validate[required] text-input"/>
      <label for="textfield3">        </label>


      Confirm Password
      <input type="password" name="textfield5" id="textfield5" class="validate[required,equals[password]] text-input" />


      Email ID
      <input type="text" name="email" id="textfield6" class="validate[required,custom[email]] text-input" />


      Contact No
      <input type="text" name="contact" id="textfield7" class="validate[required] text-input" />
    <div align="center">
        <input type="submit" name="button" id="button" value="Register"   class="submit"/>
        &nbsp;&nbsp;&nbsp;&nbsp;
        <input type="reset" name="button2" id="button2" value="Reset"  class="submit"/>
</div>
 <p>
&nbsp;<br />&nbsp;
      </p>
</form>
<form method="post" action="patientaccount.php" id="formID1" class="formular" >
       <p>
<b>Already Registered?</b>
      </p>
       <input name="btnlogin" type="submit" id="submit" value="Click here to Login"  class="submit"/>

      <p>
&nbsp;<br />&nbsp;
      </p>
      </form>
     <?php
}
?> 
      <p>&nbsp;</p>

      <div id="respond">
    </div>
    </div>
    <div id="column">
      <div class="holder">
        <h2>Registration Page</h2>
        <p>Please enter First Name, Last Name, Password, Email ID, Contact number to Register Clinicosight.</p>
</div>
</div>
    <br class="clear" />
  </div>
</div>

Please someone help me to solve this problem. When i input the same details of exists user, it still accept and duplicate the data in mysql. I need some validation code in here. Thanks in advance.

  • 写回答

3条回答 默认 最新

  • dongliang1223 2015-08-24 17:10
    关注

    instead of SELECT MAX(patid) FROM patient use SELECT $patid FROM patient if the rows returned is more than 0 the patient already exitst

    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图