我有一个简单的 <ul>
,您可以在其中添加带有输入字段的列表项目:
$('#plannerform').submit(function(e) {
var val = $(this).find('#plannername').val();
$('ul.plannerlist:visible').append('<li>' + val + '</li>');
e.preventDefault();
});
我的问题是:是否可以通过在网络服务器上的MySQL数据库上保存此创建的列表的方式?对于服务器侧面存储,我没有太多的PHP或其他语言经验。如果可能的话,您能告诉我任何链接如何解释如何?我已经花了一些时间来搜索,但是我什么都没找到,因为我根本不知道要搜索什么。
这是我写的一个简单的PHP脚本,可以连接到我的mysql db,并在给定列中检索每个结果。
只是替换:如果MySQL安装在本地计算机上,则可能具有本地IP的主机名。您的MySQL用户名,如果您没有创建另一个用户,则可能会扎根。密码,如果您不创建密码,则可能是空白的。带有数据库名称的数据库。
<?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>';
}
?>