-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddlink.php
More file actions
42 lines (30 loc) · 954 Bytes
/
addlink.php
File metadata and controls
42 lines (30 loc) · 954 Bytes
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
<?php
if ( isset( $_POST['SubmitData'] ) ) { //check if the submit button on index.php has been clicked
//assign text box input from index.php to variables
$servername = "localhost";
$username = "testuser";
$password = "password";
$dbname = "testuser";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// prepare sql and bind parameters
$stmt = $conn->prepare("INSERT INTO resources (user, url)
VALUES (:user, :url)");
$stmt->bindParam(':user', $user);
$stmt->bindParam(':url', $url);
// insert a row
$user = $_POST['user'];
$url = $_POST['url'];
$stmt->execute();
echo "New records created successfully";
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
$conn = null;
}
echo '<a href="showlinks.php">Show links</a>';
?>