Jump to content

Barand

Moderators
  • Posts

    24,565
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. If you want to return all jobs for all employees each time it is called, the yes. If you just want jobs for that employee, then no. Please use code tags button "<>" when posting code and use indentations to render it more readable
  2. We need more information than that. What, precisely, are you trying to achieve? What are the the table structures? What is the relationship between the data in the two tables?
  3. If you aren't allowed to write to files, find another host. It seems your only option may be a hard-coded array. Create passwords using password_hash() for added security. $pwds = [ 'john' => '$2y$10$Vp/6Bk1eNcl3V/cKZCcZN.d43uYTgEMyHSkkFv..S22LbIhkTATPK', 'paul' => '$2y$10$hMcamjUSx5/ixfMjd34gL.ChXtO/EsbPYoYb82tFw3YBrqGwADAEW', 'george' => '$2y$10$kjFY1j.0GfmUbNEa0rOfE.UfFCZ19sYIHzEh2T4NeqOCsC8jnDlPG', 'ringo' => '$2y$10$XgFC90JsmmpCeU68y/gm8epw1PZRgSDTNn0GdoCG9MdKkiVigTvkG' ]; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $pass = $pwds[ $_POST['username'] ]; if (password_verify($_POST['password'], $pass)) { echo "Log in successful<br>"; } else { echo "Invalid log in<br>"; } }
  4. You don't need a mysql database but you do need somewhere to store the userame/password pairs. Sqlite is an option, or you could just use a text file (perhaps ini file format)
  5. Use the code tags button "<>" when posting code. I added them for you this time.
  6. As requested, here's the output
  7. From the Forum Guidelines... If you are having a problem, show us what you have tried already and tell us which bit is giving you the problem.
  8. Ok, I've done those. What's next?
  9. It isn't doing any checking. You create, in the function, an empty local $error array, then your code says "if this (empty) array is not empty, add the empty array to $all_errors array. You should be create empty $error array check for error if error add message to error array endif // repeat for other other error checks as necessary if error array is not empty add it to the all_errors array return false endif return field
  10. My apologies (blame it on age - I guess I had a "senior" moment). array_merge($all_errors, $errors); should be $all_errors = array_merge($all_errors, $errors);
  11. Here's a slightly simpler exampleof achieving same thing $errors = []; // create empty array to accumulate all errors $a = functionA($errors); // call the functions $b = functionB($errors); // passing the error array $c = functionC($errors); // so they can add to it if ($errors) { show_errors($errors); } else { echo "$a - $b - $c<br>"; } // normally when passing a variable to a function // the value is copied to the variable used by the function. // In this case we pass the array *by reference* // so that the original array is used and not a copy. function functionA(&$all_errors) // that way we can accumulate all the errors in the one array { $hasErrs = 0; if (rand(1, 3)==1) { $all_errors[] = 'A error'; // write any error messages into the error array $hasErrs = 1; } if ($hasErrs) { // if there are errors return false; // a common convention is to return false when a function fails with errors } return 1; } function functionB(&$all_errors) { $hasErrs = 0; if (rand(1, 3)==2) { $all_errors[] = 'B error'; $hasErrs = 1; } if ($hasErrs) { return false; } return 2; } function functionC(&$all_errors) { $hasErrs = 0; if (rand(1, 3)==3) { $all_errors[] = 'C error'; $hasErrs = 1; } if ($hasErrs) { return false; } return 3; } function show_errors($errors) { echo "You had errors<ul>"; foreach ($errors as $e) { echo "<li>$e</li>"; } echo "</ul>"; }
  12. Have you got error reporting turned on?
  13. If form method is POST, why try to access $_GET for the id? Where is $del being set? You should be using prepared statements instead of putting user input data directly into your query.
  14. You seem to be in two minds about what your assign_*() functions should return. The one you show can return either a username or an error. It would be better if it were to return the username or false if there was an error and put the error into the error array during the function's execution, as in this example function assign_username(&$all_errors) /// pass the array by reference { global $conn; $username = $_POST['username']; $errors = []; if(!$username){ $errors[] = "A username is mandatory"; } else { $username = clean_names($username); } //check for duplicate username and return $username if doesn't exist already $username_check = mysqli_query($conn, "SELECT username FROM users WHERE username='$username'"); $number_rows = mysqli_num_rows($username_check); if($number_rows > 0) { $errors[] = "Username already in use <br>"; } if ($errors) { array_merge($all_errors, $errors); return false; } else return $username; } // END USERNAME // CALL THE FUNCTIONS $errors = []; $username = assign_username($errors); $lastname = assign_lastname($errors); $username = assign_username($errors); $email = assign_email($errors); show_errors($errors);
  15. Do you mean ... +------------+------------+------------+ | Status 1 | Status 2 | Status 3 | +------------+------------+------------+ | 14 user14 | 12 user12 | NO DATA | | 13 user13 | 11 user11 | | | 8 user8 | | | | 7 user7 | | | | 6 user6 | | | +------------+------------+------------+
  16. Nothing to do with the integers. Your code would require 6,000 case statements just for the products. Then there would be hundreds more for the the categories and brands!
  17. @NotSunfighter could you show us how that would look with all 6,000 products? 😀
  18. If you want it in a single query, initialize the variables in a joined subquery SELECT , (@csumA := @csumA + A) as cumulative_A , (@csumM := @csumM + M) as cumulative_M , (@csumE := @csumE + E) as cumulative_E , (@csumW := @csumW + W) as cumulative_W FROM ( SELECT WEEK(s.date) week, SUM(CASE WHEN s.user_id = 50 THEN s.points ELSE 0 END) AS A, SUM(CASE WHEN s.user_id = 51 THEN s.points ELSE 0 END) AS M, SUM(CASE WHEN s.user_id = 52 THEN s.points ELSE 0 END) AS E, SUM(CASE WHEN s.user_id = 53 THEN s.points ELSE 0 END) AS W FROM users u JOIN scores s ON u.user_id = s.user_id JOIN league l ON l.league_id = s.league_id AND and l.league_name = 'Sunday League' WHERE year(s.date) = YEAR(sysdate()) GROUP BY s.date ORDER BY s.date ASC ) PTS JOIN ( SELECT @csumA:=0, @csumM:=0, @csumE := 0, @csumW:=0 ) INIT;
  19. Using your posted code but with $bnm = null , I get BI-IN0020 Which is pretty similar to what you want. (Except I can't see how you are getting IK from the first 2 chars of "INSECT KILLER")
  20. For the benefit of the non-clairvoyant among us, what are you wanting it to look like when there are NULL values?
  21. Welcome
  22. Where does $filePath get its value from?
  23. That was intended as a hint. Make them both the same and you should then be able to create your foreign key.
  24. Is the column UNSIGNED in both tables?
×
×
  • 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.