【发布时间】:2012-06-14 13:40:33
【问题描述】:
我有一个 html 表单、一个 php 脚本和一个 mysql 数据库我希望表单通过 php 脚本发布到 mysql 数据库。我填写表格并提交,但表格保持不变。我在 Ubuntu 上使用 Lamp 设置。
/var/www/add_review.php
<?
$username="user";
$password="password";
$database="database";
$review=$_POST['review'];
$Cname=$_POST['Cname'];
$picture=$_POST['picture'];
$profile=$_POST['Cprofile'];
$location=$_POST['location'];
$ratingImg=$_POST['ratingImg'];
$rating=$_POST['rating'];
$date=$_POST['date'];
$Creview=$_POST['Creview'];
$link=$_POST['link'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO table VALUES ('$review','$Cname','$picture','$location','$ratingImg','$rating','$date','$Creview','$link')";
mysql_query($query);
if($query)
{
echo "Success!";
}
else
{
die(mysql_error());
}
mysql_close();
echo "Review Added!";
echo "<br />";
echo $review;
echo "<br />";
echo $name;
echo "<br />";
echo $picture;
echo "<br />";
echo $profile;
echo "<br />";
echo $location;
echo "<br />";
echo $ratingImg;
echo "<br />";
echo $rating;
echo "<br />";
echo $date;
echo "<br />";
echo $Creview;
echo "<br />";
echo $link;
?>
/var/www/add_review.html
<h1>Add A Drink</h1>
<form action="add_review.php" method="post">
<p>Review # <input type="text" name="review"><br></p>
<p>UserName <input type="text" name="Cname"><br></p>
<p>Picture URL <input type="text" name = "picture"><br></p>
<p>Users Profile URL <input type="text" name = "Cprofile"><br></p>
<p>Location <input type="text" name = "location"><br></p>
<p>Star URL <input type="text" name = "ratingImg"><br></p>
<p>Star Value <input type="text" name = "rating"><br></p>
<p>Date(MMDDYYYY) <input type="text" name = "date"><br></p>
<p>Users Review<br> <textarea name="Creview"></textarea><br></p>
<p>Review Link <input type="text" name = "link"><br></p>
<input type="submit" value="Submit">
</form>
MYSQL 表
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| review | int(11) | YES | | NULL | |
| Cname | varchar(20) | YES | | NULL | |
| picture | text | YES | | NULL | |
| Cprofile | text | YES | | NULL | |
| location | varchar(30) | YES | | NULL | |
| ratingImg | text | YES | | NULL | |
| rating | float | YES | | NULL | |
| date | int(11) | YES | | NULL | |
| Creview | text | YES | | NULL | |
| link | text | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
我不知道我做错了什么!请帮忙。
【问题讨论】:
-
请不要将
mysql_*函数用于新代码。它们不再维护,社区已经开始deprecation process。看到red box?相反,您应该了解prepared statements 并使用PDO 或MySQLi。如果您不能决定,this article 将帮助您选择。如果你想学习,here is good PDO tutorial. -
@Truth,完全会窃取您的评论以备将来使用!
-
好吧,我不知道,我 8 个月前刚学过 MYSQL……你知道当你的“首选”解决方案现在被淘汰并变得“过时”时,你会偷懒,哈哈,我会的赶上 mysqli 但同时你知道这是怎么回事吗?
-
用
date这样的保留字命名列是个坏主意 -
@JohnConde:所有功劳都归功于 PHP 聊天中的 teresko。欢迎你加入:)
标签: php mysql apache ubuntu-11.10