Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/insert record #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions database/insert_record_PDO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

<?php
$first_name=$_POST['firstname'];
$email=$_POST['email'];
$address=$_POST['address'];
$servername= "localhost";
$database="myDatabase";
$username="root";
$password="";
$conn = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('insert into person(firstname, email, address) values (?,?,?) ');
$stmt->execute([$first_name, $email, $address]);
?>
29 changes: 29 additions & 0 deletions database/insert_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
$server_name = "localhost";
$user_name = "root";
$password = "";
$dbname = "myDatabase";

// Create connection
$conn = new mysqli($server_name, $user_name, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// sql to create table
$sql = "CREATE TABLE person (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
email VARCHAR(50),
address VARCHAR(50)
)";

if ($conn->query($sql) === TRUE) {
echo "Table person created successfully";
} else {
echo "Error creating table: " . $conn->error;
}

$conn->close();
?>