我想在本页末尾查看mysql数据库中的一个表。该表具有以下属性:“id”、“longurl”和“shorturl”。
<!DOCTYPE html>
<html>
<head>
<title>URL Shortening Service </title>
<head>
<body>
<center>
<h1>URL Shortening Service</h1>
<form method="POST" action="index.php">
Enter your Url: <input type="text" name="urlshort" placeholder="Enter here"> <br><br>
<input type="submit" name="submit">
</form>
</center>
</body>
</html>
<?php
if (isset($_POST["submit"])){
$conn = mysqli_connect('localhost','zarjis','123456','url');
$longurl = $_POST ["urlshort"];
$shorturl = substr(md5( microtime()), rand(0,26),5);
$query = "INSERT INTO shorturl (shorturl,longurl) VALUES ('$shorturl','$longurl')";
$result = mysqli_query($conn,$query);
if ($result) {
echo "Your Short Url Link is :: http://localhost/url/$shorturl ";
}
else{
echo "We are facing some problems";
}
}
if (isset($_GET["link"])) {
$conn = mysqli_connect('localhost','zarjis','123456','url');
$link = $_GET["link"];
$fetchquery = "SELECT * FROM shorturl WHERE shorturl= '$link'";
$fetchresult = mysqli_query($conn,$fetchquery);
while ($row = mysqli_fetch_assoc($fetchresult)) {
$visitlongurl = $row ["longurl"];
header ("Location: $visitlongurl");
exit();
}
}
?>
我想在本页末尾查看数据库中的表。表在我的数据库中。
1条答案
按热度按时间wgeznvg71#
添加此代码,