我的mysql数据库是空的,没有创建表格,数据写在上面,请帮助,谢谢!在这里,对不起,我是一个新手:
function mySelectVal(res1, res2) {
$('#stat1').change(function() {
$('#row_dim')[($("option[value='"res1 "']").is(":checked")) ? "show" : "hide"]();
});
}
答案 0 :(得分:1)
使用它:
$servername = "server";
$username = "username";
$password = "pass";
$dbname = "db name";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}else{
// sql to create table
$sql = "CREATE TABLE IF NOT EXISTS data (
id INT(6) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
link text NOT NULL,
title text NOT NULL,
description text NOT NULL,
internal_link text NOT NULL,
eg_date TIMESTAMP) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1";
if(mysqli_query($conn,$sql)){
$sql = "INSERT INTO data (title) VALUES ('".$title."')";
mysqli_query($conn,$sql);
}else{
echo "Error creating table: " . mysqli_error($conn)."<br/>";
}
}
mysqli_close($conn);
但要注意你应该在临时文件中使用这些代码。只使用一次!如果你想在你的数据库上放置数据,那么创建一个像yourpage.php这样的php文件作为你的面板。然后在其中创建一个面板。所以你可以在桌面上插入数据,这很简单。这是一个简单的样本:
<?php
$server_name='';
$username='';
$password='';
$db_name='';
$conn=mysqli_connect($server_name,$username,$password,$db_name);
if(isset($_GET['add_record'])){
if(isset($_GET['title']) && $_GET['title']!=NULL){
if(isset($_GET['description']) && $_GET['description']){
// TODO : for security reason I use these filters for getting strings
$title=mysqli_real_escape_string($conn,htmlspecialchars($_GET['title']));
$des=mysqli_real_escape_string($conn,htmlspecialchars($_GET['description']));
$sql="INSERT INTO data(title,description) VALUES ('".$title."','".$des."')";
mysqli_query($conn,$sql);
header("location:yourpage.php");
}
}
}
?>
<!DOCTYPE html>
<html>
<head></head>
<body>
<form method="get">
<input type="text" name="title" placeholder="title">
<input type="text" name="description" placeholder="description">
<input type="submit" name="add_record" value="Save it!">
</form>
</body>
</html>
答案 1 :(得分:0)
您必须通过代码中无处的mysqli_query()
执行查询。
答案 2 :(得分:0)
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection using
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// sql to create table
$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
// for inserting the values
if (mysqli_query($conn, $sql)) {
echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . mysqli_error($conn);
}
$sql_qry="INSERT INTO data (title) VALUES ('$title')";
if (mysqli_query($conn, $sql_qry)) {
echo "values added successfully";
} else {
echo "data can't be added";
}
mysqli_close($conn);
?>
试试这个并用你的代码更改连接代码和所有内容..祝你好运。