Reputation: 1
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? For example, the browser has a save button and when pressed the url a person is viewing is stored in 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);
?>
Upvotes: 0
Views: 3422
Reputation: 13327
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
<?php
$url = $_GET['url'];
.........
?>
and then make the insert statement to your database note: this solution i wrote just to show u a very simple way to do that
Upvotes: 1