我想输入到一个html表单中的数据发送到我的SQL数据库,即创建一个新的行归于一定值某些列。 我知道有类似的问题,我读了答案,但似乎没有任何工作。
send_post.php
<?php
//Connecting to sql db.
$connect = mysqli_connect("my host","my user","my passwrod","my db");
//Sending form data to sql db.
mysqli_query($connect,"INSERT INTO posts (category, title, contents, tags)
VALUES ('$_POST[post_category]', '$_POST[post_title]', '$_POST[post_contents]', '$_POST[post_tags]')";
?>
post.html#形式
<form onSubmit="send_post.php" method="post">
<h3>Category:</h3>
<input type="text" name="post_category">
<h3>Post title:</h3>
<input type="text" name="post_title">
<h3>Post tags (a,b,c...):</h3>
<input type="text" name="post_tags">
<h3>Post (use html):</h3>
<textarea rows="20" cols="50" name="post_contents"></textarea>
<input type="submit">
</form>
我的分贝“的帖子”表colums:
pid
title
contents
tags
category
pid
已auto_increment
上
我已经尝试发送值的所有colunes,包括pid
,并在“右”的顺序。
该mysqli_connect
部分不是问题,因为我从我的一个不同的PHP文件的作品复制它。
服务器的PHP-SQL兼容性不是问题,因为相关我成功有不同的PHP文件从DB(这是手动插入数据)中检索数据。