0
我想知道是否有任何善良的人可以帮我解决我的php难题!我非常非常新的PHP,我不明白如何添加一个功能的评论部分。我制作了一个数据库表(名为'comments')来存储用户提交的所有评论。我不确定这些东西: 1.如何将评论部分(在php页面 - home.php)连接到我的数据库表(评论) 2.如何使人张贴的评论贴到相同的页面 - home.php使用php和html添加注释
我做错的现在,当我在网址栏中输入这个错误出现
Parse error: syntax error, unexpected '{', expecting '(' in .../home.php on line 34
无论如何,我希望有人能帮帮我! 感谢
<?php
session_start();
if (!isset($_SESSION['logged'])){
$_SESSION = array();
session_destroy();
header('location: home_start.php'); //your login form
require_once("functions.php");
include_once("home_start.php");
require_once("db_connect.php");
}
//EXISTING DATABASE CONNECTION CODE
//if (!$db_server){
//die("Unable to connect to MySQL: " . mysqli_connect_error($db_server));
}else{ $ db_status = "not connected";
//NEW SUBMISSION HANDLING CODE HERE
//if(trim($_POST['submit']) == "Submit"){
//}//EXISTING CODE (to create the options list) HERE...
//}
require_once('recaptcha/recaptchalib.php');
$privatekey = " 6Lem4-gSAAAAADsaa9KXlzSAhLs8Ztp83Lt-x1kn";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
$message = "";
if (!$resp->is_valid) {
$message = "The reCAPTCHA wasn't entered correctly. Go back and try it again (reCAPTCHA said: " . $resp->error . ")";
} else {
// ADD YOUR CODE HERE to handle a successful ReCAPTCHA submission
// e.g. Validate the data
$unsafe_name = $_POST['fullname'];
}
$message .= "Thanks for your input $unsafe_name !";
echo $message;
if {
$bedrooms = $_POST['year'];
$bedrooms = clean_string($db_server, $year);
$comment = clean_string($db_server, $_POST['comment']);
else ($comment != "") {
$query2 = "INSERT INTO comments (comment) VALUES ('$comment')";
mysqli_query($db_server, $query2) or
die("Insert failed: " . mysqli_error($db_server));
$message = "Thanks for your comment";
}
$query3 = "SELECT * FROM comments";
$result3 = mysqli_query($db_server, $query3);
while($array = mysqli_fetch_array($result3)){
$comments = date('d/m/Y', strtotime($array['commDate'])) . "<p>" . $array['comment'] . "</p><br/>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="home.css" rel="stylesheet" type="text/css"/>
<title>Home</title>
</head>
<body>
<div id="middle">
<h2><strong>HELLO!</strong></h2>
<h2>Welcome to <strong>Cosy Cribs</strong> website!</h2>
<p>This website combines all the possible lettings available to YOU from the most prefered letting companies in the great city of Leeds!</p>
<p>It was recognised that when students attempt to let a house for the next year, there were far too many different websites and companies visit; making the whole ordeal of finding a house more stressful then needs be!</p>
<p>We, at <strong>Cosy Cribs</strong>, decided that your lives needed to be made easier, and so we announce a website that provides you with all of the lettings from these different companies - all on one website - and links to the house you like.</p>
<h2>ENJOY!</h2>
</div>
<form id="comments" action="home.php" method="post">
<select name="comments">
</select>
<h1>Do you have a comment on preferred company or number of bedrooms?</h1>
Comment: <textarea rows="2" cols="30" name="comment"></textarea>
<?php echo $recaptcha_form; ?>
<input type="submit" id="submit" name="submit" value="Submit form" />
</form>
</body>
</html>
太谢谢你了!它现在说我没有错误!但我现在有错误reCAPTCHA输入不正确。回去再试一次。 (reCAPTCHA说:不正确的captcha溶胶)感谢您的输入! 警告:mysqli_error()期望参数1为mysqli,null在第41行的/home/fh11alb/public_html/home.php中给出012, 警告:mysqli_error()期望参数1为mysqli,null在...中给出/ 42线上的home.php 插入失败: – Ash
你在哪里定义变量'$ db_server'?它似乎失踪了。 – Rikesh