首页 \ 问答 \ 使用单选按钮从动态注册表单插入数据[关闭](Insert Data from a dynamic registration form with radio buttons [closed])

使用单选按钮从动态注册表单插入数据[关闭](Insert Data from a dynamic registration form with radio buttons [closed])

我想从表单中将数据插入到我的数据库中,当我选择一种类型(医生或患者)将数据发送到适当的表格时。

这是代码

    <?php



    include_once 'header.php';


    if (isset($_SESSION['username'])) destroySession();
    if(isset($_POST['register']))
    {
    if (isset($_POST['username']))
    {
        $fname = sanitizeString($_POST['fname']);
        $lname = sanitizeString($_POST['lname']);
        $username = sanitizeString($_POST['username']);
        $email = sanitizeString($_POST['email']);
        $password = sanitizeString($_POST['password']);
        if($_POST["answer" === "Doctor"])
        {
            $DoctorG = sanitizeString($_POST['DoctorG']);
            $DoctorAge = ($_POST['DoctorAge']);
            $specialty = sanitizeString($_POST['specialty']);
            $Doctor_ID = ($_POST['Doctor_ID']);

                 if (mysql_num_rows(queryMysql("SELECT * FROM doctor
                      WHERE username='$username'")))
                    $error = "That username already exists<br /><br />";
                else
                  {
                    queryMysql("INSERT INTO doctor (fname,lname,username,email,password,gender,age,specialty,doctorID) VALUES('$fname','$lname','$username','$email', '$password','$DoctorG','$DoctorAge','$specialty','$DoctorID')");
                    die("<h4>Account created</h4>Please Log in.<br /><br />");
                  }
        }




    }
    }
    ?>
    <html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<form method="post" action="signup.php">
<fieldset>
    <legend>Registration Form</legend>
    <label>First Name
        <input type="text" name="fname" required="required" />
    </label>
    <br/>
    <br/>
    <label>Last Name
        <input type="text" name="lname" required="required" />
    </label>
    <br />
    <br />
    <label>Username
        <input type="text" name="username" required="required" />
    </label>
    <br />
    <br />
    <label>Email
        <input type="text" name="email" required="required" />
    </label>
    <br />
    <br />
    <label>Password
        <input type="text" name="password" required="required" />
    </label>
    <br/><br/>
 User Type:
  <br/>Doctor
  <input type="radio" name="answer" value="Doctor" />
  Patient
  <input type="radio" name="answer" value="Patient" />

  <!--DOCTOR OPTIONS -->
  <div id="expandDoctor" style="display:none;">
    <label id="Male">Male</label>
    <input type="radio" name="DoctorG" value="male" id="DoctorG">
    <label id="Female">Female</label>
    <input type="radio" name="DoctorG" value="female" id="DoctorG">
    <br/>
    <br/>
    <label id="Age">Age:</label>
    <input type="text" name="DoctorAge" id="DoctorAge" />
    <br/>
    <br/>
    <label id="Specialty">Specialty:</label>
    <select id="SelectSpecialty" name="specialty">
      <option value="A">A</option>
      <option value="B">B</option>
      <option value="C">C</option>
      <option value="D">D</option>
    </select>
    <br/>
    <br/>
    <label id="ID">Doctor ID:</label>
    <input type="text" name="Doctor_ID" id="Doctor_ID" />
  </div>

  <!--PATIENT OPTIONS -->
  <div id="expandPatient" style="display:none;">
    <label id="Male">Male</label>
    <input type="radio" name="PatientG" value="male" id="PatientGM">
    <label id="Female">Female</label>
    <input type="radio" name="PatientG" value="female" id="PatientGF">
    <br/>
    <br/>
    <label id="Age">Age:</label>
    <input type="text" name="PatientAge" id="PatientAge" />
    <br/>
    <br/>
    <label id="Disease">Disease:</label>
    <select id="SelectDisease" name="specialty">
      <option value="A">A</option>
      <option value="B">B</option>
      <option value="C">C</option>
      <option value="D">D</option>
    </select>
    <br/>
    <br/>
    <label id="SPID">SPID:</label>
    <input type="text" name="PatientSPID" id="PatientSPID" />
  </div>
</fieldset>

<input type="submit" value="Register" name="register"/>
</form>
</body>
<script>
$("input[type='radio'][name='answer']").change(function() {
  $("[id^=expand]").hide();
  $("#expand" + $(this).val()).show();
});</script>

</body>
</html>

我收到此错误注意:未定义的偏移量:在第21行的E:\ xampp \ htdocs \ ptixiaki \ signup.php中为0

PS:我没有所有需要的插页,我只是想为博士测试它,如果它适用于他们我也会为病人做


I want to insert data to my database from a form and when i select a type (doctor or patient) to send the data to the appropriate table.

HERE IS THE CODE

    <?php



    include_once 'header.php';


    if (isset($_SESSION['username'])) destroySession();
    if(isset($_POST['register']))
    {
    if (isset($_POST['username']))
    {
        $fname = sanitizeString($_POST['fname']);
        $lname = sanitizeString($_POST['lname']);
        $username = sanitizeString($_POST['username']);
        $email = sanitizeString($_POST['email']);
        $password = sanitizeString($_POST['password']);
        if($_POST["answer" === "Doctor"])
        {
            $DoctorG = sanitizeString($_POST['DoctorG']);
            $DoctorAge = ($_POST['DoctorAge']);
            $specialty = sanitizeString($_POST['specialty']);
            $Doctor_ID = ($_POST['Doctor_ID']);

                 if (mysql_num_rows(queryMysql("SELECT * FROM doctor
                      WHERE username='$username'")))
                    $error = "That username already exists<br /><br />";
                else
                  {
                    queryMysql("INSERT INTO doctor (fname,lname,username,email,password,gender,age,specialty,doctorID) VALUES('$fname','$lname','$username','$email', '$password','$DoctorG','$DoctorAge','$specialty','$DoctorID')");
                    die("<h4>Account created</h4>Please Log in.<br /><br />");
                  }
        }




    }
    }
    ?>
    <html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<form method="post" action="signup.php">
<fieldset>
    <legend>Registration Form</legend>
    <label>First Name
        <input type="text" name="fname" required="required" />
    </label>
    <br/>
    <br/>
    <label>Last Name
        <input type="text" name="lname" required="required" />
    </label>
    <br />
    <br />
    <label>Username
        <input type="text" name="username" required="required" />
    </label>
    <br />
    <br />
    <label>Email
        <input type="text" name="email" required="required" />
    </label>
    <br />
    <br />
    <label>Password
        <input type="text" name="password" required="required" />
    </label>
    <br/><br/>
 User Type:
  <br/>Doctor
  <input type="radio" name="answer" value="Doctor" />
  Patient
  <input type="radio" name="answer" value="Patient" />

  <!--DOCTOR OPTIONS -->
  <div id="expandDoctor" style="display:none;">
    <label id="Male">Male</label>
    <input type="radio" name="DoctorG" value="male" id="DoctorG">
    <label id="Female">Female</label>
    <input type="radio" name="DoctorG" value="female" id="DoctorG">
    <br/>
    <br/>
    <label id="Age">Age:</label>
    <input type="text" name="DoctorAge" id="DoctorAge" />
    <br/>
    <br/>
    <label id="Specialty">Specialty:</label>
    <select id="SelectSpecialty" name="specialty">
      <option value="A">A</option>
      <option value="B">B</option>
      <option value="C">C</option>
      <option value="D">D</option>
    </select>
    <br/>
    <br/>
    <label id="ID">Doctor ID:</label>
    <input type="text" name="Doctor_ID" id="Doctor_ID" />
  </div>

  <!--PATIENT OPTIONS -->
  <div id="expandPatient" style="display:none;">
    <label id="Male">Male</label>
    <input type="radio" name="PatientG" value="male" id="PatientGM">
    <label id="Female">Female</label>
    <input type="radio" name="PatientG" value="female" id="PatientGF">
    <br/>
    <br/>
    <label id="Age">Age:</label>
    <input type="text" name="PatientAge" id="PatientAge" />
    <br/>
    <br/>
    <label id="Disease">Disease:</label>
    <select id="SelectDisease" name="specialty">
      <option value="A">A</option>
      <option value="B">B</option>
      <option value="C">C</option>
      <option value="D">D</option>
    </select>
    <br/>
    <br/>
    <label id="SPID">SPID:</label>
    <input type="text" name="PatientSPID" id="PatientSPID" />
  </div>
</fieldset>

<input type="submit" value="Register" name="register"/>
</form>
</body>
<script>
$("input[type='radio'][name='answer']").change(function() {
  $("[id^=expand]").hide();
  $("#expand" + $(this).val()).show();
});</script>

</body>
</html>

I get this error Notice: Undefined offset: 0 in E:\xampp\htdocs\ptixiaki\signup.php on line 21

PS: I dont have all the needed inserts , I just want to test it for the Doctor and if it works for them I will do for the patient also


原文:https://stackoverflow.com/questions/27643068
更新时间:2021-10-11 18:10

最满意答案

错误是我应该有if($ _POST [“answer”] ===“Doctor”)而不是if($ _ POST [“answer”===“Doctor”])然后它显示第二个错误INSERT INTO是Doctor_ID中的下划线

这是新代码....

 <?php

    /**
     * @author Nick Bourlai
     * @copyright 2014
     */

    include_once 'header.php';


    if (isset($_SESSION['username'])) destroySession();
    if(isset($_POST['register']))
    {
    if (isset($_POST['username']))
    {
        $fname = sanitizeString($_POST['fname']);
        $lname = sanitizeString($_POST['lname']);
        $username = sanitizeString($_POST['username']);
        $email = sanitizeString($_POST['email']);
        $password = sanitizeString($_POST['password']);
        if( $_POST["answer"] === "Doctor" )
        {
            $DoctorG = sanitizeString($_POST['DoctorG']);
            $DoctorAge = ($_POST['DoctorAge']);
            $specialty = sanitizeString($_POST['specialty']);
            $Doctor_ID = ($_POST['Doctor_ID']);

                 if (mysql_num_rows(queryMysql("SELECT * FROM doctor
                      WHERE username='$username'")))
                    $error = "That username already exists<br /><br />";
                else
                  {
                    queryMysql("INSERT INTO doctor (fname,lname,username,email,password,gender,age,specialty,doctorID) VALUES('$fname','$lname','$username','$email', '$password','$DoctorG','$DoctorAge','$specialty','$Doctor_ID')");
                    die("<h4>Account created</h4>Please Log in.<br /><br />");
                  }
        }




    }
    }
    ?>
    <html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    </head>
    <body>
    <form method="post" action="signup.php">
    <fieldset>
        <legend>Registration Form</legend>
        <label>First Name
            <input type="text" name="fname" required="required" />
        </label>
        <br/>
        <br/>
        <label>Last Name
            <input type="text" name="lname" required="required" />
        </label>
        <br />
        <br />
        <label>Username
            <input type="text" name="username" required="required" />
        </label>
        <br />
        <br />
        <label>Email
            <input type="text" name="email" required="required" />
        </label>
        <br />
        <br />
        <label>Password
            <input type="text" name="password" required="required" />
        </label>
        <br/><br/>
     User Type:
      <br/>Doctor
      <input type="radio" name="answer" value="Doctor" />
      Patient
      <input type="radio" name="answer" value="Patient" />

      <!--DOCTOR OPTIONS -->
      <div id="expandDoctor" style="display:none;">
        <label id="Male">Male</label>
        <input type="radio" name="DoctorG" value="male" id="DoctorG">
        <label id="Female">Female</label>
        <input type="radio" name="DoctorG" value="female" id="DoctorG">
        <br/>
        <br/>
        <label id="Age"&t;Age:</label>
        <input type="text" name="DoctorAge" id="DoctorAge" />
        <br/>
        <br/>
        <label id="Specialty">Specialty:</label>
        <select id="SelectSpecialty" name="specialty">
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          <option value="D">D</option>
        </select>
        <br/>
        <br/>
        <label id="ID">Doctor ID:</label>
        <input type="text" name="Doctor_ID" id="Doctor_ID" />
      </div>

      <!--PATIENT OPTIONS -->
      <div id="expandPatient" style="display:none;">
        <label id="Male">Male</label>
        <input type="radio" name="PatientG" value="male" id="PatientGM">
        <label id="Female">Female</label>
        <input type="radio" name="PatientG" value="female" id="PatientGF">
        <br/>
        <br/>
        <label id="Age">Age:</label>
        <input type="text" name="PatientAge" id="PatientAge" />
        <br/>
        <br/>
        <label id="Disease">Disease:</label>
        <select id="SelectDisease" name="specialty">
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          <option value="D">D</option>
        </select>
        <br/>
        <br/>
        <label id="SPID">SPID:</label>
        <input type="text" name="PatientSPID" id="PatientSPID" />
      </div>
    </fieldset>

    <input type="submit" value="Register" name="register"/>
    </form>
    </body>
    <script>
    $("input[type='radio'][name='answer']").change(function() {
      $("[id^=expand]").hide();
      $("#expand" + $(this).val()).show();
    });</script>

    </body>
    </html>

The error was that i should have if( $_POST["answer"] === "Doctor" ) instead of if($_POST["answer" === "Doctor"]) and then it shows a second error in the INSERT INTO which was an underscore in the Doctor_ID

HERE IS THE NEW CODE....

 <?php

    /**
     * @author Nick Bourlai
     * @copyright 2014
     */

    include_once 'header.php';


    if (isset($_SESSION['username'])) destroySession();
    if(isset($_POST['register']))
    {
    if (isset($_POST['username']))
    {
        $fname = sanitizeString($_POST['fname']);
        $lname = sanitizeString($_POST['lname']);
        $username = sanitizeString($_POST['username']);
        $email = sanitizeString($_POST['email']);
        $password = sanitizeString($_POST['password']);
        if( $_POST["answer"] === "Doctor" )
        {
            $DoctorG = sanitizeString($_POST['DoctorG']);
            $DoctorAge = ($_POST['DoctorAge']);
            $specialty = sanitizeString($_POST['specialty']);
            $Doctor_ID = ($_POST['Doctor_ID']);

                 if (mysql_num_rows(queryMysql("SELECT * FROM doctor
                      WHERE username='$username'")))
                    $error = "That username already exists<br /><br />";
                else
                  {
                    queryMysql("INSERT INTO doctor (fname,lname,username,email,password,gender,age,specialty,doctorID) VALUES('$fname','$lname','$username','$email', '$password','$DoctorG','$DoctorAge','$specialty','$Doctor_ID')");
                    die("<h4>Account created</h4>Please Log in.<br /><br />");
                  }
        }




    }
    }
    ?>
    <html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    </head>
    <body>
    <form method="post" action="signup.php">
    <fieldset>
        <legend>Registration Form</legend>
        <label>First Name
            <input type="text" name="fname" required="required" />
        </label>
        <br/>
        <br/>
        <label>Last Name
            <input type="text" name="lname" required="required" />
        </label>
        <br />
        <br />
        <label>Username
            <input type="text" name="username" required="required" />
        </label>
        <br />
        <br />
        <label>Email
            <input type="text" name="email" required="required" />
        </label>
        <br />
        <br />
        <label>Password
            <input type="text" name="password" required="required" />
        </label>
        <br/><br/>
     User Type:
      <br/>Doctor
      <input type="radio" name="answer" value="Doctor" />
      Patient
      <input type="radio" name="answer" value="Patient" />

      <!--DOCTOR OPTIONS -->
      <div id="expandDoctor" style="display:none;">
        <label id="Male">Male</label>
        <input type="radio" name="DoctorG" value="male" id="DoctorG">
        <label id="Female">Female</label>
        <input type="radio" name="DoctorG" value="female" id="DoctorG">
        <br/>
        <br/>
        <label id="Age">Age:</label>
        <input type="text" name="DoctorAge" id="DoctorAge" />
        <br/>
        <br/>
        <label id="Specialty">Specialty:</label>
        <select id="SelectSpecialty" name="specialty">
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          <option value="D">D</option>
        </select>
        <br/>
        <br/>
        <label id="ID">Doctor ID:</label>
        <input type="text" name="Doctor_ID" id="Doctor_ID" />
      </div>

      <!--PATIENT OPTIONS -->
      <div id="expandPatient" style="display:none;">
        <label id="Male">Male</label>
        <input type="radio" name="PatientG" value="male" id="PatientGM">
        <label id="Female">Female</label>
        <input type="radio" name="PatientG" value="female" id="PatientGF">
        <br/>
        <br/>
        <label id="Age">Age:</label>
        <input type="text" name="PatientAge" id="PatientAge" />
        <br/>
        <br/>
        <label id="Disease">Disease:</label>
        <select id="SelectDisease" name="specialty">
          <option value="A">A</option>
          <option value="B">B</option>
          <option value="C">C</option>
          <option value="D">D</option>
        </select>
        <br/>
        <br/>
        <label id="SPID">SPID:</label>
        <input type="text" name="PatientSPID" id="PatientSPID" />
      </div>
    </fieldset>

    <input type="submit" value="Register" name="register"/>
    </form>
    </body>
    <script>
    $("input[type='radio'][name='answer']").change(function() {
      $("[id^=expand]").hide();
      $("#expand" + $(this).val()).show();
    });</script>

    </body>
    </html>

相关问答

更多

相关文章

更多

最新问答

更多
  • 如何避免iPhone应用程序泄漏?(How to avoid leaking in iPhone application?)
  • Rails引擎:在哪里定义仅用于测试的gems(Rails Engines: Where to define gems only used in testing)
  • 如何在android中的texviews中随机设置文本?(How to randomly settext in textviews in Android?)
  • PHP函数 - 用.00清理数字(PHP Function - cleaning up numbers with .00)
  • 如何在WPF中数据绑定到IGrouping?(How do I databind to a IGrouping in WPF?)
  • 在更新语句中增加时是否存在并发问题[复制](Are there concurrency issues when incrementing in update statement [duplicate])
  • RabbitMQ与NodeJS Addon for C ++应用程序集成(RabbitMQ vs NodeJS Addon for C++ Application Integration)
  • 使用CoreData执行乘法(聚合):如何?(Performing multiplication (aggregation) with CoreData: how to?)
  • 如何在Android中按位置显示Listview中的项目(How to display Item from a Listview by position in Android)
  • 无效的命令ProxyRequests设置jenkins时(Invalid command ProxyRequests when setting up jenkins)
  • C#,MySQL - 从表中检索行并在方法中填充变量,然后将Add()方法填充到List <>(C#, MySQL - Retrieve row from table and populate variables in method then Add() method to List<>)
  • 如何从内部拒绝承诺功能(How to reject a promise from inside then function)
  • javadoc for String [] args(javadoc for String[] args)
  • Laravel格式查询json结果(Laravel format query json result)
  • ImageIO - 从加载的图像中获取图像宽度和高度(ImageIO - get image Width and Height from loaded image)
  • 如何在Windows 7中批量重命名文件名,以便它们在结尾处具有数字顺序?(How do I batch-rename filenames in windows 7, so that they have numerical order at the end of them?)
  • 限制用户在Apple应用商店中撰写有关该应用的评论(Restrict user to write review about the app at Apple app store)
  • 亚马逊Kindle Fire中的java.lang.OutOfMemoryError(java.lang.OutOfMemoryError in Amazon Kindle Fire)
  • 如何使用C#在python中将字符串作为命令行参数传递(How to pass string as command line argument in python using C#)
  • 发生操作时使用ngrx-effect调用服务(Use ngrx-effect to call a service when an action occurs)
  • 在Android应用程序中集成所有社交资源(Integrating All Social Feeds In an Android App)
  • 哪些对象需要产前诊断?
  • 在React模板渲染上调用函数(Call function on React template render)
  • 如何将图标添加到SlidingTabLayout?(How to add Icons to SlidingTabLayout?)
  • 根据给定的数字数组创建一个几乎唯一的标识符(Create an almost unique identifier based on a given array of numbers)
  • 使用样式标签更改鼠标上方的文本颜色(Change text color on mouse over using the style tag)
  • Ruby String#{}不起作用(Ruby String #{} doesn't work)
  • 字符串和指针(Strings and pointers)
  • 中小学教师信息技术应用能力提升全员培训要求教师每五年不少于学时的培训标
  • 无法传递函数值来设置数组大小C ++(Can't pass a function value to set an array size C++)