-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinsert.php
More file actions
33 lines (32 loc) · 927 Bytes
/
Copy pathinsert.php
File metadata and controls
33 lines (32 loc) · 927 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
<?php
$server = 'localhost';
$user = 'root';
$pass = '';
$dbname = 'rideshare';
try {
//create database
$city=$_POST['city'];
$state=$_POST['state'];
$date=$_POST['date'];
$dbconn = new PDO("mysql:host=$server;dbname=$dbname", $user, $pass);
$dbconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$ins=$dbconn->prepare(
'INSERT INTO `riders` (id,username,state,city,date)
VALUES (:id,:username,:city,:state,:date)'
);
$username="bob";
$dt=new DateTime($date);
$date=$dt->format('Y-m-d');
$ins->bindParam(':id',$id);
$ins->bindParam(':username',$username);
$ins->bindParam(':city',$city);
$ins->bindParam(':state',$state);
$ins->bindParam(':date',$date);
$ins->execute();
echo "New records created successfully";
echo "<script> location.href='index.html'; </script>";
}
catch(PDOException $e){
echo "<br>" . $e->getMessage();
}
?>