php / sql - 使用PHP将数据插入表中(Bootstrap Form,如果这有所不同)

时间:2017-04-19 22:17:47

标签: php mysql sql

底线:我不知道我到底在做什么。我只想要这个评论框将信息提交到我的数据库。让我告诉你我得到了什么。

<form method="POST" action="post.php" style="font-
 size:200%;padding:50px">
<label for="comments">Comments:</label>
<textarea class="form-control" placeholder="How can I improve?" 
 style="background-color:#fff4c9;border-radius:15px;width:100%;" 
 name="comments" rows="5" id="comments" value=""></textarea> <br>
<button type="submit" class="btn btn-default">Share Your Ideas</button>
</form>`

然后我的php我想????

<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
$servername = "localhost";
$username = "id1403626_wp_4764008ac42f7398450c24184e47c38a";
$password = "blahblahblah";
$dbname = "id1403626_wp_257ecd760342ffcefce424435ed4e776";
//Collect Value of Input Field
$name = $_POST['comments'];
$timestamp = date('Y-m-d H:i:sa');

//Create connection
$connect = mysqli_connect($servername, $username, $password);

//Check connection
if ($connect->connect_error) {
die("So here's the problem...:".$connect->connect_error);
}
//Select Database
mysqli_select_db($connect,$dbname)
or die("Whoops! Can't find that pesky database!");
//Insert Data Query
$sql = "INSERT INTO `Comments`(`comments`, `date`) VALUES ($name, 
$timestamp)";
//What should happen
$result = mysqli_query($connect, $sql);

if($result){
echo 'thank you for your feed back';
}else {
echo "...";
}
}
?>

我只是找不到我做错了什么。

0 个答案:

没有答案