맞아요, 이것은 매우 기본적인 PHP 여야합니다. 그러나 나는 이것이 왜 작동하지 않는지 알아낼 수 없습니다.
제출할 때 필드를 잡고 데이터베이스에 데이터를 삽입해야하는 양식이 있습니다. 내 index.php에 실제로 데이터베이스에서 정보를 가져오고 잘 작동하는 섹션이 있으므로 이것이 연결 문제라는 것을 알 수 없습니다.
db_connection.php 나는 여기에 내 데이터베이스에 대한 정보를 해시했지만 모든 것이 정확합니다.
<?php
define("DB_SERVER","**********");
define("DB_USER","*************");
define("DB_PASS","*********");
define("DB_NAME","reviews");
$connection = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
if(mysqli_connect_errno()){
die("database connection failed");
}
?>
functions.php
<?php
function redirect_to($new_location) {
header("Location: " . $new_location);
exit;
}
function confirm_query($result){
if(!$result){
die("database query failed");
}
}
function find_reviews($connection){
$query = "SELECT * ";
$query .= "FROM reviews";
$result = mysqli_query($connection,$query);
confirm_query($result);
while($reviews = mysqli_fetch_assoc($result)){
$output = "<li class=\"first\">";
$output .= $reviews["name"];
$output .= "</li>";
$output .= "<li class=\"second\">";
$output .= $reviews["company"];
$output .= "</li>";
$output .= "<li class=\"third\">";
$output .= $reviews["comment"];
$output .= "</li>";
$output .= "<li class=\"line\"></li>";
echo $output;
}
mysqli_free_result($result);
return $reviews;
}
?>
index.php 를 참고하면 find_reviews () 함수가 작동하고 데이터베이스에서 정보를 가져옵니다. 또한 위의 "db_connection.php"및 "functions.php"가 index.php에 필요합니다.
<?php
require("includes/header.php");
$page_title = "All County Road Markings";
$description = "Specialising in Road Marking & Car Park Lining. We are a professional established road marking service with over 20 years experience";?>
<?php require("includes/db_connection.php"); ?>
<?php require("includes/functions.php"); ?>
<?php if(isset($_POST["submit"])){
$name = $_POST["name"];
$company = $_POST["company"];
$comment = $_POST["comment"];
$query = "INSERT INTO `reviews` (name,company,comment) VALUES ('$name','$company','$comment')";
$result=mysqli_query($connection,$query);
confirm_query($result);
redirect_to("index.php");
}
?>
<div id="banner"></div>
<div id="paragraph">
<h2>All County Road Markings are a professional established road marking<br>service with over 20 years experience within the industry</h2>
<hr style="width: 1050px;">
</div>
<div id="content">
<div id="left">
<div class="slot">
<div class="top carpark"> </div>
<div class="linkbar">
<h1>Car Parks</h1>
</div><div class="linktext">
<ul class="comments display">
<li>- Car Parking Bays</li>
<li>- Disabled Parking Bays</li>
<li>- Parent and Child Bays</li>
<li>- Lettering</li>
<li>- Hatchings</li>
<li>- Arrows</li>
<li>- Customised Lettering</li>
</ul>
</div>
</div>
<div class="slot">
<div class="top roadmark"> </div>
<div class="linkbar">
<h1>Road Markings</h1>
</div>
<div class="linktext">
<ul class="comments display">
<li>- Hatchings</li>
<li>- Centre Lines</li>
<li>- Double Yellow lines</li>
<li>- Give way junctions</li>
<li>- Reinstatement of existing markings</li>
</ul>
</div>
</div>
<div class="slot">
<div class="top sportcourt">
</div>
<div class="linkbar">
<h1>Sports/Playground Court</h1>
</div>
<div class="linktext">
<ul class="comments display">
<li>- Tennis Court</li>
<li>- Basketball Court</li>
<li>- 5 A side Court</li>
<li>- Netball Court </li>
<li>- Reinstatement of existing markings</li>
<li>- Custom designs available</li>
</ul>
</div>
</div>
</div>
<div id="right">
<div id="rightbar">
<h2 style="color: white;">Testimonials</h2>
</div>
<div id="comment">
<ul class="comments">
<?php echo find_reviews($connection); ?>
</ul>
</div>
<div id="write">
<p style="margin: 0px; padding-top: 5px;color: grey; font-size: 1.25em;">Click to write a review...<p>
</div>
</div>
<a href="contact.php"><div id="quote"><div class="link-text">contact us</div></div></a>
</div>
<div id="add">
<div id="close"></div>
<form action="index.php" method="POST">
<div id="name"> Name:<br/><span>Please Enter Full Name</span>
<input type="text" name="name" id="textbox">
</div>
<div id="company"> Company<br/><span>Please Enter Company Name</span>
<input type="text" name="company" id="textbox1">
</div>
<div id="review"> Review<br/><span>Please Enter Review</span>
<textarea name="comment" id="reviewComment"></textarea>
</div>
<div id="save">
<input type="submit" name="submit">
</div>
</form>
</div>
</body>
</html>
좋아요, 누구든지 내가 잘못하고있는 것을 볼 수 있습니까? 양식이 제출 될 때 데이터베이스에 삽입되지 않습니다.
편집하다::
echo mysqli-> error; 다음과 같은 오류가 발생합니다.
Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /hermes/bosoraweb140/b484/ipg.allcountyroadmarking/index.php on line 17
그래서 나는 그것을
if(!results){
echo "hello";
}
그리고 "안녕하세요"가 보이지 않아서 포스트 필드를 다루는 부분에 들어가지도 않았 음을 나타냅니다.
자체 해결 :::::
나는 그것을 고쳤고, 나는 action = "index.php"를 action = ""로 변경했다.
이해가 안되지만 작동 했어야했지만 어떤 이유로 작업 공백이 작동했습니다. 둘 다 수용 가능해야합니다!
설정된 폼 액션
<form action="index.php" method="POST">
작동하지 않았지만 현재 페이지를 참조하는 이유를 알 수 없습니다.
그러나 이것을 변경하면 문제가 해결되었습니다.
<form action="" method="POST">
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다