duai4512
2015-08-12 11:32
浏览 53
已采纳

验证页面后如何将数据传递到另一个页面?

I have finish my validation form and everything working fine, but I have problem on how to transfer the data from the form to another .php page which is the process page.

I`m currently refer from this site for form validation code http://www.w3schools.com/php/showphp.asp?filename=demo_form_validation_required

myform

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" id="form">

       <fieldset>
                <td>Name</td>
                <label>
                    <input type="text" name = "nama">
                    </input>
                    <span class="error">* <?php echo $nameErr;?></span>
                  </label>
                  <br>
                   <p>Gender</p>
                   <p>
                    Male</p><input type="radio" name= "gender" value="Male" >
                    <br>

                    <input name= "gender" type="radio" value="Female">
                Female<br></input>
                    <span class="error">* <?php echo $genderErr;?></span>

                  <br>
                  <td>Contact No</td>
                  <label>
                    <input type="text" name= "contact">
                    </input>
                    <span class="error">* <?php echo $contactErr;?></span>
                  </label>

                  <br>
                  <td>Address</td>
                  <label>
                    <textarea name= "address"></textarea>
                    <span class="error">* <?php echo $addressErr;?></span>
                  </label>
                  <br>
                <td>Email</td>
                  <label>
                    <input type="text" name= "email"></input>
                    <span class="error">* <?php echo $emailErr;?></span>
                  </label>
                  <br>
                  <td>Account Name</td>
                  <label>
                    <input type="text" name= "account"></input>
                    <span class="error">* <?php echo $accountErr;?></span>
                  </label>
                  <br>
                  <td>Password</td>
                  <label>
                    <input type="password" name= "password"></input>
                    <span class="error">* <?php echo $passwordErr;?></span>
                  </label>
                  <br>
                  <input type="button" value="Cancel"onClick="history.go(-1);return true;">
                  <input type="submit" value="Submit">


                </fieldset>
              </form>

process.php

<?php


$link = mysqli_connect('localhost', 'root', '', 'sport');

$nama=$_POST["nama"];
$gender=$_POST["gender"];
$contact=$_POST["contact"];
$address=$_POST["address"];
$email=$_POST["email"];
$account=$_POST["account"];
$password=$_POST["password"];

$sql = "INSERT INTO sport(name, gender, contact, address, email, account, password, eventtype) VALUES ('$nama' , '$gender', '$contact' , '$address', '$email', '$account', '$password', '')"; 

$query=mysqli_query($link, $sql);

if (!$query)
{
    echo "Fail to register";
}
else
{
header('Location:login_success.html');  
}

?>

How do I pass the data after I validate the form to process.php and execute the sql query so I store the data into the database. Supposedly we just put the target page in , but the code required me to use <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douwen1549 2015-08-12 11:50
    已采纳

    As per the link you have provided that they have used a server side validation instead of doing the server side validation try to do a client side validation by using the JavaScript or jQuery.

    you can check the simplest way of doing the JavaScript validation here : http://www.w3schools.com/js/tryit.asp?filename=tryjs_validation_js

    or you can try this by using any jquery library for form validation:

    http://formvalidator.net/

    for demo : http://formvalidator.net/#reg-form

    评论
    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题