2016-04-21 1 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> 

übertragen Ich habe ein paar Probleme mit diesem Code, ich mache ein ATM Visual Web. Ich möchte Daten von HTML-Datei zu PHP-Datei übertragen, ich weiß, ich muss "Formular" verwenden, aber ich weiß nicht, wie man es in diesem Fall verwendet, ich benutze auch "Skript" zu lösen, wenn Benutzer einen falschen Wert eingeben.Wie kann ich Daten von HTML zu PHP in diesem Fall

<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> 

Was soll ich tun, um es zu beheben?

+0

Erstellen Sie ein Formularobjekt in der Methode process_Login und dann Daten anhängen und Post –

+0

folgen Sie Ihrer Idee, ich muss ein Formular in meinem

1

Wenn Sie ein Formular tun, werden Sie posten Sie es in Ihrem PHP-Skript. Ihre Eingaben müssen ein Namensattribut haben, das heißt,

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

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

auf Ihrem PHP-Skript, können Sie Ihre Felder mit $ _POST zugreifen [ 'username'] usw.

+0

danke dir so sehr, ich habe es geschafft! –

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; 
} 
?> 
Verwandte Themen