我正在学习创建自己的数据库,到目前为止,我已经“感谢教程和stackoverflow”来创建一个注册页面。
注册后,他们输入用户名和密码,然后打开上传页面。
上传房屋详情
在上传页面上,他们输入城市:价格:描述:卧室:浴室:照片:
到目前为止,一旦他们输入了它在索引页面上显示的数据,我就完成了分页,重新调整了上传图像的大小,一切正常。
我的下一步是在索引页面上为每个条目打开一个显示其数据的新窗口。
事情就是让我很难找到代码,我希望用户在上传房屋详细信息时为其详细信息页面输入名称。
并且不以.php或.html结尾只是www.mysite.com/the-desired-name
我的代码到目前为止可能使用了错误的代码,但它工作正常,它帮助我实现我想要的东西,直到我有经验来完善它。
我的代码是上传页面
<form enctype="multipart/form-data" action="add.php" method="POST">
City: <input type="text" name="city"><br>
Price: <input type="text" name = "price"><br>
Decription: <input type="text" name ="description"><br>
Bedrooms: <input type="text" name="bed"><br>
Bathrooms: <input type="text" name="bath"><br>
Your desired link name MYSITE.COM/ <input type="text" name="link"><br>
Photo: <input type="file" name="photo"><br>
<input type="submit" value="Add">
</form>
然后通过
上传<?php
//This is the directory where images will be saved
$target = "upload/";
$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$city=$_POST['city'];
$price=$_POST['price'];
$description=$_POST['description'];
$bed=$_POST['bed'];
$bath=$_POST['bath'];
$link=$_POST['link'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("host", "username", "password") or die(mysql_error()) ;
mysql_select_db("mydatabase") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$city', '$price', '$description', '$bed', '$bath', '$link', '$pic')") ;
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
require_once 'SimpleImage.php';
$image = new SimpleImage();
$image->load($target);
$image->resize(50,50);
$image->save($target);
//Tells you if its all ok
echo "<script>window.location = 'http://www.mysite.com'</script>";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
然后它显示在索引页面上
<?php
// Connects to your Database
mysql_connect("host", "username", "password") or die(mysql_error()) ;
mysql_select_db("mydatabase") or die(mysql_error()) ;
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * 2;
$data = mysql_query("SELECT * FROM employees ORDER BY bath ASC LIMIT $start_from, 2") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
?>
<?php
//Outputs the image and other data
echo "<img src=http://www.mysite.com/upload/".$info['photo'] . " /><br />";
echo "<b>City:</b> ".$info['city'] . " ";
echo "<b>Price:</b> ".$info['price'] . " ";
echo "<b>Bed:</b> ".$info['bed'] . " ";
echo "<b>Bath:</b> ".$info['bath'] . " ";
echo "<b>Extra:</b> ".$info['description'] . " ";
echo "<b>Link:</b> <u>www.mysite.com/</u> ".$info['link'] . " <br /><br /></a>";
}?>
<?php
$data = mysql_query("SELECT COUNT(photo) FROM employees") or die(mysql_error());
$info = mysql_fetch_row($data);
$total_records = $info[0];
$total_pages = ceil($total_records / 2);
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='index.php?page=".$i."'>".$i."</a> ";
};
?>
答案 0 :(得分:0)
因为它不以.php或.html结尾只是www.mysite.com/the-desired-name
假设您使用的是Apache,请查看mod_rewrite。您可以使用它将您所声明的请求转换为/showpage.php/the-desired-name
的内部请求。在showpage.php
脚本中,您可以通过$_SERVER['PATH_INFO']
变量访问the-desired-name
。或者,如果这不起作用,可以通过phpinfo()
告诉您的其他变量。