<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
<?php
$vote_yes=$_GET['yes'];
$vote_no=$_GET['no'];
$time=time();
$servername = "localhost";
$username = "bob";
$password = "123456";
$db = "classDB";
$conn = new mysqli($servername, $username, $password, $db);
if ($conn->connect_error){
die("Connection failed: ". $conn->connect_error);
}
$sql = "insert into votes(yes,no,time)values('$vote_yes','$vote_no','$time')";
if ($conn->query($sql) === TRUE) {
echo "Votes Recorded: Yes = ".$vote_yes." No = ".$vote_no." Time = ".$time;
} else {
echo "Error: ".$sql."<br>".$conn->error;
}
$conn->close();
?>
$sql = "INSERT INTO database_table('arg1, 'arg2', ...) VALUES ('value1,
value2, ...)'";
--
-- Table structure for table `tbl_posts`
--
CREATE TABLE IF NOT EXISTS `tbl_posts` (
`post_id` int(11) NOT NULL AUTO_INCREMENT,
`post_title` varchar(150) NOT NULL,
`post_desc` text NOT NULL,
PRIMARY KEY (`post_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `tbl_posts`
--