2017-06-09 10 views
0

home.htmlファイル:jQueryのモバイルフォームポストの問題、PHP警告:(ヌル与えられ、パラメータ1はmysqliのことを期待)

ヘッダと固定フッタを持つ2つの単純なjQのモバイルページ。フォームは1ページにあります。私は今のところ "パスワードはパスワードを確認する必要があります"のような規定は追加していません。私はそれをDBで最初に動作させる、つまりDBに格納するだけです。

<!DOCTYPE html> 

<html> 
    <head> 
    <!-- Include meta tag to ensure proper rendering and touch zooming --> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
    <!-- Include jQuery Mobile stylesheets --> 
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> 
<link rel="stylesheet" type="text/css" href="https://example.net/Login/styles.css"> 
    <!-- Include the jQuery library --> 
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> 
    <!-- Include the your Ajax-ify file --> 
<script type="text/javascript" src="https://example.net/Login/functions.js"></script> 
    <!-- Include the jQuery Mobile library --> 
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 
</head> 
    <body> 
        <!--      --> 
        <!-- Page One starts here --> 
        <!--      --> 

<div data-role="page" id="pageone"> 
<div data-role="header" data-theme="b"> 
    <h1>Welcome</h1> 
</div> 

<div data-role="main" class="ui-content"> 
    <br> 
    <br> 
       <!-- Form starts here --> 
    <form id="NewForm" method="post" action="include.php"> 
     <label>Username</label> 
    <input type="text" name="username" placeholder="E.g. JoeB95"> 
    <br> 
     <label>Email</label> 
    <input type="text" name="email" placeholder="E.g. [email protected]"> 
    <br> 
     <label>Password</label> 
    <input type="password" name="password_1" placeholder="E.g. 8969-545a-r3"> 
    <br> 
    <!--Submit button goes below here -->                      
    <div id="register"><input type="submit" name="register" data-inline="true" value="Submit"></div> 
    </form> 
    <br> 
    <p>Already a member?</p> <a href="#pagetwo">Sign In</a> 
    <br> 
    <span id="result"></span> 
    <br> 
    </div> 

    <div data-role="footer" id="foot" data-position="fixed" data-theme="b"> 
    <h1>footer</h1> 
    </div> 
    </div> 
         <!-- Page One ends here --> 
         <!--       --> 
         <!-- Page Two starts here --> 


<div data-role="page" id="pagetwo"> 
<div data-role="header" data-theme="b"> 
    <h1>Welcome</h1> 
</div> 

<div data-role="main" class="ui-content"> 
    <br> 
    <br> 
<p>Not a member?</p> <a href="#pageone">Signup</a> 
    <br> 
</div> 

    <div data-role="footer" id="foot" data-position="fixed" data-theme="b"> 
    <h1>footer</h1> 
</div> 
</div> 

functions.jsファイル:(アヤックス-IFY)

コード形式は以下の通りですAjaxが-ifyingため。ここにエラーがあるかどうかはわかりません。

// AJAX-ify the form 
$(document).on("pagecreate","#pageone",function() 
{ 

$("#register").click(function() { 
    $.post($("#NewForm").attr("action"), 
    $("#NewForm :input").serializeArray(), 
     function(info){ $("#result").html(info); 
    }); 
}); 

$("#NewForm").submit(function() { 
    return false; 
    }); 
}); 

をdb.phpファイル:それはDBに接続し、私は前にそれを使用していたとして

このコードは、作業を行います。

<?php 

//put your connection code here 
     $servername = 'localhost'; 
     $username = 'admin_example'; 
     $password = '123456-7'; 
     $dbname = 'example_DB'; 

    // create connection 
    $conn = new mysqli($servername, $username, $password, $dbname); 

    // Check connection 
    if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 
    } 
    echo "Connected successfully, <br>"; 
?> 

include.phpファイル:

私は問題があると考えているところです。 error_logでは、問題領域として8行目と11行目を指しています。

PHP警告:mysqli_query()は空行8

PHP警告上のpublic_html /ログイン/ include.phpに与え、パラメータ1はmysqliのことを期待:mysqli_error()ヌル、パラメータ1はmysqliのことを期待しますpublic_html/Login/include.php on line 11で指定されています。

これらのエラーに関する似たような話題がありますが、私はそれを直接私のものに関連付けることはできませんでした。誰が問題が何であるかを示唆することができ、何を変更する必要がありますか?ありがとう。

<?php 
    $user = $_POST['username']; 
    $email = $_POST['email']; 
    $password_1 = $_POST['password_1']; 

    $access = md5($password_1); 
    $sql = "INSERT INTO users (`username`, `email`, `password`) VALUES ('$username', '$email', '$password_1')"; 
    if(mysqli_query($conn,$sql)){ 
     echo "Successfully Inserted"; 
    } else { 
     echo ("Error description: " . mysqli_error($conn)); 
    } 
?> 
+1

例でコードが見つからない限り、include.phpの '$ conn'はnullです。接続はdb.phpで動作しますが、include.phpはその '$ conn'にアクセスできません。クエリ呼び出しの前にinclude.phpにdb.phpを含めるか/要求してみてください。 – cteski

答えて

1

home.htmlファイルは、フォームアクションによってinclude.phpを呼び出します。ただし、include.phpはdb.phpファイルを呼び出しません。あなたのinclude.phpファイル内

require db.php;

:あなたのような何かが欠けている表示されます。これがなければ、10行目のdb.phpに設定された$ conn変数はinclude.phpファイルには表示されません。これがエラーの原因です。

+0

ありがとうございます!それはそれと同じくらい簡単なものでした。乾杯。 – Skin99

関連する問題