Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by justsomeguy

  1. There are several problems there, still. For the fifth time, you're missing a semicolon. Again, the first opening bracket doesn't have a matching closing one, so figure that out. If the person is not logged in, what do you specifically want to do? Which lines of code should be executed if the person is not logged in? Figure it out and add the missing bracket. When you're checking if it's a post request, you're missing your brackets. A try block should have brackets. Again, missing. And, again, the try/catch block is completely unnecessary and won't impact how the code runs at all. I've already explained why. The code will never enter the catch block even if move_uploaded_file fails.
  2. Probably not automatically through .NET (it is .NET, not IIS, that manages session state), but I suppose you can figure out where it stores them and look them up that way. I don't know why that's necessary though, this is all handled automatically. When the session times out it is deleted. I don't know how .NET handles sessions specifically, but I imagine that if you try to start a session then it will either look for an ID for an existing valid session, or start a new empty session otherwise. Your web service can have some method that can look at the session to determine if it is a new empty session or if there is data there, and return that information to your other application.
  3. I guess I don't understand why you're not setting the value initially, I don't understand what the barrier to doing that is. How about just calling the reset function when the thing loads? That's what I'm talking about for the reset button doing the same thing as when it initially loads.
  4. Well, how are you generating and storing the ID in the first place? It seems pretty trivial to store a piece of data in a certain place and then check the same place to see if that data is there or not, I'm not sure what you're missing.
  5. Insert queries do not have a WHERE clause, ever. A WHERE clause is for filtering. You do not filter an insert. Well, the first step is to fix your syntax errors. After that you can work on getting the logic right once the code actually runs.
  6. Are you saying you don't set the value unless the reset button is pressed? It seems like the reset button should just repeat the exact same action that set it up in the first place, why is it doing something different? What's the difference between initially setting up the form and resetting it?
  7. The type attribute is just for native validation or adding helpful controls (like a date picker), but according to MDN the value property is always a string: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement
  8. .NET should handle that automatically, or is this some ID that you're creating and managing yourself?
  9. There was only one missing opening bracket in your code, all of the other bracket issues were caused by no matching closing bracket. The solution for a missing closing bracket isn't to remove the opening bracket, it's to figure out where the closing one should go. That's why I pointed out that your solution above to remove the unmatched opening bracket was not the correct solution. Also, the syntax error about the unexpected variable is not about brackets at all. No, that does not seem like the right place to add one. Although the entire logic of having that query there and checking the result doesn't make sense to me at all. When someone uploads a file, you want to check the database to see if an image with a certain ID exists? Why? Why are you checking for the presence of a particular record in the database to decide whether or not to process an uploaded file? I don't know why you have that there at all, but that opening bracket is one of the ones which actually does have a matching closing bracket.
  10. If you want to do that in PHP, this might be all you need: https://www.php.net/manual/en/function.getimagesize.php
  11. The global scope is always available if that's what you're asking about. If it's a question of timing instead of scope then whatever code sets the value should then execute the function that uses it. Or, maybe some flag that says whether or not the values are loaded and if the function that uses those values sees that they're not loaded then it runs whatever code loads the values before trying to use them. This is all pretty abstract though.
  12. The general reason is that the variables are out of scope or undefined when the code runs. The specific reason depends on the specific code.
  13. No it wouldn't, which is why I was confused when you said it reported no more errors. There are several more errors.
  14. justsomeguy

    where not

    Use the not equal operator in place of the equal operator.
  15. If all I do is remove that one bracket, it still just shows the next error it finds: Error: There is 1 more closing curly braces '}' found This count is unaware if curly braces are inside of a string PHP Syntax Check: Parse error: syntax error, unexpected '$q' (T_VARIABLE) in your code on line 17 You're not pasting individual blocks or lines, right, you're checking the entire file at once? PHP checks the entire file at once before executing it. If you're not doing the same, you're not doing it right. The individual lines of code in your file do not live in a vacuum, they are surrounded by and part of other code. The entire file is one piece of code. That is why a syntax error in any part of the file causes the entire thing to fail. I also pointed out 2 syntax errors in that block of code, the missing curly bracket is not the only error (and removing a curly bracket doesn't fix the fact that you have a missing one, it just causes another runtime error because now you've removed lines of code from your if statement). The error message is related to the second error in that code that I've already pointed out at least four times.
  16. Well, yeah, that's going to eliminate a syntax error, but I'm pretty sure you've added a runtime error that you'll see whenever you get the code to actually execute. What "PHP checker" are you using?
  17. This is what happened when my IDE tried to reformat your code: <?php # Access session. session_start(); # Open database connection. require('connect_db.php'); # DISPLAY COMPLETE LOGGED IN PAGE. # Redirect if not logged in. if (!isset($_SESSION['user_id'])) { require('login_tools.php'); load() # Retrieve selective item data from 'images' database table. $q = "SELECT * FROM images WHERE id = $id"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) == 1) { $row = mysqli_fetch_array($r, MYSQLI_ASSOC); if ($_SERVER['REQUEST_METHOD'] == 'POST') $name = $_FILES['image']['name']; $temp = $_FILES['image']['tmp_name']; $size = $_FILES['image']['size']; $ext = pathinfo($name, PATHINFO_EXTENSION); $ext = strtolower($ext); if ($ext != 'png' && $ext != 'jpg' && $ext != 'gif') { echo 'Format must be PNG, JPG, or GIF'; exit(); } if ($size > 512000) { echo 'File size must not exceed 500Kb'; exit(); } if (file_exists($name)) { echo 'File ' . $name . ' already uploaded'; exit(); } try move_uploaded_file($temp, $name); echo 'File uploaded : ' . $name; echo '<br><img src="' . $name . '">'; } catch(Exception $e ) echo 'File upload failed!'; } # Close database connection. mysqli_close($dbc); ?> Line 17 is not indented because of the missing semicolon on the previous line. Line 17 has a variable called $id in the query. $id is not defined. Why are you trying to select a row with a certain ID, and only process the form if you find one? You get the database record on line 20 but don't do anything else with $row, what's the point? The if statement on line 22 does not have brackets at all, so only the next line, line 24, is included in the if statement. You have a try statement on line 41. Again, it has no brackets. At least, no opening bracket. It looks like the closing bracket is supposed to be the one on line 46. move_uploaded_file does not throw an exception, there's no point to putting it in a try/catch block. If it fails it returns false, it does not throw an exception.
  18. justsomeguy

    sql query isuue

    They use different formats for dates.
  19. Like I said, the opening bracket before require does not have a closing bracket, and you're missing a semicolon. I am not talking about parentheses, I'm talking about curly brackets. Your computer does not have a finite supply of newline characters, format your code so that it's easy to read. There's no prize for having the fewest lines of code. if (!isset($_SESSION['user_id'])) { require('login_tools.php'); load() What is missing from this picture? It should be pretty obvious.
  20. Well that's remarkably light on details, although it's probably worth pointing out that the president of the US is not a dictator. It would also be pretty surprising if any world government decided to take out ad space on a programming website.
  21. Practice. Pick a technology, learn how to use it, and start making things.
  22. Yeah, that's the line. Does that opening bracket before require have a matching closing bracket? Because it looks to me like your code has 8 opening brackets and 6 closing brackets. Don't you think those should be the same number? You need to find the missing ones and add them where they are supposed to be. And how about that call to the load function? Every statement should end with a semicolon, right? Well, where is it? More importantly, why don't you notice these things? That's the reason. Maybe you are. But you must. always. write. code. correctly. There is not another option. Adding or removing any single piece of punctuation outside of a string will cause all of your code to stop working. Programming is not estimation or guessing, it must always be precise and specific. The computer understands a very specific language, and if you are not using it according to the rules then the computer does not know what you want it to do. You must follow the language rules. There is not an option. You are responsible for finding the errors when you're writing code. I don't know how else to say it. If you can't spot basic syntax errors then you don't know the language and you're not going to be able to make anything that works.
  23. Here's your actual error message: Parse error: syntax error, unexpected '$q' (T_VARIABLE) on line 15 Like I said, your code is full of syntax errors. That error message has absolutely nothing to do with $q or what it's set to or anything else. It means that when PHP gets to line 15 it sees you trying to set a variable and that doesn't make sense, because of (multiple) syntax errors on the previous line of code. You're missing opening brackets, you're missing closing brackets, you're missing semicolons, and none of your code is going to run - at all - until you fix them. I've said this multiple times and you're still not fixing the errors. PHP is telling you that when it gets to line 15 it found something that it didn't expect, and when that happens you have an error above that line somewhere. You need to figure out why there is a syntax error on the previous lines and fix it. And if you get another error message, then fix that one too. And then when you get another one, fix that one. Don't jump around copying and pasting every example you can find, don't worry about how to set your database when you can't even get your code to run. Work on one thing at a time. Focus. Pay attention. You have basic errors about how to even structure the code that have nothing to do with programming logic or anything else, it doesn't even get that far because the code isn't even structured correctly in the first place.
  24. I see 3 syntax errors in your code that will stop anything from running, and 2 runtime errors that will cause problems if you actually get it to run. To start with, count the opening and closing brackets. Those should be the same number. Yeah, you've got several syntax errors in that too. You've got commas where they shouldn't be, and missing commas where they should be. Even that has syntax errors. You've got an opening double quote, where's the double quote to close the string? And the SQL query in your PHP has 2 syntax errors. There's only 9 words in it. You really need to pay attention to this stuff. Syntax errors stop any code from running. And yes, adding just a single syntax error in a piece of code because you aren't paying attention means that now nothing works.
  25. I don't see any issues, as far as I'm aware that should work fine.
  • Create New...