我创建了一个评论网站。人们访问它并在其上放置评论,这些评论将被放置在数据库中。
我在网站上创建了一个简单的表单和区域,以便他们能够编辑和删除他们的评论。
但是,我必须从每个用户的数据库中提取他们的评论信息的代码不起作用。我需要替换“WHERE FirstName ='peter'”); ,其中包含允许脚本获取并显示用户在表单上输入的电子邮件提交的评论。< / p>
<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons
**WHERE FirstName='Peter'");**
while($row = mysqli_fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br>";
}
?>
这是html的形式(非常简单,但还没有做很多工作)
<form action="myReviews.php" method="post">
<label>Please enter your email:</label>
<input type="email" id="email" name="email" placeholder="email">
<input type="submit" value="submit">
</form>
我试过用“回声”和中间的一切来解决这个问题!请帮帮我。谷歌搜索它并去教程网站没有好处!我会在找到答案时更新问题。
根据其他用户的帮助更新
我编辑了php脚本,完全按照以下方式阅读:
<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons
WHERE $email = mysqli_real_escape_string($_POST['email']);");
while($row = mysqli_fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br>";
}
?>
我现在在点击表单中的提交后在浏览器中收到此错误。
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/38/10473938/html/review-pratt/business_profiles/myReviews.php on line 106
答案 0 :(得分:0)
我认为您的代码有问题。试试这个:
<?php
$result = mysqli_query($con,sprintf("SELECT * FROM Persons WHERE email = '%s'",mysqli_real_escape_string($con,$_POST['email'])));