[英]How to store page url to mysql database
I know this may sound novice to some of the members of this board. 我知道这对本委员会的某些成员来说可能是新手。 I'm attempting to create a 'bookmarking' feature.
我正在尝试创建“书签”功能。 Is there a way to store page urls to mysql through php?
有没有办法通过php将页面网址存储到mysql? For example, the browser has a save button and when pressed the url a person is viewing is stored in mysql.
例如,浏览器有一个保存按钮,当按下url时,正在查看的人将存储在mysql中。
I've attempted to do this and its gone very horrible to say the least. 我已经尝试过这样做,至少可以说,它变得非常可怕。 I would greatly appreciate any feedback.
我将不胜感激任何反馈。
<html>
<body>
<form action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="post">
<input type="submit" value="Save" />
</form>
</body>
</html>
<?php
$url = $_GET['url'];
$dbc = mysqli_connect('xxxx', 'xxxx', 'xxxx', 'xxxx')
or die('Error connecting to MySQL server');
$query = "INSERT INTO xxxx (url)".
"VALUES('$url')";
$result = mysqli_query($dbc, $query)
or die('Error.');
mysqli_close($dbc);
?>
this is the index page for example 例如,这是索引页
<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
<html>
<body>
<form action="storeBookmark.php?url=<?php echo curPageURL();" method="GET">
<input type="submit" value="Submit" />
</form>
</body>
</html>
in storeBookmark.php 在storeBookmark.php中
<?php
$url = $_GET['url'];
.........
?>
and then make the insert statement to your database note: this solution i wrote just to show ua very simple way to do that
然后将insert语句添加到您的数据库中, 请注意:我编写此解决方案只是为了展示ua一种非常简单的方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.