我使用XAMPP和PHP作为基本网站。PHP超级基本内容管理建议请
我已经完成了大部分内容管理部分。
我有一个基本的形式,您可以上传图片并添加所有必要的详细信息。我需要帮助保持格式一致,因为目前有三间房屋,价格和细节以HTML编码。
如何以类似的格式回显细节?
安全性不是问题,因为没有使用任何敏感信息,也不会公开使用。我只需要知道如何以类似的方式来设置细节和图片的格式?
我附上了照片,以便您可以更好地了解我需要的帮助。下面是代码:
<?php
$servername="localhost";
$username="root";
$password="";
$dbname="content_management";
$tbl_name="houses";
$housepic ="housepic";
$houseprice ="houseprice";
$housetype ="housetype";
$houseloc = "houseloc";
$housedesc = "housedesc";
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql="INSERT INTO $tbl_name (picture, price, type, location, description) VALUES ('$housepic','$houseprice','$housetype','$houseloc','$housedesc')";
if (mysqli_query($conn, $sql)) {
echo "";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
<?php
$host="localhost";
$username="root";
$password="";
$db_name="content_management";
$tbl_name="houses";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = "SELECT * FROM $tbl_name";
$result=mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
echo "<img src='" . $row['picture'] . "'>";
echo $row['price'];
echo $row['type'];
echo $row['location'];
echo $row['description'];
}
?>
<div class="housepost">
<img src="img/houses/house_01.jpg">
<h2>£350,000</h2>
<p>2 bedroom detached house for sale</p>
<p>Deanfield Avenue, Henley-on-Thames</p>
<p>Set in the heart of Henley-on-Thames and just a short walk from Henley train station is this rarely available and spacious three bedroom apartment. Offered to the market with no onward chain the property benefits from off road parking.</p>
</div>
<div class="housepost">
<img src="img/houses/house_02.jpg">
<h2>£475,000</h2>
<p>2 bedroom detached bungalow for sale</p>
<p>Fair Mile, Henley-on-Thames</p>
<p>Set in the heart of the town centre in a quiet backwater this delightful single storey detached home is rarely available and well presented.</p>
</div>
<div class="housepost">
<img src="img/houses/house_03.jpg">
<h2>£600,000</h2>
<p>3 bedroom cottage for sale</p>
<p>Remenham Row, Henley-on-Thames</p>
<p>The English Courtyard Association and The Beechcroft Trust - synonymous with the very best in retirement housing since the 1980s. An extremely attractive three-bedroom cottage with landscaped riverside gardens in this much sought after location.</p>
</div>
<?php echo '<div class="housepost">
<img>$row <img>
<h2></h2>
<p></p>
<p></p>
<p>$row</p>
</div>' ?>
</div>
我不知道我用PHP做什么,我很惊讶,我做了这么远,但我有一个初学者理解。您可以在代码中看到三个硬编码的HTML div,最后一个div是我用PHP尝试失败的实验。如果你看看房子的图片,你可以看到我希望PHP脚本显示信息的格式。 (目前刷新页面自动创建一个记录与表格框标题,我需要修复以及)
请问如果你需要我澄清,如果你能帮助我,那将是非常感激。我相信答案非常简单,我花了一段时间来解释所有这些。
这是我使用的数据库的事情:
这是房子的一个div我需要PHP每个房子被上传时自动创建格式:
关于刷新创造了新的记录的页面:它是有重定向回到原来的页面创建一个单独的后处理程序脚本是一个好主意。这确保页面刷新不会重新发布任何内容。 – Ixalmida
我不知道如何完成这个任务,我是PHP的一个极端的基本用户。我不能只写脚本。我的老师甚至没有教过我们,他只是给了我们练习来复制代码,所以我只能通过我在那些非常有限的知识中学到的知识。 –