phreak3r Posted January 1, 2019 Share Posted January 1, 2019 Excerpts of code: function addUser() { $username = $_POST['username']; $password = password_hash($_POST['password'], PASSWORD_DEFAULT); $bio = $_POST['bio']; $email = $_POST['email']; $c_status = 0; //$avatar = //$username_query = $pdo->prepare("SELECT * from profiles001 WHERE username=':username'"); //$username_query->bindValue(':username', $username); //$username_query->execute(); $query = $pdo->prepare("INSERT into profiles001 (username, password, email, c_status, bio) VALUES (:username, :password, :email, :cstat, :bio)"); $query->bindValue(':username', $username); $query->bindValue(':password', $password); $query->bindValue(':email', $email); $query->bindValue(':cstat', $c_status); $query->bindValue(':bio', $bio); $query->execute(); setAvatar(); } function setAvatar() { // check if avatar is set, if not give default avatar if (isset($file) && $fileError === UPLOAD_ERR_OK) { $file = $_FILES['userfile']; $fileName = $file['name']; $fileTmpName = $file['tmp_name']; $fileSize = $file['size']; $fileError = $file['error']; $fileType = $file['type']; $fileExt = explode('.', $fileName); $fileActualExt = strtolower(end($fileExt)); $allowedExtensions = array('jpg', 'jpeg', 'png'); } // if user has not assigned avatar, assign the default. if (empty($file)) { $avatar = "assets/soap.jpg"; $query = $pdo->prepare("INSERT INTO profiles001 (avatar) VALUES (:avatar)"); $query->bindValue(':avatar', $avatar); $query->execute(); } } addUser(); } From the database file: <?php $host = "localhost"; $database = "soapbox"; $username = "drb"; $password = "m1n3craft"; // Create connection $pdo = new PDO('mysql:host=localhost;dbname=soapbox;', $username, $password); /* Print error message and or code to the screen if there is an error. */ ?> NOTE: I also require dbcon.php at the top of the confirmation.php file which is NOT included in the excerpt at the top. Making pdo a global variable would probably fix it, but from what I heard globals are frowned upon. Quote Link to comment Share on other sites More sharing options...
Barand Posted January 1, 2019 Share Posted January 1, 2019 $pdo isn't defined within the function. Pass it as an argument. function AddUser($pdo) { // code here } Quote Link to comment Share on other sites More sharing options...
phreak3r Posted January 2, 2019 Author Share Posted January 2, 2019 Thank you so much, Barand and Happy New Year to you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.