-
Posts
5,450 -
Joined
-
Days Won
175
Everything posted by mac_gyver
-
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)
-
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.
-
PDO multirow insert with a multidimensional array
mac_gyver replied to Bldyhll's topic in PHP Coding Help
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. -
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.)
-
Distinct AND Group By have LONG delay, return nothing.
mac_gyver replied to njdubois's topic in PHP Coding Help
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. -
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.)
-
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.
-
how do you know the display is 30 minutes behind, since you are not displaying the minutes?
-
the first parameter to the watermarkImage() function is the watermark, the second parameter is the image to watermark.
-
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.
-
PDO multirow insert with a multidimensional array
mac_gyver replied to Bldyhll's topic in PHP Coding Help
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. -
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.
-
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.
- 7 replies
-
- paypal
- linking input form
-
(and 3 more)
Tagged with:
-
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.
-
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.)
-
PDO multirow insert with a multidimensional array
mac_gyver replied to Bldyhll's topic in PHP Coding Help
the quickest possible way is to use a multi-value insert query. running a prepared query inside of a loop only provides minimal speed improvement (a fraction of second improvement for thousands of rows that take multiple seconds to insert) over running a non-prepared query inside a loop since most of the time is taken up by the handshaking and transmission of information between php and the database server to send each query/set of data for the prepared query. i did a benchmark some time-ago and the only significant way to speed up inserting/updating large amounts of data is to use the multi-value form of an insert query. for your current code, the bindParam() statements need to be outside of and before the while() loop. the variable you supply as the second parameter to the bindParam() must be a reference to where the actual data is at when the ->execute() method is called. the clearest way would be to use three distinct variables in the bindParam() statements, i.e. $a, $b, $c, then assign $a = $fullarray[$j][0]; $b = $fullarray[$j][1] ; $c=.$fullarray[$j][2] ; inside the while(){} loop code. next, $stmt->execute(); needs to be inside the while(){} loop code. lastly, you should also put the count($fullarray) statement outside of and before the while() loop so that it is not re-evaluated each time the while() condition is evaluated and you will probably want to initialize $j to zero before the start of the while() loop. -
whatever method you are using to view the end result is likely where the problem is at. i'm going to guess you are trying to output the content of the Comments database column using a value="..." attribute. that's not how <textarea></textarea>'s work. you need to output the content of the database column between the <textarea>output goes here</textarea> tags. for the escape string function you use, you need to do that right before you put the data into your mysql query statement (or use prepared queries) and you need to use the escape string function from the same set of database functions you are using in your code to run the query.
-
op started a new thread for this, thread locked.
-
What's wrong with my query? Works on sqlyog, but nowhere else.
mac_gyver replied to sKunKbad's topic in MySQL Help
the only thing that comes to mind would be running a query to initialize the user variable(s) to zero so that they are not nulls at the start of the query. perhaps sqlyog automatically does this for you. -
every occurrence of ?page=_______ in the links would need to be changed.
-
the easiest way of building the query-string part of links, with any existing values (the search term), and any specific values (the page number) is to use http_build_query(). see the example code in the following reply - http://forums.phpfreaks.com/topic/288934-pagination-question-using-array-to-get-data/?hl=%2Bhttp_build_query&do=findComment&comment=1481655
-
the WHERE clause you are forming needs to be in both the query that gets a count of matching rows and in the query that retrieves the data. so, it is best if you form the WHERE clause in a php variable, then just put that variable in both queries. next, the search term determines what the page is gong to display and should use method='get'. a second reason for using get is to make it easier to build the pagination links, since they must have both the pagination and search term in them for this to work. i'm pretty sure i have posted an example somewhere. i will either find a link or re-post something.
-
your client-side code is likely skipping or overwriting the first dynamic/cloned form field key/index. you can examine the submitted data by adding the following to your php code - echo '<pre>',print_r($_POST,true),'</pre>':