php - 如何存储由用户服务器端(mySQL)创建的 <li>-item

标签 php mysql database

我有一个简单的<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/

相关文章:

Php排行榜问题

php - Laravel 关系返回 null

c# - 使用 C# 在 MySQL 数据库中查找具有特定 id 的行

database - PostgreSQL : how to delete rows of Table1 where category = x (but Category is defined in Table 2)?

php - 升级后的 jwt-auth - 从请求 token 获取用户

PHP 需要帮助来过滤日志文件

php - PHP 中何时关闭连接?

mysql句点(.)搜索模式

php - Mysql服务器数据插入错误

sql - SQL Server 2005发送邮件