Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. edit: pretty much repeating what they ^^^ said - your data is not stored/indexed in a way that you can simply produce the desired output from it. also, 'tools' is a type/category of items. assuming that wherever this data is retrieved from, you are only getting the data that you want in the order that you want it, or that you would filter the data before using it, see the following - $items['tools']['good']['quantity'] = 3; $items['tools']['good']['price'] = 10.00; $items['tools']['broken']['quantity'] = 3; $items['tools']['broken']['price'] = 5.00; $curency = '$'; foreach($items as $type=>$arr) { foreach($arr as $condition=>$item) { $price = number_format($item['price'],2); echo "We have {$item['quantity']} $condition $type at $curency$price each.<br>"; } }
  2. // recursive function to trim data function _trim($val){ if(is_array($val)){ return array_map('_trim',$val); // recurse if an array } else { return trim($val); // call php's trim function, if not an array } } $post = []; // define an array to hold a trimmed, working copy of the submitted form data // inside the form processing code, get a trimmed copy of the submitted form data $post = array_map('_trim',$_POST); // you would refernce the elements in $post in the rest of the code, i.e. $post['search_products']
  3. fetching data from a mysqli prepared query doesn't work the way you are used to for fetching data from a query. you will need to consult the documentation for the extra code necessary, or you can switch to the much simpler PDO database extension, which does work for fetching the data from a prepared query in the way you are used to. also, if you use exceptions for database statement errors, and in most cases let php catch and handle the exception, you won't have to add logic (or can remove the logic you have now) that's testing the result of the prepare() and execute() statements, simplifying the code.
  4. forget about all the bindParam calls. just supply an array of the values to the ->execute([$ip,$filename]) method call. if the filename is being changed, just call $stmt->execute([$ip,$filename]) again after each new value is assigned to $filename.
  5. @sanram123 the t, the r, and the h are table alias names and belong where they are shown. @Birdmansplace what symptom or error are you getting that leads you to believe something isn't working? you need to provide information about what you saw in order to narrow down the possibilities. also, why do you have two completely different sets of database connection code? are both of those on the same page or is the posted code for two separate pages? your database connection code should be in a separate .php file that you 'require' when needed and each page should only make one database connection.
  6. have you defined what you want the output to look like? this will define what data you need to get/produce, which will also define what inputs you need. you would then query to get the necessary data in the order that you want it. you would then loop over that data to produce the output that you want. btw - some of the xPDF libraries have writeHTML() methods that allow you to produce html (or capture the html of an existing page), then supply that as input to produce the pdf document, so that you don't need to build the pdf document at the x/y/cell level.
  7. no. you would use one file, that accepts a specialty id as an input, then uses a query with a WHERE clause in it to match the requested specialty information. the specialties should be defined in a database table, with an id and a name. this will assign an id to each specialty. you would query this table to retrieve all the specialties to produce some sort of navigation/selection menu. when the visitor to the page picks a specialty via the navigation/selection menu, the submitted specialty id would be used in the code in the single file to cause the correct data to be retrieved and used to display the contents on the page.
  8. its probably the short opening php tag on line 1 in the posted code.
  9. what result or symptom are you getting that leads you to believe that? btw - the short opening php tags <? my not be enabled on your server. you should ALWAYS use full opening <?php tags. You can also use a combined opening/echo tag <?=
  10. this logic should NOT be combined in one statement. here's why. this code is trying to process a form submission. the visitor who was presented with the form and submitted it expects the form processing code to run or to be told exactly why it didn't. these session variables are inputs to the process and must be validated, along with validating the form data, before actually using the form data. each condition that will prevent the form processing code from running should result in a unique and helpful error message being setup and displayed telling the visitor why the submitted form was not processed. for those things that the visitor has control over, he can correct, then go through the process of submitting the form again. if the process is in a state where no further forms of the type that was submitted can be processed, the error message should indicate this. your form processing code should - detect if a post method form has been submitted. if there is more than one type of form, detect which form was submitted. trim all the form data, so that you can detect if all white-space characters where entered. validate all the input data, setting error messages in an array, using an array index indicating the input the error corresponds to. you would display the contents of the errors array at the appropriate point in the html document. if there are no errors (the array holding the error messages is empty), use the submitted form data. btw - once a form has been submitted, except for unchecked check boxes and radio buttons, all form inputs will be set. there's no good reason to have isset() tests for these type of inputs as this will just hide programming mistakes.
  11. the OP solved this on another forum.
  12. the associative index for the COUNT(*) expression is actually something like $row['COUNT(*)']. to simplify this, add an alias name for the COUNT(*) expression in the query and use that alias name for the associative index. next, both of the query examples you have shown will/probably match at most one row. why you are using a loop to fetch the data. just fetch the single row without the loop.
  13. what do you want the output to actually be? where do you want to show the totals and do you really want to repeat all the id/name/designation information?
  14. in addition, you need to always have error handling for database statements. if you had, you would know that the query is failing, with an error about a non-existent column of the same name as the session variable value. also, using a prepared query would have eliminated the problem, since you would not be trying to put data directly into the sql query statement.
  15. if you are asking about the value zero in the ['error'] element, that means the upload was successful, which you would know by making use of the php.net documentation on uploading files. your existing code should be testing for that value before using any of the uploaded file information and reporting back to the user that the upload failed for any of the other possible values. for the posted print_r() output, if the code 'isn't working', the problem is something else. do you have php's error related settings setup so that all php errors will get displayed or logged?
  16. data related to the user should use the user's id (auto-increment integer primary index from the 'user' table') to relate it back to the user it belongs to. this will result in the least amount of data storage, result in the fastest queries, and allow the user's information (name, username, ...) to be edited without breaking the relationship in the data. you would also store the user's id in the session variable, not the user's name/username, when the user logs in, as this will also support editing the user's information, in addition to supporting the current operation you are asking about. to get any of the other user's information, you would query for it on any page that needs it. tbl_rides needs a user_id column that you would store the $_SESSION['user_id'] value in. also, for the operation you are asking about, if the current visitor is not logged in, you would not display the form, nor run any of the form processing code.
  17. based on the http error page, you are doing this on Windows. the .htaccess file is not keeping the leading dot when downloaded. you need to rename/copy the contents of the htaccess file to a file named .htaccess (with a leading dot.) this should allow the requested URL to get rewritten and should work.
  18. your code has no error handling for the database statements that can fail - connection, query, prepare, and execute. as a result of this, you are getting follow-on php errors, that are not where the real problem is at, because the code continues to run when one of these database statements fail. the simplest way of adding error handling for these database statements is to use exceptions for errors and in most cases let php catch and handle the exception, where it will use its error related settings to control what happens with the actual error information (database statement errors will 'automatically' get logged or displayed the same as php errors.) the exception to this rule is when inserting/updating user supplied data and you need to detect duplicate or out of range values. in this case, you code would catch the exception, detect if the error number is for something that your code can handle, then setup a message telling the user what was wrong with the data that they submitted. to use exceptions for errors for the mysqli extension, add the following line of code before the point where you make your database connection - mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); next, if you switch to the much simpler and more consistent PDO extension, over half of the php statements will go away and there's also no good reason to be concatenating multiple lines together when building the sql query statement or html content.
  19. finding a line in a php.ini file that has a value, doesn't mean that that php.ini or that line is being used (syntax errors in a php.ini stop the parsing of the following lines in the file/probably treat all the rest of the file as part of the line where the syntax error is at, w/o any error being reported), which is why i asked what a phpinfo() statement showed for the value. this is also why you need to ALWAYS have the error related settings set to report all errors and to log them on a live/public server.
  20. that's because it is using the same method and is lacking in any logging of information when the success value isn't true. do you have php's error_reporting set to E_ALL and either log_errors set to ON or temporarily (turn off when finished) set display_errors to ON, so that php would help you? while there's nothing php version specific in the code, there is something php configuration specific that could affect the code. allow_url_fopen is probably off (there would be php errors when the code runs.) what does a phpinfo() statement show for allow_url_fopen?
  21. you are probably looking for an absolute file system path, not a http URL - require $_SERVER['DOCUMENT_ROOT'] . '/r/pagevisit.php';
  22. your connection probably doesn't exist and you would be getting a bunch of php errors. you need to ALWAYS have php's error_reporting set to E_ALL and when learning, developing, and debugging code/queries, set display_errors to ON. these settings should be in the php.ini on your system. next, you need to ALWAYS have error handling for all statements that can fail. for database statements - connection, query, prepare, and execute, the easiest way of adding error handling is to use exceptions and in most cases let php catch the exception where it will use its error related settings to control what happens with the actual error information (database errors will automatically get displayed or logged the same as php errors.)
  23. use (NOT) FIND_IN_SET(str,strlist). the strlist parameter can be supplied via a single prepared query place-holder.
  24. if all you are doing is mapping input values to output values, don't write out conditional logic for every possible choice. if the input to output mapping doesn't contain any calculable relationship, define a data structure (array, database table) to map the input to the output. for the example values you have shown, wouldn't you just break apart the value at the '-' character and use the first part as the lowest range value?
  25. also, are php's error related settings set to report and either display or log all errors?
×
×
  • 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.