doucuyu2259 2016-12-05 18:00
浏览 92
已采纳

处理HTML <input>属性[duplicate]

This question already has an answer here:

I am writing basic user register page, My register page contain : usermail ,password, plan type. There are three plans for plan type. Three plans are: basic, sliver and gold.

The register_main.php is to store user information in Mysql.

I met issue that is when I click basic or sliver or gold plan, the page will go to register_main page . I want sent user information only to server ,when they click sign in.

Can anyone help me to solve this issue?

HTML Code:

    <html>
        <head>
                <title>Register</title>
                <meta charset="UTF-8">
                <!-- Include JS File Here -->
                <script src="Script/register_validate.js">
                <script type="text/javascript"
                    src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
                <script type="text/javascript"
                    src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
                </script>
        </head>
<body>
        <form name="registerform" action="register_main.php" method="post" onsubmit="return validate()">
              <p id="benefits_text" class="white size_8">Benefits:</p>
              <input id="type_basic" type ="image" name="basicPlan" " src="basic.png">
              <input id="type_silver" type ="image" name="silverPlan" " src="silver.png">
              <input id="type_gold" type ="image" name="goldPlan" " src="gold.png">
              <div id="userinfo_content">
                   <p id="email_text" class="white size_8">Email Address</p>
                   <input id="email_input" name="userEmail" type="text"class="sign_input">
                   <p id="password_text" class="white size_8">Password</p>
                   <input id="password_input" name="password" type="password">
                   <p id="confirmPW_text" class="white size_8">Confirm Password</p>
                   <input id="confirmPW_input" name="confirm_password" type="password">
                  <input id="btn_signin" type ="image" alt ="submit" src="signin.png">
              </div>
    </form></body>
    </html>

register_main.php

include ("config.php");
require ("encrypt.php");
session_start ();

if ($_SERVER ["REQUEST_METHOD"] == "POST") {

    // Get userEmail from client side and create a legal SQL string that you can use in an SQL statement.
    $user_emailaddress = mysqli_real_escape_string ( $db, $_POST ['userEmail'] );
    // Get password from client side and create a legal SQL string that you can use in an SQL statement.
    $user_password = mysqli_real_escape_string ( $db, $_POST ['password'] );
    // Get planType from client side and create a legal SQL string that you can use in an SQL statement.
    $user_planType = mysqli_real_escape_string ( $db, $_POST ['planType'] );
    // Create user.
    // Note user Id is generated when a new record is inserted into a table.
    $sql = "INSERT INTO admin (emailAddress,passcode,planType) VALUES ('$user_emailaddress','$user_Newpassword','$user_planType')";
    $result = mysqli_query ( $db, $sql );


    // if create user a successfully, jump to welcome page.
    // otherwise print error information
    if ($result ) {
        echo "New record created successfully";
        $_SESSION ['login_user'] = $user_emailaddress;
        header ( "location: welcome.php" );
    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error ( $db );
    }
    // Close Database
    mysqli_close ( $db );
}
?>
</div>
  • 写回答

1条回答 默认 最新

  • douzhong6480 2016-12-05 18:18
    关注

    the problem with your form is that the input tag with type="image" acts as a submit button when clicked. Check out this link: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/image.

    I guess that in your use case, you want these images to act as selection buttons for the available plan types. So I think you could replace then for an image tag with a radio button, or a select input with the three plans.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮