我想將輸入的數據以html格式發送到我的sql數據庫,即創建一個新的行,將某些值賦予某些列。我知道有類似的問題,我讀了答案,但似乎沒有任何工作。通過PHP發送html格式數據到sql數據庫(使用mysqli)
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
上
我已經嘗試將值發送到所有分支,包括pid
,並按「正確」順序發送。
mysqli_connect
部分不是問題,因爲我從我的另一個.php文件複製它的作品。
服務器php-sql的兼容性也不是問題,因爲我成功地有一個不同的.php文件從數據庫中檢索數據(手動插入的數據)。
當你說什麼都沒有工作,什麼是不工作?你得到一個錯誤,數據庫中的錯誤數據等? – 2013-03-11 05:03:16
我的意思是沒有任何解決方案提供的答案來自不同的問題。我沒有收到錯誤輸出。 – Alex 2013-03-11 05:08:57