Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,356
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. you cannot concatenate general php logic together with a string. you can only concatenate php code that evaluates to a string. the reason it's displaying the id is because you are concatenating the result of the $id = $_GET['id']; assignment statement onto the end of the string in $accom. that's the end of the concatenation in the existing code. the rest of the strings being built in the php code are being discarded, because they are not 'attached' to anything. you would need to use $accom .= to add the string that's being built inside of the while(){} loop and again for the string that's being built after the end of the conditional logic. edit: you would also need to terminate the string assignment statement, right before the (needless) $id = $_GET['id']; assignment statement, with a ; rather than with a concatenation dot. you should also use a prepared query when supplying external, unknown, dynamic values to a query when it gets executed, instead of putting values directly into the sql query statement.
  2. based on the error message and the displayed spacing in the posted code, there are probably some non-printing/non-ascii character(s) between the AND and the 's (incorrect quote usage around a column name) or just the s (correct quote usage around a column name), that's breaking the sql query syntax. when you copy/pasted the echoed sql query syntax to run it directly against the database server, you are only getting the printing characters, which eliminates the cause of the sql syntax error. when you alter your code to use @Barand's suggestions, i recommend that you delete and retype everything between the end of the AND and the s. as to the query 'working' with the quotes around 'start_date', making it string, rather than a column name, a string starting with s is greater than a string starting with a numerical digit, so that (version of the) query may be returning data, but it's not because the date comparison is working.
  3. don't actually move any data between tables. in fact, once 'live' data is inserted into a table, it is almost never actually deleted. all you need to do is record and use a 'status' value. you should have a user table that holds the unique, one-time, user information. the auto-increment integer id column in this table establishes a user_id that you would use to relate any other user data, such as the user's status, back to the user it belongs to. you would have a status table that defines the different status values (id and name columns.) the auto-increment integer id column in this table establishes a status_id that you would use to relate any status data back to the status name. you would then have a user_status table (id, user_id, status_id, datetime, ... columns) that is used to hold the user status records. you would insert a new row in this table for each transaction that affects a user's status. when the user registers, after you insert the row in the user table, you would get the last insert id from that query, then insert a row in the user_status table with a status_id value that corresponds to a 'new' non-approved user. you would query to get a list of the 'new' users to select which one(s) you want to approve. when you submit this information, you would insert new row(s) in the user_status table with the selected user_id and the status_id value that corresponds to the 'approved' state (or any other state you specifically select via a form input.) to query to get the 'current' status for any user(s), you would get the group-wise latest/highest row per user_id value.
  4. check is a reserved work and should not be used as a column name. either use a different name for that column or you must enclose the column name in back-ticks to cause it to be treated as an identifier.
  5. $this (programming pun intended) is the correct syntax, but produced a different error than the one you posted about the undefined variable. what was the error message in $this case? i'm going to guess that the database connection probably failed and there's no useful error handling in the code. while not the cause of the most immediate problem, your main code should be responsible for creating the database connection, then use dependency injection to supply that to any class that needs it. by making each class responsible for getting a specific database connection, your code is not general purpose. if the data source changes, to use an additional/different database type or using a remote api, you would need to go through and edit all the current code.
  6. odd syntax errors are often caused by copy/pasting code from web pages where it has been 'published' and 'beautified'. it contains non-ascii characters that when treated in a php code context breaks the php code. the solution is to delete and re-type the line of code. there should be no quotes in the print_r() output around the associative array index names (just tested.) there's something going in your form field name attributes. what is the code/markup for your form fields?
  7. you also have a reply in your previous thread pointing out an issue with using both bindParam() and supplying an array to the ->execute(...) call -
  8. don't use variable-variables, ever. they are not needed, ever, and for the posted code, those bindParam() statements aren't doing anything. you are overriding them by supplying an array to the ->execute(...) call. using bindParam/bindValue and supplying an array of value to the ->execute(...) call are mutually exclusive methods of supplying values to the query. you should simply supply an array of values to the ->execute(...) call. i was hoping that getting working php/pdo errors would point to a problem i saw in the code. you are hard-coding the table name (Sites) in the $sql query you are building, rather than using the supplied name. since this table name doesn't match the list of columns you are supplying, you should have been getting a pdo/mysql error about unknown columns in the query at the execution of the ->prepare() call.
  9. you have to find what's causing a problem in order to fix it, otherwise you are just putting Band-Aids on top of symptoms, and the real problem remains. there are significant problems in the posted code - no comments to let anyone know what the intent of any section is, variables created for nothing, inconstant/no error handling, putting external data directly into sql query statements, running queries inside of loops... you will only see a http 500 error page in a browser due to a 'primary' request to a page, not an ajax request. if you are seeing a http 500 error page, it's for the action of the form - userlistssiexport.php?id=$coursefilterid. what is the code for userlistssiexport.php? and it's not any of the posted code because there is no $_GET['id'] or $_POST variables, the data that the form will submit, anywhere in the code you have posted.
  10. the code handling that from submission isn't even part of the posted code, though it should be - the form should submit to the same page it is on, so the most immediate problem is in some different code. you need to find the php.ini that php is using and set error_reporting to E_ALL and set display_errors to ON, so that php will report and display all the errors it detects. stop and start your web server to insure that any changes made to the php.ini will take effect and then use a phpinfo(); statement in a .php script file to check that those settings actually got set to those values.
  11. that's not what I stated/asked about php's error related settings. you are setting the pdo error mode to exceptions (twice.) what this does is cause an error with a prepare(), query(), exec(), execute(), ... statement to throw an exception. if you don't catch the exception in your code, php will catch it. if php's error related settings are not set up to report and display (or log) all php errors, nothing will happen with this information. your script will just halt at the point of the error. as to the try/catch block you do have for the connection. a connection error is a fatal problem for a database dependent web page. your code should stop upon such an error so that you don't get follow-on errors by trying to use a connection that doesn't exist. if you just remove that try/catch logic and let php catch the exception, any connection error will get displayed or logged the same as php errors. the only time you should have a try/catch block for database statement errors is if the visitor to the site can correct an error that he/she caused, such as inserting/updating duplicate or out of range values. in all other cases, you might as well save the typing and just let php catch and handle the database exception.
  12. you are most likely getting an error from the ->prepare() call. do you have php's error_reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your system, so that php will help you by reporting and displaying all the errors it detects?
  13. what symptom or error did you see that leads you to believe that?
  14. regardless of what you do to pre-check the username, from the point in time when you pre-check if the username is available, to the point where the user actually submits the form, someone else could have submitted the same username and it is no longer available. your database table must enforce uniqueness, by defining the relevant column(s) to be unique indexes. you must then have error checking for the INSERT query to detect if a duplicate was attempted to be inserted, and report back to the user if the username already exists.
  15. there's no reason for the php code to even be making a database connection, unless it was testing if the database server is running and the connection credentials are valid, which it isn't doing.
  16. just about everything in this code is working against you finding out what the code is actually doing. put the php error related settings into the php.ini on your system. if for some reason you can only (temporarily) put them into your code, put them before all other php statements and put them into both of the relevant files. you are likely having an error at the session_start() statements... don't use output buffering unless you want to specifically buffer output. by always using output buffering, you don't know if the lack of php errors or other indications from your code, is due to the operation of the code or due to the operation of the output buffering. all output, except due to a fatal php error, will be discarded. the only redirect inside post method form processing code, should be to the exact same url of the current page upon successful (no errors) completion of the form processing code. this will cause a get request for that page. then provide navigation links to allow the visitor to go elsewhere on the site. don't loop to fetch the result from a query that will match at most one row of data. just fetch and test the result of the fetch statement. you are also testing the num_rows value inside the loop. if there are no rows, the loop will never be entered, and the num_rows test will never get executed. you should store the user's id (auto-increment integer) in the session variable to indicate who is logged in, not the (raw) username, which could be anything, including javascript/sql,... there's actually a bunch or other issues with this code, which i will leave for others to mention.
  17. php is a server-side scripting language. if you are not making a http(s) request to a web server for the .php file, the php language engine isn't being invoked. when you directly enter the URL of the .php file in question in your browser's address bar, do you get the expected output?
  18. are you using full <?php opening tags, per the problem in one of your previous threads? https://forums.phpfreaks.com/topic/311034-includes-not-being-displayed-on-page how about the other improvements made in that thread? you seem to have gone backwards.
  19. what URL to the file through the web server are you using? it should be something like - http://localhost/your_file.php
  20. method is misspelt in the form tag, so this is actually a get method form and none of the $_POST data exists.
  21. you need to read @requinix's reply about the data type of the expires column. actually, you need to slow down, define what you want each part of the code to do, then test and observe the result you get at each step so that you are actually learning by doing. the php error message you most recently got was the same and for the same reason as at the start of this thread, a different number of prepared query place-holders vs the number of bound inputs in the php code. you also have a case later in the code that will produce the same error due to the use of an $email variable in an sql query vs correctly using a place-holder in a prepared query. next, you have have a serious functionality problem in that your code will allow empty password/password2 inputs to reset the user's password, due to not having exit; statements after every redirect. this is made worse by the form and the form processing code being on different pages, which requires the user to keep reentering these values every time there is a validation error. you should put the form and the form processing code on the same page, the only redirect you should have in your form processing code is to the exact same url as the current page upon successful completion of the form processing code, and you should always have an exit; statement after every redirect.
  22. you can use the PDO classes (PDO, PDOStatement, and PDOException) at any time in any code.
  23. if you are asking this because the mysqli prepared query programming interface is ridiculously overcomplicated and inconsistent, switch to the much simpler, more consistent, and better designed PDO extension. no. it only works for string data and then only if the character set that php is using is the same as your database table's. a prepared query works for all data types. also, aside from trimming data, mainly so that you can detect if all white-space characters were entered, don't alter user submitted data. just validate data and use it if it passes validation. by altering data, you are changing the meaning of it which can lead to security holes or unexpected operation in your application, having nothing to do with sql special characters in data values. yes. a true prepared query (PDO has an emulated prepared query that suffers from the same character set mismatch between php and your database table's) prevents any sql special characters in data from breaking the sql query syntax, by separating the parsing of the sql query syntax from the evaluation of the data values.
  24. the simplest and most efficient way of doing this would be to query the database to get all the data matching the date range you are trying to display, fetch all the data into a php array variable, using the date value as the main array index. if there can be more than one piece of data per day, when you are fetching the data store it as an array of rows of data. then, as you are looping to produce the output for the calendar, for each day, form a date value in exactly the same format as was used for the array index values, test if an element isset() in the array of data, and if so, reference it when you are producing the output for that calendar's day.
  25. if you do this - you will end up with code that looks like this - $out = ''; foreach($indexed_data as $type=>$arr) { // start a group $out .= "<optgroup label='$type'>"; foreach($arr as $row) { // add the output for each $row of data within the group $out .= "your makdup here for the <option ...>...</option> tag"; } // finish the group $out .= "</optgroup>"; }
×
×
  • 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.