Echo SQL查询结果给JS

时间:2016-12-12 22:20:46

标签: php mysql ajax

我试图获得一个简单的SQL查询结果并将其回显给JS,但返回的数据显示为"结果"。

如何在JS中使用SQL查询结果? SQL查询结果应该是一个简单的' 32'

我尝试在复制线程中使用该建议,但我无法使其正常工作。我不认为我需要一个阵列来回应一个结果。

PHP:

<div id="block-1">My <em>id</em> is <strong>block-1</strong></div>
<div id="block-2">My <em>id</em> is <strong>block-2</strong></div>
<div id="block-3">My <em>id</em> is <strong>block-3</strong></div>

&GT;

JS:

<?php 

require "../connectionPages/localConnect.php";

$fName  = $_POST["fName"];
$lName  = $_POST["lName"];
$email  = $_POST["email"];
$pw     = $_POST["pw"];

if($fName == null || $lName == null || $email == null || $pw == null)
    $message = "missing required data";
else
{

    $SQL =  "INSERT INTO `customer/User` (custFName,
                                custLName,
                                custEmail,
                                custPassword)
    VALUES ('$fName', '$lName','$email', '$pw')";

    $mysqli->query($SQL);

    if($mysqli->affected_rows > 0)
        $message = "Record successfully inserted <br><a href='..'>Back to Main Page</a>";

        $SQL = "SELECT max(custID) as ID FROM `customer/User`";
        $result = $mysqli->query($SQL);

        echo $result;

        if($mysqli->affected_rows > 0) 
        {
            $message .= "<input type='text' value='id' id='userID' hidden />";
        }
    else
        $message = "Unable to insert record: " . $mysqli->error;

    $mysqli->close();
}

0 个答案:

没有答案