gpt4 book ai didi

PHP 不插入到 MYSQL 表

转载 作者:行者123 更新时间:2023-11-29 06:07:02 29 4
gpt4 key购买 nike

我有一个 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 | |
+-----------+-------------+------+-----+---------+-------+

我不知道我做错了什么!请帮忙。

最佳答案

您似乎没有为 CProfile 提供值,这可能会导致某种错误。

关于PHP 不插入到 MYSQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11034373/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com