I am having more problems with my Admin CP. There is a form on the previous page that sends the data here. I can't figure out why it won't add users into the database.
Code:<?php session_start(); if(!isset($_SESSION['username'])){ header("location:index.php"); } $host = 'localhost'; $database = 'stencil_access'; $db_username = 'stencil_admin'; $db_password = '<censored>'; if (($db = new PDO("mysql:host=$host;dbname=$database", $db_username, $db_password)) == NULL) { echo $db->getMessage(); } $memberQuery = $db->prepare("SELECT * FROM members WHERE username=:username"); $memberQuery->execute(array(':username' => $_SESSION['username'])); $memberQuery1 = $db->prepare("SELECT * FROM members WHERE username=:username"); $memberQuery1->execute(array(':username' => $username)); $memberQuery2 = $db->prepare("SELECT * FROM members"); $memberQuery2->execute(); $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $type = $_POST['type']; $purchased = $_POST['purchased']; $expiry = $_POST['expiry']; $today=date("F j, Y"); $file_date=date('Y-m-d'); $file = "Logs/" . $file_date .".txt"; $res_array = $memberQuery->fetchColumn(4); if ($res_array<'2') { header("location:main.php"); die(); } if ($memberQuery1->fetchColumn() > 0) { header("Location:admin.php"); die(); } if (empty($_POST['username']) || ($_POST['username']) == $memberQuery || empty($_POST['password']) || strlen($_POST['password']) != 40 || empty($_POST['email']) || intval($_POST['type']) < 0 || !is_numeric($_POST['type']) || empty($_POST['purchased']) || empty($_POST['expiry']) ) { header("Location:admin.php"); die(); } $result = $db->prepare('INSERT INTO members (username, password, email, type, purchased, expiry) VALUES (:username, :password, :email, :type, :purchased, :expiry)'); $result->execute(array(':username' => $username, ':password' => $password, ':email' => $email, ':type' => $type, ':purchased' => $purchased, ':expiry' => $expiry)); if($result) { file_put_contents($file, "{$_SESSION['username']} has added an user to the database on on $today\n", FILE_APPEND | LOCK_EX); } header("Location:admin.php"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css"> </head> </html>


LinkBack URL
About LinkBacks
Reply With Quote

