Jump to content

slotegraafd

Members
  • Posts

    35
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by slotegraafd

  1. ope sorry if ($keys[$recordCount] == "logo" && $totalRows[$column] != "") { echo '<td class="py-2"><img src="' . $totalRows[$column] . '" alt="Client Logo" class="logo-thumbnail" /></td>'; //Check whether or not the client is active or inactive } else if ($keys[$recordCount] == "enabled") { $userId = $data[$record]['id']; $enabled = $data[$record]['status']; echo ' <td class="py-2">'. '<form method="POST" action="salesperson.php"> <div> <input type="radio" name="active[' . $userId . ']" value="Active" '; if($enabled == "a") { echo 'checked'; }; echo '/> <label for="' . $userId . '-Active">Active</label> </div> <div> <input type="radio" name="active[' . $userId . ']" value="Inactive" '; if($enabled == "d") { echo 'checked'; }; echo '/> <label for="' . $userId . '-Inactive">Inactive</label> </div> <input type="submit" name="submitType" value="Update" /> </form> Current Status: '. $totalRows[$column] . "</td>"; (its created as a function)
  2. So I am trying to create a table where users can be disabled and enabled with the press of a radio button. So for the most part it works but for some reason it only allows me to disable a user it wont let me enable them and I can't seem to figure out why. I've checked that all the names were correct with the database and I have also tried both single ' quotes and double " quotes on the prepared statements to see if that makes a difference... it did not These are the functions to disable and enable users function inactive($userId){ $conn = db_connect(); $disable_user = pg_prepare($conn, 'disable', "UPDATE users SET Enabled = false, Status = 'd' WHERE Id = $userId"); $result = pg_execute($conn, 'disable', array()); } //Create a function to activate a salesperson function active($userId){ $conn = db_connect(); $enable_user = pg_prepare($conn, 'enable', "UPDATE users SET Enabled = true, Status = 'a' WHERE Id = $userId"); $result = pg_execute($conn, 'enable', array()); } $id = (array_keys($_POST['active'])[0]); $status = $_POST['active'][$id]; if($status == "t"){ active($id); } else{ inactive($id); } And this is where it gets put into action ^^ In the database I have a boolean for enabled which is either true or false and then I have a varchar for status which is either 'd' or 'a' Any help would be greatly appreciated Thanks in advance
  3. Okay well can you show me where exactly you put that stuff in my code so I can see if maybe i put it in the wrong spot
  4. Is this how you did it. Idk what im missing $lastRecord = min($firstRecord + ROWS_PER_PAGE, $rows); for($record = $firstRecord; $record < $lastRecord; $record++){ $row = $data[$firstRecord + ROWS_PER_PAGE]; echo '<tr>'; for($recordCount = 0; $recordCount < count($keys); $recordCount++){ $column = $keys[$recordCount]; echo '<td class="py-2">' . $row[$column] . '</td>'; } echo '</tr>'; }
  5. Okay so that didnt in fact get rid of the errors I was getting but now it doesnt show any of the data
  6. display_table( array( "id" => "Id", "emailaddress" => "Email", "firstname" => "First Name", "lastname" => "Last Name", "salesperson" => "Salesperson", "phonenumber" => "Phone Number", "extension" => "Extension", "type" => "Type" ), client_select_all(), client_count(), 1 ); I forgot to add the last part of this, I have those two as other functions to for the data and rows and such
  7. What do you mean? Cuz it does actually show the data in the table still
  8. Hi, WHAT: So I cannot for the life of me figure out why I'm getting this error. I'm trying to create a function that will display the user information from the database in a table but I have like a ton of these errors on the page and I don't know whats wrong. STEPS TO RESOLVE: So I've gone over my code a bunch of types to make sure that all the variables and what not were spelled correctly and as far as I can tell they are. I've also googled this issue to see if I can find a solution but none of them are very helpful. I honestly don't know whats wrong so kinda hard to find ways to resolve an issue, I don't even really know what this error means. THE CODE: This is where I put the function into action <?php display_table( array( "id" => "Id", "emailaddress" => "Email", "firstname" => "First Name", "lastname" => "Last Name", "salesperson" => "Salesperson", "phonenumber" => "Phone Number", "extension" => "Extension", "type" => "Type" ) ); ?> //This is the function <?php function display_table($fields, $data, $rows, $page){ if(isset($_GET['page'])){ $page = $_GET['page']; } else { $page = 1; } $firstRecord = ($page - 1) * ROWS_PER_PAGE; $pageNumbers = ceil($rows / ROWS_PER_PAGE); echo '<div class="table-responsive w-75 mx-auto py-3"> <table class="table table-dark table-bordered table-sm"> <thead> <tr>'; foreach($fields as $key){ echo '<th class="py-2">' . $key . '</th>'; } echo '</tr> </thead> </tbody>'; $keys = array_keys($fields); for($record = $firstRecord; $record < $firstRecord + ROWS_PER_PAGE; $record++){ $row = $data[$record]; echo '<tr>'; for($recordCount = 0; $recordCount < count($keys); $recordCount++){ $column = $keys[$recordCount]; echo '<td class="py-2">' . $row[$column] . '</td>'; } echo '</tr>'; } echo '</tbody> </table'; for($pages = 1; $pages <= $pageNumbers; $pages++){ echo '<a class="btn btn-dark mx-1" href=?page=' . $pages . '</a>'; } } ?> Any help/advice would be really appreciated
  9. // Form Fields Arrays: Field Title, Field Name, Field Type $display_form = array( array( "type" => "text", "name" => "first_name", "value" => "", "label" => "First Name" ), array( "type" => "text", "name" => "last_name", "value" => "", "label" => "Last Name" ), array( "type" => "email", "name" => "email", "value" => "", "label" => "Email" ), array( "type" => "number", "name" => "extension", "value" => "", "label" => "Extension" ), ); foreach ($display_form as $key => $value) { echo "<label for='{$value[1]}'>{$value[3]}</label>\n<input id='{$value[1]}' name='{$value[1]} type=\"{$value[0]}' value='{$value[2]}' ><br><br>\n\n"; } ?> <input type="submit" name="submit" value="Submit" class="button"> </fieldset> </form>
  10. Oh so I’m using the array that I have in my code there. (I’m really bad with arrays if you couldn’t tell) I thought that each one in the array corresponded to a number no matter what type of arrays
  11. @benanamen Ah I see, Notice: Undefined offset: 2 in C:\XAMPP\htdocs\Webd3201\salesperson.php on line 83 though do you know what this error means?
  12. Hey, So I'm doing a school assignment and my professor wants us to use an array to display forms and I have no idea how to do that. He wants us to create an array of arrays like this: display_form( array( "type" => "text", "name" => "first_name", "value" => "", "label" => "First Name" ), array( "type" => "text", "name" => "last_name", "value" => "", "label" => "Last Name" ), array( "type" => "email", "name" => "email", "value" => "", "label" => "Email" ), array( "type" => "number", "name" => "extension", "value" => "", "label" => "Extension" ) ); But I dont understand how you use that array to actually display the form. Does anyone know how?
  13. because i am trying to get it from the database my issue however is what do I do once i get that information
  14. I know the answer is to check if the input is the right combination but I'm asking how you do that
  15. I dont' know what to try because I was certain this was the right code which it obviously isnt, I retrieved it from the data as in the code in the if statement but it doesnt check to see if the input is the right combination that is why I am asking for help because I do not know what to do with this
  16. I'm required to use pgadmin, this is an assignment for school, all I am focusing on right now is trying to get it to login
  17. Hello, I am once again desperately asking for your help, I am working on a simple login page and I am having trouble actually getting it to login. I display error messages for if the user doesn't enter anything but I can't seem to get it to work for if the credentials are wrong. It logs the user in whether the information is right or not and i dont even know what to do now This is the code any suggestions would be greatly appreciated <?php /* Name: Deanna Slotegraaf Course Code: WEBD3201 Date: 2020-09-22 */ $file = "sign-in.php"; $date = "2020-09-22"; $title = "WEBD3201 Login Page"; $description = "This page was created for WEBD3201 as a login page for a real estate website"; $banner = "Login Page"; require 'header.php'; $error = ""; if($_SERVER["REQUEST_METHOD"] == "GET") { $username = ""; $password = ""; $lastaccess = ""; $error = ""; $result = ""; $validUser = ""; } else if($_SERVER["REQUEST_METHOD"] == "POST") { $conn; $username = trim($_POST['username']); //Remove trailing white space $password = trim($_POST['password']); //Remove trailing white space if (!isset($username) || $username == "") { $error .= "<br/>Username is required"; } if (!isset($password) || $password == ""){ $error .= "<br/>Password is required"; } if ($error == "") { $password = md5($password); $query = "SELECT * FROM users WHERE EmailAddress='$username' AND Password='$password'"; $results = pg_query($conn, $query); //$_SESSION['username'] = $username; //$_SESSION['success'] = "You are now logged in"; header('location: dashboard.php'); }else { $error .= "Username and/or Password is incorrect"; } } ?> <div class = "form-signin"> <?php echo "<h2 style='color:red; font-size:20px'>".$error."</h2>"; ?> <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label for="uname"><b>Login ID</b></label> <input type="text" name="username" value="<?php echo $username; ?>"/> <br/> <label for="psw"><b>Password</b></label> <input type="password" name="password" value="<?php echo $password; ?>"/> <br/> <button type="submit" name="login_user">Login</button> <button type="reset">Reset</button></div> </form> </div> <?php require "footer.php"; ?>
  18. HI, Sorry the question title is really bad. But I'm currently making a simple php login page for school(well it should be simple anyway) and I'm having trouble getting the user to actually login. So Everything else on my page works fine. I have the login form and then I have error messages that displays an error if the user didnt enter any information or if the information is incorrect. So when I try to login with information from the database that should let me login and take me to the dashboard page it still says it is incorrect. Now at the top of my page I am getting an error that says: syntax error at or near "'lastAccess'" LINE 1: UPDATE users SET 'lastAccess' = $1 WHERE 'id' = $2 ^ in C:\XAMPP\htdocs\Webd3201\includes\db.php on line 13. I don't understand why I a,m getting that error. I don't see any syntax errors in my database. CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public; -- DROP'ping tables clear out any existing data DROP TABLE IF EXISTS users; -- CREATE the table CREATE TABLE users( userId VARCHAR(50) PRIMARY KEY NOT NULL, email VARCHAR(255) UNIQUE, password VARCHAR(255) NOT NULL, firstName VARCHAR(128), lastName VARCHAR(128), enrolDate TIMESTAMP, lastAccess TIMESTAMP, enable BOOLEAN, type VARCHAR(2) NOT NULL ); ALTER TABLE users OWNER TO postgres; INSERT INTO users (userId, email, password, firstName, lastName, enrolDate, lastAccess, enable, type) VALUES ( 'DoeJ', 'jdoe@dcmail.ca', crypt('password', gen_salt('bf')), --NOTE: bf stands for blowfish 'John', 'Doe', '2020-09-14 19:10:25', '2020-09-15 11:11:11', true, 'a'); INSERT INTO users (userId, email, password, firstName, lastName, enrolDate, lastAccess, enable, type) VALUES ( 'slotegraafd', 'deanna.slotegraaf@dcmail.ca', crypt('deanna1999', gen_salt('bf')), 'Deanna', 'Slotegraaf', '2020-09-15 23:18:27', '2020-09-16 13:40:02', true, 'a'); INSERT INTO users (userId, email, password, firstName, lastName, enrolDate, lastAccess, enable, type) VALUES ( 'smithj', 'smithj@dcmail.ca', crypt('smith', gen_salt('bf')), 'Jane', 'Smith', '2020-08-22 09:14:56', '2020-09-01 20:34:14', true, 'a'); This is the database code ^^^^^^^ <?php function db_connect() { $conn = pg_connect("host=" .DB_HOST. " port=" .DB_PORT. " dbname=" .DB_NAME. " user=" .DB_USER. " password=" .DB_PASSWORD); return $conn; } $conn = db_connect(); //Retrieve the user $stmt1 = pg_prepare($conn, "user_select", 'SELECT * FROM users WHERE userId = $1 AND password = $2'); //Update the login time $stmt2 = pg_prepare($conn, 'user_update_login_time', "UPDATE users SET 'lastAccess' = $1 WHERE 'id' = $2"); $stmt3 = pg_prepare($conn, 'user_authenticate', "SELECT 'userId', 'password', 'email', 'lastAccess', 'type' FROM users WHERE 'id' = $1 AND 'password' = $2"); $stmt4 = pg_prepare($conn, 'get_info', "SELECT userId, firstName, lastName FROM users WHERE userId = $1;"); ?> This is the file thats giving the error^^^^ <?php /* Name: Deanna Slotegraaf Course Code: WEBD3201 Date: 2020-09-22 */ $file = "login.php"; $date = "2020-09-22"; $title = "Login Page"; $coursecode = "WEBD3201"; $description = "This is a login page created for a real estate website for WEBD3201"; $banner = "Login Page"; $heading = "DS REAL ESTATE"; require 'header.php'; $error = ""; //Displays the error message to the screen //Get method to get the info from the server if($_SERVER["REQUEST_METHOD"] == "GET") { $username = ""; //Holds the username $password = ""; //Holds the password $lastaccess = ""; //Displays the last access time $error = ""; //Displays the error message on the screen $result = ""; //Gets the result of the query $validUser = ""; //Determines if the user is valid } //Posts to the server else if($_SERVER["REQUEST_METHOD"] == "POST") { //Connects to the database from db.php $conn; $username = trim($_POST["username"]); //removes trailing white space for username input box $password = trim($_POST["password"]); //Removes trailing white space for password input box //Determines if the username input box is blank if(!isset($username) || $username == "") { //Display error message $error .= "<br/>You must enter a username!"; } //Determines if the password input box is blank if(!isset($password) || $password == "") { //Display error message $error .= "<br/>You must enter a password!"; } //If the error message is blank if ($error == "") { //Hash the password $password = hash("md5", $password); //Gets the user from the database $result = pg_execute($conn, "user_select", array($username, $password)); //IF the query results were successful if(pg_num_rows($result)) { $user = pg_fetch_assoc($result, 0); $_SESSION['user'] = $user; //Update the login time $result = pg_execute($conn, "user_update_login_time", array(date("Y-m-d"), $login)); //If there is a user on the session if($_SESSION['user']) { header("Location: ./dashboard.php"); ob_flush(); } } else { //Validates if the username and password are correct $sql = "SELECT userId FROM users WHERE userId = '".$username."'"; $result = pg_query($conn, $sql); $validUser = pg_num_rows($result); if($validUser > 0) { //Display error message $error = "Incorrect Password. Please try again!"; } else { //Displays error message $error = "Incorrect Username / Password. Please try again!"; } } } } ?> <div class = "form-signin"> <?php echo "<h2 style='color:red; font-size: 20px'>".$error."</h2>"; ?> <br/> <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <label for="username"><b>Username:</b></label> <input type="text" name="username" value="<?php echo $username; ?>"/> <br/> <label for="password"><b>Password:</b></label> <input type="password" name="password" value="<?php echo $password; ?>"/> <br/> <button type="submit">Login</button> <button type="reset">Reset</button> </form> </div> <?php require "footer.php"; ?> And this is the login page(don't know if this one will be neededf. Anyway any help would be amazing! Thanks in advance!
  19. Oh well, I am currently using MYSQL im not even using phpmyadmin and i wouldnt know how to use the pdo you suggested im more familiar with mysql
  20. Didn't you say you werent going to help me?
  21. It only has one row of data I entered a test one just to well test. cuz its only supposed to be checking for one because I don't want users with duplicate usernames
×
×
  • Create New...

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.