-
Notifications
You must be signed in to change notification settings - Fork 1
/
urlreg.php
55 lines (43 loc) · 1.3 KB
/
urlreg.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
$url = $_REQUEST['url'];
$purpose = $_REQUEST['purpose'];
$auth = $_REQUEST['auth'];
// Same AUTH as you have inworld.
$actualauth = "";
$mysql_hostname = 'localhost';
$mysql_username = '';
$mysql_password = '';
$mysql_dbname = '';
try {
$conn = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
exit($e->getMessage());
}
if ($_REQUEST['auth'] != $actualauth) {
exit();
}
// assuming a named submit button
try {
// prepare sql and bind parameters
$sql = "UPDATE url SET url='" . $url . "' WHERE id='" . $purpose . "'";
// Prepare statement
$stmt = $conn->prepare($sql);
// execute the query
$stmt->execute();
if ($stmt->rowCount() > 0) {
// echo a message to say the UPDATE succeeded
echo $stmt->rowCount() . " records UPDATED successfully";
} else {
$sql = "INSERT INTO url (id, url) VALUES ('" . $purpose . "','" . $url . "')";
// use exec() because no results are returned
$stmt = $conn->prepare($sql);
$stmt->execute();
echo "New record created successfully";
}
}
catch (PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
?>