Jump to content

mac_gyver

Staff Alumni
  • Content Count

    4,485
  • Joined

  • Days Won

    121

mac_gyver last won the day on August 5

mac_gyver had the most liked content!

Community Reputation

486 Excellent

2 Followers

About mac_gyver

  • Rank
    Staff Alumni

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

148,515 profile views
  1. how do you know that, especially since you should be getting a status_id number as the returned value? perhaps there's some problem with the code that's using the result from calling that function? what is the (default) fetch mode you are using for the ->fetch() method call? have you set a default fetch mode yourself or are you using the default, default fetch mode? any chance you have more than one database and are selecting the wrong one?
  2. there are a number of issues in the code that are producing php errors. to get php to help you, find the php.ini that php is using and set error_reporting to E_ALL, display_errors to ON, and output_buffing to OFF. stop and start your web server to get any changes made to the php.ini to take effect. you need to ALWAYS validate inputs to your code before using them. if you are selecting from existing catalog (id) values, you should have some type of select menu and not require the user to remember and type in values. another recommendation is to separate the database specific code, that knows how to query for and fetch data, from the presentation code, that knows how to produce the output from that data. to do this, just fetch all the data into an appropriately named php variable, then test/loop over this variable in the html document. this will make testing easier, since you can 'see' if all the data you are getting is what you expect (it also makes asking for help easier since someone can make up some data to see what your code is actually doing, without needing any of your actual database information.) next, add the following line of code near the start of your php code so that you can see what data is actually being submitted - echo '<pre>'; print_r($_POST); echo '</pre>'; by putting the numerical index 1st, the array(s) of data being submitted are not what you think. lastly, the reason you are not getting the ITEM_NAME form fields is because the html markup is broken. don't concatenate things unless needed. you should also validate your resulting html markup at validator.w3.org
  3. to get php to help you, find the php.ini that php is using and set error_reporting to E_ALL, display_errors to ON, and output_buffing to OFF. stop and start your web server to get any changes made to the php.ini to take effect. you should then be getting some php errors when you run your code that will help you find what the problem is.
  4. a. the echoed time values should have been correct. are you sure about the posted code and the output that you got? b. browsers and web servers don't interact in real-time. even if you try to flush() the output, you are not very likely to get the result you want (see the php.net documentation for the flush() statement to see all the problems with trying to do it this way.) c. people don't like to wait on web pages to display things for x amount out time (it's either too long of a value or too short of one to suit the current visitor) or to redirect around on your site. the only redirect you have upon successful completion of post method form processing code should be to the exact same url of the current page to cause a get request for that page. if you want to display a one-time success message, store it in a session variable, then test/display/clear that session variable at the appropriate place in the html document. any navigation to other pages should be handled using navigation links where the visitor can choose where they want to go to next.
  5. no. this results in a bad User eXperience (UX), takes more code, and gets your users used to automatically changing urls on your site, which increases the chance of a phishing site working. the form processing code should be on the same page as the form and the only redirect, upon successfully completing the form processing code, should be to the exact same url of the current page, to cause a get request for that page. any navigation to other pages should be via navigation links that the user can choose where he/she wants to go to. the form processing code would go above the start of the html document. you should also re-populate the form field values/selections when you re-display the form when there are validation errors. you didn't provide any details, but post method form processing code should - detect that a post method form was submitted before accessing any of the form data. if there is more than one form on a page, add logic to detect a unique value in the form data (a hidden field) to control which form processing code to execute. keep the submitted form data as an array, then use elements in the array throughout the rest of the code. trim all input data before validating it. you can do this with one array_map() statement, since you are keeping and operating on the data as a array. validate all the inputs, storing validation error messages in an array, using the field name or another appropriate name as the array index. this array is also an error flag. if the array is empty, there are no errors and you can use the submitted data. you can test/display the contents of this array at the appropriate point in the html document. if there are no validation errors, use the submitted data. if there are no (new) errors after using the submitted data, redirect to the exact same url of the page to cause a get request. if you want to display a one-time success message, store it in a session variable, then test/display/clear that variable at the appropriate point in the html document.
  6. the username is a value that originally came from external submitted data. depending on your registration code's validation logic, it could contain anything, such as a hexadecimal encoded string, consisting of just letters and numbers (a hexadecimal encoded string, in a non-string context, will be decoded into whatever string it actually contains), or it could contain single-quotes, that if put directly into an sql query will allow sql injection. it sounds like you think that using a prepared query ONCE, when the data was first submitted and stored makes the value safe to use in all future queries. it does not. it only made that first query safe. any value that ever came from external, unknown, or dynamic data (recently, a year ago, or a year from now, when your application gets updated to get usernames via a call to an external api, where you don't know what type of characters it might contain) must treat the value as unsafe in whatever context the value is being used in (sql, html/css/javascript, email header, filename, system/shell, ...)
  7. you need to define what output your code is going to produce (before you write the code.) if each of the three sections of data is to be a separate html table, you need an opening <table> tag at the start of each table and a closing </table> tag after you have output all the <tr> ... </tr> rows in the table. we cannot help you with any problem with code you tried unless you post that code. you have one opening <form ...> tag for each of the three sections of data, but you are outputting a closing </form> tag inside the data loop. after the 1st closing </form> tag, for the 1st row of data, the browser doesn't have any idea what the rest of the form fields and submit buttons are for. are you sure you even need/want forms for this part of the output? why are you even outputting the data values in readonly form fields?
  8. the html markup has a number of mistakes - some missing <tr></tr> tags, no closing </table> tags, and opening/closing <form></form> tags in the wrong places. this last item is probably what's causing the wrong operation. you should validate the html of the resulting page at validator.w3.org for what you are apparently doing, a 'view more' link, just use a button as a html link, with a type id (paye/contract/permanent) and a record id as get parameters in the link. there's really no need for the post method forms (and the search form should use method = 'get'.)
  9. if you are currently getting undefined index errors, it means $row exists, but doesn't contain what you think. what columns are in the uni2020 table? what does using var_dump($row); show? the above line of code is not doing anything, because of the ; on the end of it. a lot of these issues would not exist if you organized your code better. your code should be laid out in this general order - initialization - define, require, create, ... things your page needs, such as the session_start() statement, a database connection, configuration values, ... post method form processing code - a post method form should be used for things that create/update data on the server or perform an action such as sending an email. you should detect if a post method form has been submitted before using any of the form data. get method business logic - get/create data needed to display the dynamic content on the web page. you should fetch the data from any query into an appropriately named php variable, then test/reference that variable in the html document. html document/template - using simple php code or an actual template system, produce the actual html document, using the data produced from the above sections of code. the php error settings should be in the php.ini on your system, not in your code file. next, you need to validate all inputs to any section of code before using them, setting up and displaying a user error message for any 'required' input that doesn't contain an expected value. if $_GET['ID'] is required for the page to work, it is a user error if it doesn't exist. you should be setting up a message for the user telling them that no UniversityCourse has been selected. at the point of echoing the result from the SELECT query, if the query did not match any data, you should be outputting a message stating so, and only attempt to echo the values if they exist. inside the post method form processing code, if any of the inputs are 'required', but they are empty, that's a user error. you should be setting up a unique message for each empty input, telling the user which inputs they did not enter a value for.
  10. there are three current problems - 1. you are getting a fatal runtime error, due to both where you put the php statements and that one of the statements is using a wrong variable name, but you don't have php's error related settings set up so that php will help you. when learning, developing, and debugging code/query(ies), you need to display all php errors. find the php.ini that php is using and set error_reporting to E_ALL and set display_errors to ON. stop and start your web server to insure that any changes made to the php.ini will take effect. 2. where you put those lines of code is nonsense. you put them before the point where you are executing the sql query. this says you are not even looking at what you are doing. you must be aware of what each line of code is doing and what it is contributing to the overall goal. the first line of code, which is attempting to fetch all the rows of data from the query, should replace the current line of code that's fetching just one row of data. it goes in your program at the point where you are fetching the data from the query, which would be after the point where you are executing the query. the second line of code is the start of the loop. it would go at the point in the html document where you are going to repeat the output for each user. you would 'close' the loop, with a } at the end of the block of html that you are repeating for each user. 3. the first line of code you copied, is using a wrong variable name. copying code is not programming. that's just you acting like a human Optical Character Reader (OCR) program. again, you must actually look at and read what the lines of code are doing. in your code, the $start variable (which is poorly named, use something like $stmt to indicate the variable holds a PDOStatement object), is what you would be calling the ->fetchAll() method on.
  11. the sub-query was originally selecting everything, the g.*. you need to select the end column, so that there is a t.end for the outer query to test.
  12. does any part of the output you got look like it would correspond to the next step of -
  13. the following debugging code will show you what the submitted form data looks like - echo '<pre>'; print_r($_POST); echo '</pre>';
  14. where's your attempt at doing this? just repeating something someone else told you to do isn't programming and isn't learning how to program.
  15. for the first step - make the checkbox field an array, with the array index being the user_id value - <td><input type="checkbox" name="checkbox[<?php echo $row['user_id']; ?>]"></td>
×
×
  • 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.