2016-04-21 88 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; 
} 
?>