HTML表单不使用PHP将数据发送到MySQL

前端之家收集整理的这篇文章主要介绍了HTML表单不使用PHP将数据发送到MySQL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个 HTML格式的表单,但它的设置并不像我想的那样正常.我将发布代码形式的HTML( PHP)文件PHP将其发送到数据库.
<form action="upload.PHP" method="POST">
    <!-- Name input-->
    <div class="form-group">
      <label class="control-label" for="name">Name</label>
      <div class="">
        <input id="name" name="name" placeholder="First and Last Name" class="form-control input-md" type="text" required>
      </div>
    </div>
    <div class="form-group">
        <label class=" control-label" for="supportingDoc">Upload Supporting Documentation</label>
        <div class="">
            <input id="supportingDoc" name="supportingDoc" class="input-file" type="file" style="margin-top: .5em; margin-left: 4em;">
        </div>
    </div>
    <hr>
      <!-- Submit -->
      <div class="form-group">
        <label class="control-label" for="submit"></label>
        <div class="">
          <button value="Submit" type="submit" id="submit" name="submit" class="btn btn-danger" style="border-radius: 25px;">Submit</button>
        </div>
      </div>
</form>

这是我的sql / PHP

<?PHP
    $servername = "localhost";
    $username = "xxx";
    $password = "xxx";
    $dbname = "xxx";
    // Create connection
    $con = MysqLi_connect("localhost","xxx","xxx");
    // Check connection
    if (MysqLi_connect_errno()){
        echo "Failed to connect to MysqL: " . MysqLi_connect_error();
    }

    if (isset($_REQUEST['name'])){
        // set variables

        $name = MysqL_real_escape_string($_POST['name']);
        $supportingDoc = MysqL_real_escape_string($_POST['supportingDoc']);

        $sql = "INSERT INTO `tablew` (name,supportingDoc) VALUES ('$name','$supportingDoc')";
        $result = MysqLi_query($con,$sql);

        if ($con->query($sql) === TRUE) {
            echo "New record created successfully";
            printf("New record created successfully");
        } else {
            echo "Error: " . $sql . "<br>" . $con->error;
            printf("Error: " . $sql . "<br>" . $con->error);
        }

        $con->close();
    }
?>

我尝试了各种各样的变化,在PHPmyadmin中没有显示任何内容.我甚至从我之前创建的网站复制了它仍然没有工作大声笑.

我看到有登录信息的变量并且仍然把它放在MysqLi中,但是我现在已经在这一件事情大约8个小时了,并且没有果汁,所以希望有人看到我搞砸了.

在此先感谢大家的帮助.

================================================== =========================
更新:
我做了上面提到的所有更改,现在得到这个:

警告:MysqLi_connect():( HY000 / 1049):未知数据库

我可以在PHPmyadmin和Sequel Pro中看到数据库.我还确保设置密码并登录“root”.我的代码如下登录

$con = MysqLi_connect("localhost","root","epboarding");
// Check connection
if (MysqLi_connect_errno())
{
    echo "Failed to connect to MysqL: " . MysqLi_connect_error();
}

这是我的帖子:

if (isset($_REQUEST['submit'])){
// set variables
$name = MysqLi_real_escape_string($con,$_POST['name']);
$sql = "INSERT INTO `wos` (name) VALUES ('$name')";
$result = MysqLi_query($con,$sql);

解决方法

以下问题可以在那里:

>上传错误.在表单标记中使用enctype =“multipart / form-data”.>更正MysqL_connect详细信息,即用户名,密码,Dbname.> MysqL_real_escape_string被删除.使用MysqLi.>重新检查列名,即name,supportingDoc.

原文链接:https://www.f2er.com/html/225471.html

猜你在找的HTML相关文章