使用この:あなたは一時ファイルにこれらのコードを使用する必要があります
$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>
'$ sql =" ... "'は自動的に何もしません。つまり、クエリを実行します。 –
あなたはクエリを実行しなければならない何かが発生する –
あなたはちょうどクエリを書いた、それをexcuteしなかった –