2016-04-21 82 views
2
<div id="background"> 
    <div class="form-group"> 
    <label for="usr" style="position:fixed;margin-top:180px;margin-left:900px;"><u>Account ID</u>:</label> 
    <input type="text" placeholder="Enter your ID in here" class="form-control" id="usr" style="position:absolute;width:350px;margin-top:205px;margin-left:900px;">  
    </div> 
    <div class="form-group"> 
    <label for="pwd" style="position:fixed;margin-top:230px;margin-left:900px;"><u>PIN</u>:</label> 
    <input type="password" placeholder="Enter your PIN in here" class="form-control" id="pwd" style="position:absolute;width:350px;margin-top:255px;margin-left:900px;"> 
    <button type="submit" onClick="process_Login()" class="btn btn-default" style="font-weight:bold;font-family:Tahoma, Geneva, sans-serif;position:fixed;margin-left:1040px;margin-top:310px;width:100px;">Login</button> 
    <button type="submit" class="btn btn-default" style="font-weight:bold;font-family:Tahoma, Geneva, sans-serif;position:absolute;margin-left:1150px;margin-top:310px;width:100px;">Sign Up</button> 
    </div> 
</div> 

我对这段代码有一些问题,我在网上做了一个ATM可视化。我想从HTML文件传输数据到PHP文件,我知道我必须使用“表单”,但我不知道如何在这种情况下使用它,我也使用“脚本”来解决,如果用户输入一个不正确的值。在这种情况下,如何将数据从html传输到php

<script> 
    function process_Login() { 
    var c = document.getElementById("usr").value; 
    var d = document.getElementById("pwd").value; 
    if (c.length == 0) { 
     alert("ERROR: Your ID account is NULL"); 
    } else if (isNaN(c)) { 
     alert("ERROR: Your ID must be number"); 
    } 
    } 
</script> 

我该怎么办才能修复它?

+0

在process_Login方法中创建一个表单对象,然后附加数据并发布 –

+0

按照你的想法,我已经在我的

1

如果你正在做一个表,你会将其发布到您的PHP脚本。 你的投入将需要有一个name属性,即

<form action="myPHPLogin.php" method="post"> 
    <input type="text" placeholder="Do this.." name="username"> 

    <button type="submit">submit</button> 
</form> 

在你的PHP脚本,你可以用$ _POST [ '用户名']等访问你的领域

+0

非常感谢你,我做到了! –

0
<div id="background"> 
<div class="form-group"> 
<form method="post" id="dataForm"> 
<label for="usr" style="position:fixed;margin-top:180px;margin-left:900px;"><u>Account ID</u>:</label> 
    <input type="text" placeholder="Enter your ID in here" class="form-control" id="usr" name="user" style="position:absolute;width:350px;margin-top:205px;margin-left:900px;">  
</div> 
<div class="form-group"> 
    <label for="pwd" style="position:fixed;margin-top:230px;margin-left:900px;"><u>PIN</u>:</label> 
    <input type="password" placeholder="Enter your PIN in here" class="form-control" id="pwd" name="pass" style="position:absolute;width:350px;margin-top:255px;margin-left:900px;"> 
    <button type="button" onClick="process_Login()" class="btn btn-default" style="font-weight:bold;font-family:Tahoma, Geneva, sans-serif;position:fixed;margin-left:1040px;margin-top:310px;width:100px;">Login</button> 
    <button type="button" class="btn btn-default" style="font-weight:bold;font-family:Tahoma, Geneva, sans-serif;position:absolute;margin-left:1150px;margin-top:310px;width:100px;">Sign Up</button> 
    </form> 
</div> 

//your javscript 
function process_Login() { 
var c = document.getElementById("usr").value; 
var d = document.getElementById("pwd").value; 
if (c.length == 0) { 
    alert("ERROR: Your ID account is NULL"); 
} else if (isNaN(c)) { 
    alert("ERROR: Your ID must be number"); 
} 

$.ajax({url:"your php page.php",type:'POST',data:$("#dataForm").serialize(),success: function(data){ 

    if(data==0){alert("No data Added");} 
    }}); 

}

//on your php page 
<?php 
$user=$_POST['user']; 
$pass=$_POST['pass']; 
//you database query for insert 

if($result) 
{ 
    echo "inserted"; 
} 
    else 
{ 
    echo 0; 
} 
?> 
相关问题