2017-06-09 17 views
0

home.html的文件:jQuery Mobile的表单提交问题,PHP的警告:(预计参数1是mysqli的,空给出)

两个简单的JQ移动网页具有页眉和页脚固定。表格在第一页。我现在没有添加任何“密码必须匹配确认密码”的规定。我只想让它首先与数据库一起工作,即存储在数据库中。

<!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文件:(Ajax的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中的文件:

此代码的工作,因为它与数据库连接和我以前用过它。

<?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()预计参数1是mysqli的,在的public_html /登录/ include.php空给定第8行

PHP警告:mysqli_error()预计参数1是mysqli的,空在第11行的public_html/Login/include.php中给出

我知道有关于这些错误的类似主题,但我不能直接将它与我的关联。任何人都可以提出什么问题,需要改变什么?谢谢。

<?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文件。看来你失去了一些东西,如:

require db.php;

在include.php文件

。没有它,第10行的db.php中设置的$ conn变量在include.php文件中是不可见的。这是导致错误。

+0

谢谢!这件事很简单。干杯。 – Skin99

相关问题