Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,449
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. the reason you cannot write the query to do what you want, is because your data isn't normalized. by having two separate columns, holding same meaning data (a user id), that only differs in its assigned role - admin or superadmin, you cannot write a simple query that does what you want. also, what if you need more than one admin for a group? you need a separate table to hold this related data (user_id and type - admin/superadmin). then you would simply join that table in your query and get the user id and type for each admin/superadmin for each group.
  2. your form processing code is not testing if the upload worked at all before trying to use the uploaded file information and your current symptom is either due to your form processing code being entirely skipped over due to the conditional tests being false or your form is not using the ?error=n information it does receive. if you use this forum's advanced search (the white star like thing to the right of the search box) and search for find words uploaded and find author mac_gyver, you will get a number of replies concerning testing for upload errors. briefly - both the $_FILES and $_POST array will be empty if the total of the content being submitted exceeds the post_max_size setting. next the file ['name'] element will be set, but the other fields won't be for most of the possible ['error'] element values (see this link for the errors - http://us1.php.net/manual/en/features.file-upload.errors.php), the most common one being that an individual file exceeds the upload_max_filesize setting or in this case No file was uploaded (selected) for a file field (if you don't require an uploaded file from each file field, you will need to test for this error number and ignore it, rather than report it back to the user. however if one or more of the file fields is required, you would need to report back to the user that they must select a file to upload.) so, you must test if a form has been submitted, then test if the $_FILES array is not empty, then for each of the possible file fields test if the ['error'] element is set and is a zero. it also wouldn't hurt to output a distinct and verbose message for each of the possible conditions that have failed telling the user what is wrong with his uploaded file(s) that caused them to not be processed.
  3. you would have one form that encompasses all the checkboxes. the name= ' ... ' attribute of the checkbox form field would be an array, with a name that holds meaning for that field and the array index would be the id of the row from your database table - name='field[234]' when the form is submitted, all the checked checkboxes will exist in the $_POST['field'] array, with the keys being the list of id's. to set the database field value to a 1 for the checked checkboxes, you would use something like - $ids = implode(',',array_keys($_POST['field'])); $query = "UPDATE your_table SET field = 1 WHERE id IN($ids)"; to set the database field value to a 0 for the unchecked checkboxes, you would use something like - $ids = implode(',',array_keys($_POST['field'])); $query = "UPDATE your_table SET field = 0 WHERE id NOT IN($ids)";
  4. debug_backtrace returns an array, you would need to use print_r() with the second parameter set to true to get the output returned as a string that you could write to a file - file_put_contents($file,print_r($data,true),FILE_APPEND | LOCK_EX);
  5. here's some general points about the code you posted - you need to narrow down the problem and just post the relevant code. your page works, but one part is displaying incorrectly. if your entire page wasn't working as expected, posting the code for the entire page would be useful, but that's not the case and posting a wall of hundreds of lines of non-relevant code will just get your post ignored. the only relevant information for your problem in this thread would be what your actual data is (the inputs), the code retrieving that data and outputting it (the processing), and what's wrong with that output (the actual output.) that's actually your database name and the variable/property name should reflect the actual meaning. your tourCMS class should not create its own database connection. you should have one connection in your main code and any class that needs to use it should have it passed into the instance of that class. also, you should not be trying to create your database table each time you make the database connection/each time the page gets requested. attempt to create the database table once, during an installation routine. that line implies that anyone could set admin=1 in the url and access the admin functions (i.e. post information to your database table.) you cannot rely on a simple value in a url/link to determine access restrictions. your login/authentication code is what needs to determine access restrictions. your code is using the mysql_ database library. that is depreciated starting in php5.5 and should not be used for any new code. you should use the mysqli or PDO database library. if you find yourself using stripslashes on data being retrieved from a database, it's likely the data wasn't properly escaped when being put into the database. the \ characters should not be in the actual data in the database table. if they are, given your ->write() method code that is escaping the data, it means that magic_quotes_gpc is on. you need to test if it is on and use stripslashes on the data, then escape it yourself before using it in your insert query. you have 17 lines of code that are making a copy of one variable into another variable. given the limited scope of this code (one function/method), simply use extract() to replace all those lines of code with one statement. also, if you did have a need to run a function on all elements of an array, you can just use array_map(). if you set $entry_display = ''; (an empty string) before the start of your while(){} loop, you can eliminate this else{} statement and prevent an error at the first use of $entry_display .= ....
  6. i'm going to assume you mean it is displaying the first entered data twice. what have you done to debug the problem and pin down exactly where your code and data isn't doing what you expect? is the data in the database table correct? is the problem only in the display logic? what's the HTML output in your browser's 'view source'?
  7. the .bin files are for using the modules/library API code that they provide - http://www.ip2location.com/developers/php
  8. you need to stick with ONE thread for any ONE problem. i have removed your other co-thread and moved this one to the php help forum (it's not actually a mysql problem. it's a php how to get to the point of having a mysql query statement problem.)
  9. you should NOT create a database connection, run one query, close the database connection. you are figuratively killing your database server. you need to create ONE database connection in your main code and use that throughout the code on any page. you would pass the $con variable into your functions as a call-time parameter. at least your insert query is failing due to a sql syntax error (the escaped single-quotes that are part of the sql statement syntax, not part of the data in the statement) and you have no error checking logic to get your code to tell you if and why the query failed.
  10. what is your current form code? depending on which of the suggestions you used, the method you use to loop over the uploaded files changes. edit: or you could just use a foreach(){} loop that would work regardless of the naming of the form fields.
  11. the mysql_ extension is depreciated as of php5.5 and should not be used for new code. you need to either use the mysqli or PDO database libraries. there are countless examples posted all over the place. start with the basic examples posted in the php.net documentation.
  12. you are using the PDO database library for your database connection. you must use PDO statements throughout the rest of the code. you need to have php's error_reporting set to E_ALL (always) and display_errors set to ON to get php to help you. each of the mysql_ database statements will be producing php errors that would have alerted you to the mismatch between your database connection using PDO and the rest of the statements not having a connection of the type they use.
  13. you need to at least provide us with the domain where your sending mail server is at. also, you are not setting a from address (i'm betting when you used the mail() function, you were setting a from address.)
  14. there's no guarantee that the person who wrote this didn't just put in his own call to your script into one of the web site files. since it appears that it is being included (just a guess) you can use debug_backtrace() in the file to get information about how it is being executed. you could simply append the debug_backtrace() output to a log file of your making, using file_put_contents() with the FILE_APPEND attribute.
  15. what steps have you taken to debug what your code and data are doing on your server to pin down exactly at what point in the code they aren't doing what you expect? i.e we don't have the ability to run your code with your data, nor do we have all your relevant code to even attempt to reproduce the problem. also, Please use the forum's bbcode tags (the edit form's <> button) when posting code.
  16. there's really no point in using any seek command for what you are doing. your query(ies) should retrieve just the row(s) that you want. if you have a LIKE query that matches more than one possible row, you would display those matching rows with edit links containing the id for each one. the user editing the information would select that particular row by clicking on one of the edit links. the edit code would use that id to only retrieve the data for that one row.
  17. where to begin.... you need to start with the stated goal for that block of code - check in the database if the users role is either admin or something else. i would restate this as - retrieve the currently logged in user's role in a php variable for use on the current page. and why do i suggest that. a user's role could be changed at any time. you would want that change to take effect on the next page request after the change. next you need to define what (relevant) inputs you have available - i recommend using the user id (it will result in the fastest query, since you will be running this query on any page that needs to check the user's role.) also, you appear to be trying to use a PDO prepared query. i recommend you study the documentation or some tutorials first, as you will need to know how to prepare a query, bind the input data, run the query, and fetch the result, at all, before you can do these things with your data. the code you posted isn't close. then, you can write and test the code needed to accomplish just the state goal. once you have retrieve the currently logged in user's role in a php variable, you can test it's value it in the remainder of the code on the page.
  18. also, your thread has absolutely nothing to do with the Regex forum section that you posted it in. moving thread to the php help section... edit: i also notice you previously posted a thread in the Regex forum that had to be moved. are you a bot script or a real person?
  19. the mysqli_error( ... ) statement requires the mysqli connection link as a parameter. and how do i know that, by reading the documentation and examples for that particular statement in the php.net documentation. you also need to echo the string that mysqli_error returns so that you can see it in the browser.
  20. you need to stop creating new threads for the same issue/code. taking out the mysqli_error() statement only means that the error moved down in the code. you need to go back to your first thread and solve what is wrong with the msyqli_error() statement so that it will then tell you why your query is failing.
  21. a http 500 respons for a php script usually means a fatal parse or a fatal runtime error, but php's error_reporting/display_errors are not set to show all errors. when developing and debugging php code, you must have php's error_reporting set to E_ALL and display_errors set to ON, in your php.ini, so that php will help you.
  22. @Irate, the OP checked the web server access log and it looks like the file isn't being requested directly.
  23. if the script is in the middle of processing the files and it is called again, it could leave some of the files behind/change only some of the database records... also, if the script takes more than a few seconds to run each time, it doing something wrong. short-answer to all of this, without the full code, hard to do more than make guesses.
×
×
  • 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.