I am connected to my database using PDO. My problem is, I can't insert stuff into the table for some reason. I could do it when I connected using mysqli_connect();
but that isn't secure enough for me.
Here is my code that connects to the database:
<?php
$user = "root";
$pass = "";
$loggedin;
$conn = new PDO('mysql:host=localhost;dbname=login', $user, $pass);
if (!$conn) {
die("Connection to the database failed");
}
Here is the code that is trying to insert stuff into the database:
<?php
include '../dbh.php';
$first = $_POST['first'];
$last = $_POST['last'];
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];
if (empty($first)) {
header("Location: ../signup.php?error=empty");
exit();
} if (empty($last)) {
header("Location: ../signup.php?error=empty");
exit();
} if (empty($uid)) {
header("Location: ../signup.php?error=empty");
exit();
} if (empty($pwd)) {
header("Location: ../signup.php?error=empty");
exit();
} else {
$sql = "SELECT uid FROM users WHERE uid='$uid'";
$result = mysqli_query($conn, $sql);
$uidcheck = mysqli_num_rows($result);
if ($uidcheck > 0) {
header("Location: ../signup.php?error=username");
exit();
} else {
$sql = "INSERT INTO users (first, last, uid, pwd)
VALUES ('$first', '$last', '$uid', '$pwd')";
$result = mysqli_query($conn, $sql);
header("Location: ../index.php");
}
}