Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,356
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. because the for() loop is what is incrementing the $i variable, you would need to put the if ($i % $imagesPerRow == 0) test before you output the image. this would result in an extra <br> before all the output or you would need to add a condition so that it only does this when $i is greater than zero. what i would do is use a foreach() loop instead of a for() loop and use a separate $i variable that gets incremented inside the loop.
  2. the issue isn't that the second image is entirely missing, it's that the first row of output only has one image in it. the problem is because $i is a zero and - if ($i % $imagesPerRow == 0) is a true value.
  3. is the html that's being produced and output to the browser what you expect? if the problem is always the second image, does the first or second image name contain any html special characters in it that could be breaking the html? what are the file names and what is the html that's being output?
  4. just listing what you want doesn't help us to help you as that doesn't tell us where you got stuck at when you tried to do this. i can only offer two recommendations - 1) for each step, define what your input(s) are or what data you need to get/produce, what processing you want to do on those inputs/data, and what result or output that step needs to produce. 2) "So each fan size would have two variables, its name and its output." your variables should be general purpose. you should not have variables with names like $capacity9, $capacity14, ... in fact, since you have a SET of data that's all going to be processed the same, just with different values, you should use an array to hold the data. storing the rows you retrieve from the fan/product table into an array would be a good first step, as this will decouple the actual database statements from the code using that data.
  5. the goal of your code should be to run as few queries as possible, in this case one will work, to get the data you want in the order that you want it. then, you would simply loop over the rows the query returned and output the data the way you want. to accomplish the ordering, remove the WHERE size=x clause and add an ORDER BY size clause to the query (assuming your table is designed correctly and is storing the size as an integer data type, if you used a character or text type, changed it to an integer data type.)
  6. the two sets of code are not comparable. the mysql code is doing a lot more work, with several more statements being evaluated in each iteration of the loop and of the database engine managing the auto-increment index field. to make a fair comparison, you need to use the same while loop construct in both, remove the static str variable, remove the p_hash assignment, remove the i+1 operation (or add these things to the FB code), and add an auto-increment id field to the FB product table. you would also need a comparable number of starting rows in each table. edit: btw - you should NEVER use the msyql PASSWORD() function in your application code.
  7. in the case of validation errors, you would want to re-populate the form fields with the existing values. in this case, you typically don't redirect, since the form is going to be re-submitted any way.
  8. when you submit to the same page that the form is on, when you have successfully processed the form data, use a header() redirect to the same page to clear the post data. you would need to use an exit; after a header() redirect, unless you have structured the logic in your code so that the remainder of the code on the page isn't executed after the header() statement. so, short-answer, you might as well ALWAYS use an exit; and simplify the logic on the page. whomever stated you are using too many exit's, may have been referring to combining common/repeated parts of your code (i.e. don't repeat yourself - DRY.) in your example code, you are repeating the header()/exit pair. you would move the header()/exit to the common execution point following the conditional logic and just leave the session assignment statement in the conditional logic.
  9. that's some pretty sad code. there's even someone that posted a bug/solution on the cuteflow site that got the reason for the error wrong, which got his solution to prevent the errors but didn't fix what the code is actually doing. the problem is that empty lines in the language file will be an empty string in the php data, producing errors when you try to access specific characters of the string or parts of an explode empty string that won't exist. also, the lines starting with # are apparently (there's no documentation) commented out lines and shouldn't be processed at all. the simplest fix, for just the incorrect logic, is to change the following line - if ( ($strLine[0] != "#") && (strlen($strLine) > 0) && (substr($strLine,0,5)!="_jotl")) to this - if(strlen($strLine) > 0 && $strLine[0] != "#") // not an empty line and not a commented out line if (substr($strLine,0,5)!="_jotl") // for lines not starting with _jotl (the else block is for lines starting with _jotl)
  10. i moved your thread to the php coding help forum section, since the problem is in getting your php code to connect to the database server. your web host has a FAQ section that explains what you must use for the database username and database name in your php code - https://my.bluehost.com/hosting/help/318 it prepends your hosting account's username and to the database username and database name you picked. also, localhost needs to be quoted in the php code, 'localhost', so that it is not treated as a defined constant first. lastly, for learning and development, you should do this on a local pc/laptop as you will waste a bunch of time constantly FTP'ing/uploading code and data to a live server (and needing to conform that the FTP/upload worked in its entirety) just to see the result of each change.
  11. your last code, using mysql_escape_string(), has a number of problems - 1) you should not mix mysql_ functions with PDO functions. this also implies that you have made a second database connection using mysql_connect(), resulting in two database connections. you should be using the PDO ->quote() method on string data. 2) mysql_escape_string() doesn't take into account the character set being used and can allow sql injection. 3) all the mysql_ functions are depreciated and should not be used in new code. 4) as stated, there's no point in using ->prepare() and ->execute() when you are putting values directly into the sql query statement. just use the ->query() method. 5) you must validate/cast/escape all three values being put into each row. what exactly are the data types of val1, val2, and val3? 6) i didn't bother to mention this before, but you should not put the id into the list of fields since it is an auto-increment column. this will eliminate the need to supply a value for that column, which will further speed up the process since the amount of data/length of the sql query statement is reduced. edit: my reference to using array functions, means to take any loop out of your code and use php's array functions to operate on each set of data. you can use array map (typically in a class) to cast/validate/escape all three pieces of data and to build the ('v1','v2','v3') string for each element in your data array. you can then simply implode those resulting values to produce the ('v1a','v2a','v3a'), ('v1b','v2b','v3b'),... portion of the query.
  12. re-read this - without the WHERE clause, you are SEEING the correct datetime values in the SELECT term, because the rows have been unconditionally matched by the query, but when the query with the where clause in it runs, the user variables don't have those values in them and the WHERE clause is false. (edit: when i tested this, there were no query errors, likely because of null values being used for the user variables. had you used alias names for the derived values and use the aliases in the where clause, you would have gotten query errors.) you either need to put the expressions using convert_tz() and date_add(repeating the convert_tz() expression here...) into the WHERE clause OR you need to change the WHERE clause into a HAVING clause. also, your JOIN users u ON username = 'Destramic' isn't complete. you need to relate the users table to the other table(s) in the query, something like JOIN users u ON u.user_id = i.user_id AND u.username='Destramic' (whatever condition ties the users to their data in the other tables.)
  13. for the logic testing if ($Car_Info_All_results) { ... } is true, you need an else { } branch using mysql_error() in it to get php to tell you why it thinks the query is failing.
  14. 1) the maximum length of each line in the message body is 70 characters. you need to add new-lines \n to break up and limit the length of each line in the message body. 2) the separator between headers should be \r\n, unless you have determined for a fact that your sending mail server requires just \n 3) you should only use a function like mysqli_real_escape_string on the values being put into mysql query statements. by using it on the email value, then using that in the mail function, any email addresses that contained any sql special characters will be broken and won't work. 4) your code needs to test the value returned by the mail() function. a false value would indicate an error occurred that would require debugging to find out why the mail server didn't accept the email. a true value would indicate that the mail server at least accepted the email (but may not actually send it, but at least you will know the email made it to the sending mail server.)
  15. a) don't bother with unix timestamps. you can compare datetime values directly. b) are you getting any query errors? off of the top of my head, the where clause cannot use derived values from the select term, because the where clause determines what rows are selected and you cannot produce the values in the select term until you have selected the rows.
  16. how do you know the display is 30 minutes behind, since you are not displaying the minutes?
  17. the first parameter to the watermarkImage() function is the watermark, the second parameter is the image to watermark.
  18. php has a function called checkdate(), which means your function definition isn't being made and your code is likely throwing php errors when you call php's built-in checkdate() function with those parameters. you need to ALWAYS have php's error_reporting set to E_ALL and have display_errors set to ON, when developing code, to get php to help you.
  19. that would result in the fastest method, except, by putting the data values directly into the sql query statement, there's no point in using a prepared query followed by calling the ->execute() method (which takes two 'round trip' communications with the database server.) you might as well just run the query using the ->query() method and save some time communicating with the database server. also, by putting the data values directly into the sql query statement, you must now escape string data and validate/cast numerical data to prevent sql injection and prevent query errors when string data contains sql special characters or numerical data isn't what you expect it to be. edit: also since your starting data is already in an array, it would typically be faster to use php array functions (array_map() to build the sql syntax for each row and implode() to combine all rows) to build the multi-value portion of the query. you can end up with code that contains no actual loop statement, with no need to trim any commas from the end.
  20. you need to determine what your code is actually doing to find where the problem is at. to start with, do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would help you by reporting and displaying all the errors it detects? the following line - $im = imagecreatefromjpeg('$filePath'); should be producing php error(s), because php variables are not replaced with their content when they are between single-quotes. you may also need to turn OFF any output_buffering setting that might be ON in your php.ini since that can hide php error messages. next, your upload code is looping over multiple uploaded files. do you want to water-mark all of them or just the last one (which is what your current code is trying to do) and what do you want to do with the final water-marked image(s)? the current code is outputting it (the last image) back to the browser immediately after processing the uploaded file. do you want to save the water-marked image as a file so that you don't need to run the gd functions (which take a lot of memory and processing time) every time you display the image? also, if your intent is to upload multiple images at one time (what the first part of your code supports), you won't be able to output the images back to the browser all at once as you can only output one image at a time.
  21. if this question is in any way related to your last thread, where you wanted to update the total price displayed when the quantity is changed, you seem to have hard-code/written-out the html for each product, rather than to use php to dynamically produce your page(s)? you need to use php to manage the contents of a cart (item id's and quantities) and to dynamically produce the paypal form from the contents of the cart, rather than the other way around of trying to manipulate a static paypal form's html/values. this will let you freely produce the code needed to add/delete items or change the quantities.
  22. if you are currently still getting empty values for the four columns in the database table, it's because the parameter usage for the mysql_real_escape_string() function is different form the mysqli_real_escape_string() function. the $link would be the second parameter, not the first. to muddy the water even more, the mysql_ (no i) functions are depreciated and will be removed in an upcoming php release. you should be learning the mysqli_ or PDO database library functions, which are not obsolete. if you had php's error_reporting set to E_ALL and display_errors set to ON, php would help you by reporting and displaying all the errors it detects. all the mismatched mysql/mysqli and $link parameter usage would be producing php errors. in fact, if you are using a high enough php version, the mysql_connect() statement would be giving you a depreciated error message.
  23. your current code is mixing mysql_ (no i) and mysqli_ (with an i) functions. you cannot do that (if you want it to work.) if your current code is inserting all empty values, it is because of this mixing of different functions (the mysqli functions are returning null values since there is no mysqli connection in place.) sort the current problem out, by using all the same type of database functions and see if it works with the other changes in place.)
  24. you likely have a spelling error in one of the column names in the mysql query statement.
  25. you would want to build your links with a named get parameter, i.e. ?p=some id, like what you are doing in the non-database version. the value would then be referenced using $_GET['p'] in the php code.
×
×
  • 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.