php / ajax成功和错误消息

时间:2017-03-31 00:41:59

标签: php html

我已经在数据库上工作了几个星期,我无法让我的PHP代码工作。我创建了一个数据库,用于将新的借用者信息输入库数据库。我想成功!如果填写了所有字段则发布消息,如果任何字段为空则显示错误消息。在此之后,我想合并ajax,以便在HTML页面上填充成功和失败消息,而不打开第二页。任何帮助,将不胜感激。我的HTML和PHP代码如下。

HTML:

<body>
<form action="Addborrowerinfo.php" method="post">
    <fieldset>
        <legend><strong>Enter New Borrower Information</strong></legend>
        <legend>The form  below is used to send  data to  be stored in the database</legend>
        <p> Enter data in the  fields below and press Submit to add a new record to the database. To see the information you just entered, go back to the gather all data link below</p>

        <p>BorrowerID: <input type="text" name="BorrowerID" /></p>
        <p>First Name: <input type="text" name="FirstName" /></p>
        <p>Last Name: <input type="text" name="LastName" /></p>
        <p>Address: <input type="text" name="Address" /></p>
        <p>Phone Number: <input type="text" name="PhoneNumber" /></p>
        <p> <input type="submit" value="Submit"/> </p>
    </fieldset>
</form>

PHP:

<?php
(connection info)

$BorrowerID = mysql_real_escape_string($_POST["BorrowerID"]);
$FirstName = mysql_real_escape_string($_POST["FirstName"]);
$LastName = mysql_real_escape_string($_POST["LastName"]);
$Address = mysql_real_escape_string($_POST["Address"]);
$PhoneNumber = mysql_real_escape_string($_POST["PhoneNumber"]);

$insert = mysql_query("INSERT INTO duf47_library.Borrowers (BorrowerID, FirstName, LastName, Address, PhoneNumber) VALUES ('$BorrowerID', '$FirstName', '$LastName', '$Address', '$PhoneNumber')");

mysql_close();
?> 

1 个答案:

答案 0 :(得分:0)

这取决于您的(连接信息)。我看到的最重要的事情是mysql_query("sql syntax")应为mysqli_query($db, "sql syntax")。您的数据库未被调用,这在程序php中是必需的。

以下是php手册中示例的链接:http://php.net/manual/en/mysqli.query.php