-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsave-url.php
32 lines (31 loc) · 1.34 KB
/
save-url.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
include "config.php";
$og_url = mysqli_real_escape_string($conn, $_POST['shorten_url']);
$shorten_url = str_replace(' ', '', $og_url);
$hidden_url = mysqli_real_escape_string($conn, $_POST['hidden_url']);
if(!empty($shorten_url)){
if(preg_match("/\//i", $shorten_url)){
$explodeURL = explode('/', $shorten_url);
$shortURL = end($explodeURL);
if($shortURL != ""){
$sql = mysqli_query($conn, "SELECT shorten_url FROM url WHERE shorten_url = '{$shortURL}' && shorten_url != '{$hidden_url}'");
if(mysqli_num_rows($sql) == 0){
$sql2 = mysqli_query($conn, "UPDATE url SET shorten_url = '{$shortURL}' WHERE shorten_url = '{$hidden_url}'");
if($sql2){
echo "success";
}else{
echo "Error - Failed to update link!";
}
}else{
echo "The short url that you've entered already exist. Please enter another one!";
}
}else{
echo "Required - You have to enter short url!";
}
}else{
echo "Invalid URL - You can't edit domain name!";
}
}else{
echo "Error- You have to enter short url!";
}
?>