Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. if your goal is to do this using php, your first step will be to correct the way you are querying the database. actually, you should correct the php code in any case as it has several problems. you should have ONE query that gets the data you want in the order that you want it. the current code, getting the min and max id, then running queries inside of loops, is not workable or efficient. there's no guarantee that your id's will be contiguous and running queries inside of loops is the type of thing that gets a hosting account suspended for using too many resources. you would write one query using JOIN's between the related tables. you would build the ORDER BY term in the query dynamically based on $_GET variables that come from the links in the html table headings. your program logic would need to be - 1) determine from any sort related $_GET variables, what the ORDER BY term needs to be. use a default sorting order, such as by last name, first name, if no sort column/direction is selected. 2) run one JOIN'ed query that gets the data you want in the order that you want it 3) output the html for the table, with the column header items being links that tell the code if to sort by that column and which direction to sort. the direction to sort is either a default (asc), if that column is not the active column being used to sort, and it's actually the opposite direction, if that column is the current column being sorted. the sort links should have get parameters similar to ?sortby=column_name&dir=asc for example, on the first visit to your page, the sort links should all default to dir=asc. if you click on the MVP Score sort link, ?sortby=MVP_Score&dir=ASC, the php code would take the $_GET['sortby'] and $_GET['dir'] and produce an ORDER BY MVP_Score ASC term in the query. note: do not put these values directly into a query as that will allow sql injection, upon which no escape function can protect against and which even prepared queries cannot protect against since these values cannot be put into a prepared query using place-holders. your code needs to validate that the column and direction are only and exactly permitted values. in this example, since one of the html table columns has been clicked on, there is a sortby and dir value, when you build the sort links in the html table headers, you would invert the direction value in the link so that clicking it again will produce the opposite sort result. 4) then simply loop over the result set from the one query to output the data in the html table.
  2. blank php pages are usually the result of a fatal php parse error or a fatal run time error. since the code ran on one server and there's nothing present in the 'view source' it's most likely a fatal run time error. what does adding the following lines, immediately after the first opening <?php tag on the main page, show - ini_set("display_errors", "1"); error_reporting(-1);
  3. another reason why you wouldn't dynamically create database tables based on usernames, or any other user entered data, on a case-sensitive operating system, the table names are also case-sensitive. unless you have taken steps to normalize the usernames, you could end up with multiple tables - Macgyver, macgyver, MACGYVER, and any other letter-case variations, that would all be different tables for the same entered username.
  4. two suggestions then - 1) turn off output buffering (it's probably set in your php.ini). you should only buffer output when you want to, at all other times, it just creates problems by hiding what's actually being output by your code. 2) the query failing due to an error is a fatal application problem. code that's dependent on the query working, shouldn't be ran. your code should take an appropriate action when there is a query error, such as not running any follow-on code. you would actually want to output a user message - 'sorry this page cannot complete the requested action' and display (when debugging) and log (on a live server) all the information you have about the problem. if you use php's trigger_error() statement for handling the actual error information, it follows the php error_reporting/display_errors/log_errors settings, so you can set if errors are displayed or logged at run-time by setting the php settings.
  5. your posted code throws the following exception for me - therefore, either that code isn't being ran at all or you are doing something like a header() redirect later on the page, with output_buffering turned on, and you are not seeing the output from the catch block.
  6. the database name isn't a piece of data and cannot be a place-holder/bound data in a prepared query. have you set the pdo error mode to exceptions in your database connection code so that the try/catch block would have any effect?
  7. the symptoms (if not due to a broken server/php installation) of unexplained operation that doesn't match what the code should be doing are typical of the code being ran on the server not being the same code you are looking at, either because the upload/ftp to the server failed, there are multiple copies of the code on the server at different paths and you are including the wrong file(s) (possibly due to php's include_path setting), or the server has disk-caching (or even a php bytecode cache) set to an extremely long cache time and changes to the files aren't taking effect immediately. also, the .zip file you linked to, at the time i grabbed a copy, doesn't contain any code that sets the variables $search, $search_html..., so it's obviously not the actual code you are writing about and for a case where entire web pages don't function as expected, it takes having all the code (less any database credentials) to either prove or eliminate the code as the cause of the problem. btw - in just the index.php code, you have a bunch of repetitive, hard-coded html, that only differs in one line of content, a minor variation of a class name and an id. if you are going to the trouble of using a server-side scripting language, you might as well put the programming language to work for you, rather than write out block after block of code that's hard to maintain, troubleshoot, and reuse. for just the slide html (you can use this same technique to reduce the code for the tiles), using php to dynamically produce the repetitive sections, reduces the number of lines in the index.php file by half - // define the content/differences for the slide html $slide_content[1] = '<a border="0" outline="0" href="images/DINLineCard(Front Only).pdf"target="_blank"><img border="0" outline="0" src="images/slide_images/Linecardslide.jpg" alt="line card" width="100%" height="100%" style="height:425px;"></a> <br />'; $slide_content[2] = '<img src="images/slide_images/StockReleaseslide.jpg" alt="" width="100%" height="100%" style="height:425px;">'; $slide_content[3] = '<img src="images/slide_images/in-housetestingslide.jpg" alt="" width="100%" height="100%" style="height:425px;">'; $slide_content[4] = '<img src="images/slide_images/QualityPerformance.jpg" alt="" width="100%" height="100%" style="height:425px">'; $slide_content[5] = '<img src="images/slide_images/99OnTime.jpg" alt="" width="100%" height="100%" style="height:425px">'; $last = ''; // build the class = "slide last" html after 1st pass through loop ?> <div id="header_container" class="header_container"> <table width="100%" > <tr> <td colspan="2" style="margin-top:25px;background-color:#cccccc;"> <div class="slider_holder" id="my_slides"> <?php foreach($slide_content as $id=>$content){ ?> <div class="slide<?php echo $last; ?>"> <div class="whole_slide_container"> <div class="slide_control_button_container_left" onclick="previous();" > <table height="100%"><tr><td valign="middle" align="center" > <img src="images/slide_images/leftArrow.png" /> </td></tr></table> </div> <div class="slide_content_container"> <?php echo $content; ?> </div> <div class="slide_control_button_container_bottom" id="pause_slide_<?php echo $id; ?>" onclick="pause(this.id);" >PAUSE</div> <div class="slide_control_button_container_right" onclick="next();"> <table height="100%"><tr><td valign="middle" align="center"> <img src="images/slide_images/rightArrow.png" /> </td></tr></table> </div> </div> </div> <?php $last = ' last'; // 2nd and higher loops } ?>
  8. how exactly did you make this change and have you checked, with a show variables query, that the database server shows that it actually got changed to an ON value?
  9. you will need to troubleshoot what is happening or not happening in order to find the cause of the problem. assuming that php is installed and running on the server, there's nothing inherent in the type of web hosting setup that would cause this. however, there are php configuration settings and minor things that have been changed/removed over time in the php language that could cause code that worked on one server to not work on another. what exactly is the output you are getting when you visit your site and if it is a blank page, what does the 'view source' of that blank page show? also, have you checked the web server error logs for any errors that would help pin down the problem?
  10. the reason you are getting errors at the mysqli_num_rows() statement, is because your program logic is not correct and your query is failing due to an error of some kind. the $check variable will be a false value when the query fails due to an error. you are then trying to use that false value in the mysqli_num_rows($check) statement. your program logic should be testing if $check is a true value, without the !. the reason your query is failing, is because you don't have single-quotes around the '$name' variable inside the sql statement. finally, you don't need all that program logic anyway. you should not have a database table laid out like that. the data is not normalized, requiring you to write a ton of program logic to find, insert, update, or delete any of the data. you should instead have one row for each same meaning data item, not columns in a row for each same meaning data item.
  11. you need to have some error checking logic on all your database queries. you also need to have php's error_reporting set to E_ALL (in your php.ini) and for debugging have display_errors set to ON (again in your php.ini) and when not debugging the site, have display_errors set to OFF and log_errors set to ON. i suspect either the database queries are failing due to a problem with the table name (capitalization or spelling) or fatal php parse or run-time errors.
  12. something tells me you have had a problem with a database and are now trying things to prevent sql injection? are you sure the problem was through sql injection or did someone gain direct access to the database by bruit force determining the username/password database connection credentials (most database engines don't have any sort of failed login detection/reporting)? another reason the black-list method isn't the right way of preventing sql injection is because, depending on how your query is using external data, an encoded string (i won't mention how it's encoded) can be crafted that contains no sql keyword, but which a database engine like mysql will happily convert back to sql statements and allow sql injection.
  13. if you are properly escaping string data (or using prepared queries), those keywords (and many more that are not in your list) cannot be used to inject sql. numerical data values are another story, but you should be validating numerical data (or using prepared queries) to insure the data only contains a properly formatted number of the correct type. see this related post - http://forums.phpfreaks.com/topic/294273-question/?p=1504405
  14. no one can tell where your code and question starts and stops. try posting your question again, using the forum's bbcode tags (the edit form's <> button) around the code sections. also, posting snippets of code, out of context, possibly out of order, and not showing where and how functions are being called, doesn't help us to see what your overall program logic may be doing that could be causing a problem. the code you post must be complete enough so that it reproduces the problem you are asking for help with.
  15. ^^^ your 'add to cart' code is not using the product_id as the myCart array index, so your 'remove from cart' code isn't finding the correct item in the cart. your add to cart code should be using the product_id as the array index. also, your cart should only contain the product_id (as the array indexes) and the quantity (as the array values.) by passing the item description and the price through the form and then using those values in your cart logic and displaying those values later, you have several security and functional problems in your code. by using only the product_id and quantity, which are both integer values, you can validate them for safety purposes and by using the product_id as the array index, you can easily check if an item has already been added to the cart to avoid duplicate entries in the cart.
  16. in the case of looping and testing values, again it depends. if this is data from a database query and all you are interested in is if the data was found, you would perform the test in the database query. if validating if a variable is one any of many permitted values, having the permitted values in an array and using php's array functions would produce the most efficient code, rather than looping until a value is found or not are found...
  17. from the php coding help forum's description line - we are not here to find, write, or give you code for things you need. if you need design help, after you have made an attempt at defining the steps needed to perform each task, you can ask specific questions in the 'application design' forum section. once you have code you have written and you have made an effort to solve the problems with it yourself, you can post your code and any errors or symptoms in one of the specific coding language help forum sections.
  18. in programming, there are multiple different ways of accomplishing anything and the best answer depends on what you are actually doing. if each later test is preformed based on the result of the previous tests, you would need to write out the nested logic as needed. if the tests are independent and are just testing different values in one variable, you would instead use a switch/case statement or even simpler, a look-up array to map one value to another. short answer: it depends. do you have a specific problem you are trying to solve?
  19. ^^^ using this programming style doesn't lend itself to checking if the query matched any rows, nor does it lend itself to using prepared queries and using the same basic program logic for non-prepared and prepared queries. it also ties your presentation logic to the database library being used and it requires that you run the query again should you need to iterate over the result set more than once. i recommend that you not use this programming style and instead fetch the data into a php array variable in your database dependent code, using the pdo ->fetchAll() method in those cases where you expect one or more rows, and using the pdo ->fetch() method when you expect at most only one row. you can then test the size of the array holding the data (see the count() function) to determine how many rows are in it and then use the same basic foreach() loop you have now to loop over the array of data. edit: your code also implies that you are opening a database connection, running one query, then closing the database connection. your application should only open one database connection, then close it only after you have finished using it.
  20. a solution to what? you started this thread with a snippet of code that lacked any context upon which to help you with what you eventually stated that piece of code should be doing and the code you finally posted, which contains at least two php errors and won't run at all, doesn't have the specific things in it you have been asking about. keeping in mind that we ONLY SEE the information that you supply, at this point we don't know what code you tried with the things in it you have asked about or what symptom or errors you got from that code that you need help with. go back and reread everything in this thread, from the point of view of someone that only knows what your code, data, and symptoms are from the information that's posted in this thread.
  21. the split pattern is not included, unless you use the PREG_SPLIT_DELIM_CAPTURE flag, but that will give you an array with three entries, that you must combine the first two back together. you should actually use preg_match_all() with a pattern that gets everything up to and including the 4 digit number and everything after the 4 digit number. based on my limited regex knowledge, this does what you are asking - preg_match_all('/(.*[0-9]{4})\s+(.*)/', $row['vehicle'],$parts); echo 'up to and including the 4 digit number - ' . $parts[1][0] . '<br>'; echo 'after the 4 digit number - ' . $parts[2][0];
  22. the ->fetchAll() method returns an array of arrays. in your foreach() loop, $status is an array holding the data for each row. $statID will just be the zero referenced numerical array indexes of the main array. using foreach ($arrAllStatus as $row) { would perhaps be clearer. you would then reference the two columns you have selected using - $row['StatusID'] and $row['Status']
  23. since this data in the different tables is not related to each other, how do want the output to appear, especially if you are paginating it? in any case, to do this in one query, you would use a UNION query, but you would have to select the same number and meaning columns (even if you have to select a static/dummy text string), so that similar meaning data from the different tables would fall into the same column in the result set (i.e. where you are selecting products.code in the second table, you would need to select a dummy value in the other UNION queries, in that same position in the select list, so that the name and description/content column data from all the tables would align in the correct columns in the result set.) edit: you would also want to apply your database's string escape function only once to the $keywords value, then use that escaped value in the queries (or use prepared queries.)
  24. here's another way to do this in a select query - SELECT ID,Name,Position FROM tableA ORDER BY Position < (select pos from tableB), Position ASC
  25. an appropriate select query - (SELECT ID,Name,Position FROM tableA WHERE Position >= (select pos from tableB) ORDER BY Position ASC) UNION (SELECT ID,Name,Position FROM tableA WHERE Position < (select pos from tableB) ORDER BY Position ASC) tableb just holds the current position of the 1st/top row to display. when you update/increment the tableb.pos column to rotate the display, make sure it wraps around from 9 to 1 (whatever the max value in your tablea.position column is.)
×
×
  • 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.