2016-03-23 11 views
1

私は、PHP、Ajax、およびその他すべての機能を使ってウェブデザインに取り掛かりつつあります。私は、ユーザー名とパスワード(または任意のフィールド)を格納されたデータベースに印刷する基本的なシステムを作成しようとしています。 (私はこれが安全ではないことを知っています、それはちょうど初心者のプロジェクトです。)それは非常に矛盾しているようです。フィールドAとフィールドBは必ずしもデータベースに印刷されるわけではありません。ときどきそれは何度も印刷されることがあり、まれに印刷されないこともあります。ここではあなたが必要な場合がありますコードは次のとおりです。入力フォームに不一致がありますか?

<form class="_rwf8p" data-reactid=".0.0.0.0.1.2"> 
    <div class="_ccek6 _i31zu" data-reactid=".0.0.0.0.1.2.0"> 
    <input class="_kp5f7 _qy55y" aria-required="true" autocapitalize="off" id="Username" name="Username" type="username" placeholder="Username" value="" autocorrect="off" spellcheck="false" class="" data-reactid=".0.0.0.0.1.2.0.0" type="text" /> 
    </div> 
    <div class="_ccek6 _i31zu" data-reactid=".0.0.0.0.1.2.1"> 
    <input class="_kp5f7 _qy55y" aria-required="true" autocapitalize="off" id="Passwd" name="Passwd" type="password" placeholder="Password" value="" autocorrect="off" spellcheck="false" class="" data-reactid=".0.0.0.0.1.2.1.0" type="password" /> 
    <div class="_j4ox0" data-reactid=".0.0.0.0.1.2.1.1"> 
     <a class="_19gtn" href="/accounts/password/reset/" data-reactid=".0.0.0.0.1.2.1.1.0"> 
     Forgot? 
     </a> 
    </div> 
    </div> 
    <button class="_rz1lq _k2yal _84y62 _7xso1 _nv5lf" data-reactid=".0.0.0.0.1.2.2"> 
    Log in 
    </button> 
</form> 
<script> 
     $("html").keypress(function(event) { 
      if(event.keyCode == 13) { 
      saveCridentials(); 
      } 
     }); 

     $("#signIn").click(function() { 
      saveCridentials(); 
     }); 

     function saveCridentials() { 
      $.ajax({ 
      type: "POST", 
      url: "log.php", 
      data: { "username" : $("#Username").val(), "password" : $("#Passwd").val() }, 
      dataType: "json" 
      }); 

      $("#Username").val(""); 
      $("#Passwd").val(""); 
     } 
</script> 

PHP:

<?php 
    $username = $_POST['username']; 
    $password = $_POST['password']; 

    fwrite(fopen('cridentials.txt', 'a'), "Username: ". $username . " Password: ". $password . "\n"); 
?> 

すべてのヘルプは、おかげで、本当に素晴らしいことです!

+0

フォーム送信をキャンセルしないでください。問題が発生する可能性があります。 – epascarello

答えて

-1
"I am trying to make a basic system that prints a username and password (or any fields) to a stored database" 

Why not try just php and MySql 

First you will have to connect to your database: 

<?php 
/* Database config */ 

$db_host  = 'localhost'; 
$db_user  = 'yourinput'; 
$db_pass  = 'yourinput'; 
$db_database = 'yourinput'; 

     $link = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection'); 

    mysql_select_db($db_database,$link); 
    mysql_query("SET names UTF8"); 

    // Now lets say a user is trying to register with username and password, basically the same concept as what you would be trying to do. 

    if($_POST['submit']=='Register') 

    mysql_query(" INSERT INTO registered(usr,pass) 
        VALUES('".$_POST['usr']."','".md5($pass)."')"); 

    // This would plug the values of the username and password, which is a randomly generated password but you could figure out how to conform it to the way you want. 
    // Most important your database has to be set up correctly. Check out this link http://dev.mysql.com/doc/refman/5.7/en/database-use.html , phpMyAdmin work great when working with data bases as well. 
    // Now, you HTML code has to written correctly. Your input form must be configured correctly to correspond to your php code & database. In your case you are simply trying to get the username and password into the database. Your id in your form has to be the same as you database and php code. 

    <input class="field" id="username" name="username" size="23" type="text" value=""> 
    <input class="field" id="password" name="password" size="23" type="text" value=""> 

    //If that doesn't help take a look at: https://www.eduonix.com/blog/web-programming-tutorials/learn-submit-html-data-mysql-database-using-php/ 
関連する問題