Jump to content

phreak3r

Members
  • Content Count

    85
  • Joined

  • Last visited

Community Reputation

1 Neutral

About phreak3r

  • Rank
    Regular Member

Recent Profile Visitors

171 profile views
  1. phreak3r

    $row['index here'] outputs null

    Okay, thank you.
  2. phreak3r

    $row['index here'] outputs null

    Yes, however, that was not really the issue. Not sure if this is the solution I am looking for, but I changed $row == 1 && password_verify($password, $row['password']) to $row['username'] == $username && password_verify($password, $row['password']. But, thank you.
  3. phreak3r

    $row['index here'] outputs null

    Right, right. Sorry. 😬
  4. phreak3r

    $row['index here'] outputs null

    From my understanding it fetches result from or of the array?
  5. phreak3r

    $row['index here'] outputs null

    Here is what they mysqli version looked like: <?php include('header.php'); require('dbcon/dbcon.php'); // if fields in form are set and submitted, check if user exists and is logged in or not if ($_SERVER['REQUEST_METHOD'] == 'POST') { $username = mysqli_real_escape_string($conn, $_POST['username']); $password = mysqli_real_escape_string($conn, $_POST['password']); $user_query = "SELECT * FROM profile0 WHERE username = '$username'"; $result = mysqli_query($conn, $user_query); $row = mysqli_fetch_assoc($result); // if username and password match, init session and redirect to another page. if (mysqli_num_rows($result) == 1 && password_verify($password, $row['password'])) { $_SESSION['logged_in_user'] = $username; // set to IDnum later on... $_SESSION['username'] = $username; // check if the user is logged in // if so, redirect to main page for logged-in users. if (isset($_SESSION['logged_in_user'])) { $_SESSION['logged_in_user'] = TRUE; header('Location: main.php'); } else { // not logged in, keep on same page... session_destroy(); exit(); } } else if ($username != $row['username'] || $password != $row['password']) { echo "Incorrect username or password."; } } ?>
  6. phreak3r

    $row['index here'] outputs null

    Executing the query does nothing.
  7. phreak3r

    $row['index here'] outputs null

    So this would not work? I would need to change $row == 1 to $row['username'] == 1 if ($row == 1 && password_verify($password, $row['password'])) {
  8. phreak3r

    $row['index here'] outputs null

    No, I program on and off and am not too well-versed. Empty array?
  9. <?php include('header.php'); require('dbcon/dbcon.php'); // if fields in form are set and submitted, check if user exists and is logged in or not if ($_SERVER['REQUEST_METHOD'] == 'POST') { $username = $_POST['username']; $password = $_POST['password']; $user_query = $pdo->query("SELECT * FROM profiles001 WHERE username = '$username'"); $row = $user_query->fetchAll(PDO::FETCH_ASSOC); // if username and password match, init session and redirect to another page. if ($row == 1 && password_verify($password, $row['password'])) { $_SESSION['logged_in_user'] = $username; // set to IDnum later on... $_SESSION['username'] = $username; // check if the user is logged in // if so, redirect to main page for logged-in users. if (isset($_SESSION['logged_in_user'])) { $_SESSION['logged_in_user'] = TRUE; header('Location: main.php'); } else { // not logged in, keep on same page... session_destroy(); exit(); } } else if ($username != $row['username'] || $password != $row['password']) { echo var_dump($row); echo var_dump($row['password']); echo var_dump($row['username']); echo var_dump($row['email']); echo "Incorrect username or password."; } } ?> This code is responsible for authenticating the user upon logging in. I went ahead and updated the mysqli portion to PDO. As you can see I var_dump some variables near the end. Variable $row prints out as array(1) { [0]=> array(9) { ["username"]=> string(4) "test" ["password"]=> string(60) "$2y$10$uQEUsIwm0usWyZjWk/vo8e90e867oPLBu3ThKCk1aUseMcQuuHrVq" ["avatar"]=> string(15) "assets/soap.jpg" ["doc"]=> NULL ["las"]=> NULL ["email"]=> string(13) "test@test.org" ["c_status"]=> string(1) "0" ["account_age"]=> NULL ["bio"]=> string(4) "test" } }. The other three print out as NULL. What exactly is going on here?
  10. phreak3r

    Data is not inserted into db

    Dammit! Well, you are correct Barand. See this stack overflow post. I might need to try UPDATE instead. Ah, I am sorry about that Kevin. I cannot stand cars, sadly in my case they are necessary as my locale requires them to a certain extent. Watch out for the SUVs and Pickup Truck drivers, those are the worst. Thank you benanamen and barand.
  11. phreak3r

    Data is not inserted into db

    Okay, data is being inserted into the database again, except for the avatar path. I think I will have to write out $_FILES['userfile']['name'] instead of doing what I had done before. ($file['name'] and $file being equal to $_FILES['userfile'])
  12. phreak3r

    Data is not inserted into db

    From the var_dump: array(1) { ["userfile"]=> array(5) { ["name"]=> string(0) "" ["type"]=> string(0) "" ["tmp_name"]=> string(0) "" ["error"]=> int(4) ["size"]=> int(0) } } <?php include('header.php'); ?> <!DOCTYPE html> <html> <head> <title>soapbox - sign up</title> </head> <body> <form action="confirmation.php" method="POST" enctype="multipart/form-data"> <br> Avatar <br> <input type="file" name="userfile" id="fileToUpload"> <br> Username: <br> <input type="text" name="username" maxlength="26" placeholder="Username"> <br> Password: <br> <input type="password" name="password" maxlength="26" placeholder="Password"> <br> Email Address: <br> <input type="email" name="email" placeholder="Email Address"> <p>Bio: </p><textarea name="bio" placeholder="Bio..." rows="5" style="resize: none;"></textarea> <br> <input type="submit" value="Submit"> </form> </body> <!--Include footer later on --> </html> form from the signup.php file
  13. phreak3r

    Data is not inserted into db

    I am checking for the avatar/image file, however, that is not working. if (!isset($_FILES['userfile'])) { $avatar = "assets/soap.jpg"; $avatar_present_query = $pdo->prepare("INSERT into profiles001 (avatar) VALUES (:avatar) WHERE username = ':username'"); $avatar_present_query->bindValue(':avatar', $avatar); $avatar_present_query->bindValue(':username', $username); $avatar_present_query->execute(); $query->execute(); } Specifically, the query in the if-statement is not doing its job. I tried using UPDATE previously and that too would fail to work. I know PHP after a certain version (can't quite recall which) is more so made for object-oriented programming style. But I am wanting to go with the functional programming or function-based programming format. That is why I am using functions.
  14. phreak3r

    Data is not inserted into db

    Sorry that I missed the last brace Kevin. As for putting the code in the function, I am going for a 'functional programming' type of format. I did not copy the entire thing as what is past the brace is commented code and THEN the final brace. Would you like to see that?
  15. If the user signs up and does not have an avatar, a default will be given to them. I am checking for the avatar/image file, however, that is not working. Here is the messy code below: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // $username = $_POST['username']; // adds user info submitted upon registration to database function addUser($pdo) { $username = $_POST['username']; $password = password_hash($_POST['password'], PASSWORD_DEFAULT); $bio = $_POST['bio']; $email = $_POST['email']; $c_status = 0; $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); $file = $_FILES['userfile']; $file_name = $file['name']; $file_type = $file['type']; $file_size = $file['size']; $file_tmp_name = $file['tmp_name']; $file_error = $file['error']; if (!isset($_FILES['userfile'])) { $avatar = "assets/soap.jpg"; $avatar_present_query = $pdo->prepare("INSERT into profiles001 (avatar) VALUES (:avatar) WHERE username = ':username'"); $avatar_present_query->bindValue(':avatar', $avatar); $avatar_present_query->bindValue(':username', $username); $avatar_present_query->execute(); $query->execute(); } // $query->execute(); } addUser($pdo);
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.