gpt4 book ai didi

php - 如何存储由用户服务器端(mySQL)创建的
  • -item
  • 转载 作者:行者123 更新时间:2023-11-29 19:22:05 25 4
    gpt4 key购买 nike

    我有一个简单的<ul>您可以在其中添加带有输入字段的列表项:

    $('#plannerform').submit(function(e) {
    var val = $(this).find('#plannername').val();
    $('ul.plannerlist:visible').append('<li>' + val + '</li>');
    e.preventDefault();
    });

    我的问题是:是否可以通过某种方式将这个创建的列表保存在网络服务器上的 mySQL 数据库上?我在 PHP 或其他服务器端存储语言方面没有太多经验。如果可能的话,您能告诉我任何解释它的链接吗?我已经花了一些时间进行搜索,但我没有找到任何东西,因为我根本不知道要搜索什么。

    最佳答案

    这是我编写的一个简单的 PHP 脚本,用于连接到我的 MySQL 数据库,并检索并显示给定列中的每个结果。

    只需替换:如果 MySQL 安装在您的本地计算机上,则主机名可能是您的本地 IP。您的 MySQL 用户名,如果您没有创建其他用户,则可能是 root。密码,如果您没有创建密码,则该密码可能为空。数据库名称为您的数据库名称。

    <?php 

    //Connect to DB
    $conn = new mysqli("Hostname","Username","Password","Database");

    //If the connection has errors
    if ($conn->connect_error){
    //Display the error
    die("Connection failed because: " . $conn->connect_error);
    }

    //Otherwise the connection is good so lets create a sql query
    $sql = "SELECT * FROM Database";

    //Get the results of the query
    $result = $conn->query($sql);

    //If the results have rows
    if($result->num_rows > 0){

    //While there are more rows in the results
    while($row = $result->fetch_assoc()) {

    //Display in HTML paragraph form: Column1 = DataInColumn1
    echo '<p> Column1 = ' . $row["Column1"] . ' </p>';

    }//End While
    }//End If

    //Otherwise the query had no results
    else{
    echo '<p>No results found!</p>';
    }
    ?>

    关于php - 如何存储由用户服务器端(mySQL)创建的 <li>-item,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42378041/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com