Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,354
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. no. and in the cases where you do specify a url (that resolves to the ip of the database server), it would be the url of the database server, not the url of a web server. typical urls would be something like mysql1.example.com. if you are having a problem on your hosting connecting to the correct database server for you account, you can find the correct hostname to use from your web host and it is also typically displayed on the page (phpmyadmin) where you created your databases/database tables.
  2. you shouldn't try to use time for this. multiple pieces of data can be inserted in a single second and during the same second that you are trying to retrieve data.. you can have data with the exact same time stamp with rows that were inserted before you run a query to retrieve data, that the query will find, and with rows that were inserted after the retrieval query was ran that you won't find. this is a bug that has plagued things like Vbulletin's forum software for a time (no pun intended) now. also, for the code Alex_ posted above, that's trying to compare the client's time with what's been stored on the server, this isn't reliable since it assumes that the clients time zone is related to (all) the data stored on the server and that the client's exact time (seconds) is synchronized precisely with whatever time source was used when the data was stored. instead, take a lesson from the SMF forum software, where the id (auto-increment database field) of the last retrieved/displayed information is carried in the url's and is used to find any rows inserted since that information was retrieved and displayed (in the case of SMF software, they are doing this to display 'new posts where made since you viewed this thread' and they are also using the thread id to qualify the results to the current thread being viewed in the browser.) this seems similar to what the op stated in the first post, but you must query for rows that have an id greater than the 'last displayed id'. you cannot check for a quantity of rows matching the id value since id's may not be contiguous if rows have been deleted.
  3. if you retrieve the current highest value, increment it, and try to use it, yes there exists the possibility of a race condition causing two ore more concurrent instances of your script to use the same value. you would need to lock the table to insure each value only gets used once. instead, you would use an auto-increment column in the database table, since the database locks the table for you during the INSERT query and will automatically prevent any duplicates from being used. If you need to get the auto-increment value that was just used in an INSERT (or update) query, you can retrieve it via a query or most database libraries have a dedicated function/property to retrieve the value.
  4. your form does not have a form element with the name SignUpButton, so your php code if (isset($_POST['SignUpButton'])) { will never be true. it is recommend that you detect a form field that will always be present in the submitted form data (submit buttons cannot be guaranteed to be present, if you use the enter-key to submit the form (IE and Opera browsers) or use javascript to submit the form.) either test for a non-disabled text/password/textarea field or add a hidden field.
  5. you had a significant number of problems in the posted code, including not executing the UPDATE query at all. it would take seeing your current code in order to help you with it.
  6. the problem is most likely in that bit of coding. in programming languages, and specifically php, the ^ is not a exponential operator, it is in fact a bit wise exclusive or operator. you would need to consult the php documentation to find the proper exponential operator.
  7. your goal should be to NOT repeat code, but to reuse the same, identical code. also, by creating a series of numbered variables, you must now type out or copy/paste/overtype the code for each additional set of data. you should instead use arrays for sets of same meaning data that will be processed in the same way. the looping that hansford showed is for an array of uploaded files. the php.net upload handling documentation shows how to do this. see example #3 at this link - http://php.net/manual/en/features.file-upload.post-method.php as to the validation in the php code, since this is user submitted data, each possible error should be checked separately, for each file, and you should give the visitor as much information as possible about what file and what error occurred with that file. any validation error messages you produce should be added as elements to an array, so that you build a set of all the validation errors. you can then simply loop over this array of error messages at the point where you want to display them. short-answer, use arrays when dealing with sets of data, i.e. sets of input uploaded files, sets of validation error messages, ...
  8. a function/method will generally return data, that you can then assign to a variable or directly loop over. it may however make the data available as a class property. in either case, it would take looking at the documentation and/or code for the PesquisarPorDatas() method in order to find out what where, what, and what format the data is in.
  9. you don't. the class file is only the class definition. it gets included by your main code so that you can create an instance of the class to use in your main code, not the other way around.
  10. the "Mark Solved" button is in the lower right-hand corner of each post in the thread.
  11. your code is not checking if an upload form was submitted and that the upload worked before trying to use the uploaded file information, which has resulted in you trying a bunch of code (all the isset() business) that isn't actually solving anything. because uploading files can cause the $_FILES and $_POST arrays to be empty, when you exceed the post_max_size setting, to test if a form was even submitted, you must test if $_SERVER['REQUEST_METHOD'] == "POST" (there are other ways of checking, but this way tells you that a correct method of form was used.) next, to detect if the upload worked without any errors, you must test if your expected $_FILES['video'] element exists (is set) and that the ['error'] element is a zero value (no errors.) if all the tests to this point are true, you know that the upload worked and that the ['name'], ['type'], ['size'], and ['tmp_name'] have values and can be used. In all other cases, these elements won't all have values and cannot be used. also, for each of these tests that have failed, you can determine what caused the upload to fail and tell the visitor about things he has control over, such as the size of the uploaded file(s), that he can alter and upload again. so, at this point, your form processing code, at a minimum, would look like - // check for a post method form if($_SERVER['REQUEST_METHOD'] == 'POST'){ // is the expected form field set if(isset($_FILES['video'])){ // a properly named field/variable exists, check for upload errors if($_FILES['video']['error'] == UPLOAD_ERR_OK){ // the upload worked, you can use the uploaded file information here echo "the upload worked, you can reference the ['name'], ['type'], ['size'], and ['tmp_name'] information at this point"; // all your form processing logic needs to go here... } else { // there was a detectable upload error, handle that condition here... // the php.net upload handling documentation lists all the error values and what they mean } } else { // the expected $_FILES['video'] element doesn't exist. if there are no coding errors, // this typically means the total size of the post data exceeded the post_max_size setting. // you can test the $_SERVER['CONTENT_LENGTH'] value to confirm if this is the case. } }
  12. your code apparently has a circular include/require (i'm not sure why php isn't failing with a redeclare error for the class definition.) your class definition file is including your register.php script, which is including your config.php file, which is including the class definition again. the only thing that should be in the class definition file is the class definition. the include "register.php"; line that you added, and in fact the display_errors line that the author of that software already had in that file, should not be in that file. your main file, which is register.php, is where you include/require things that it needs (and in the case of class files, you should eventually advance to the point of using an autoloader.)
  13. just put your form and form processing on the same page. in this case the only redirecting you will need is one to the exact same url/page after you have processed the form data, to cause a get request for that same url/page to cause the browser to not try and submit the same post data again.
  14. to echo a variable, all you need is echo $sql; this is pretty basic stuff and would be covered in any beginning php book, tutorial, or class. have you read a php book or tutorial, or taken a class to learn the basics before trying to write your own code that does something? of the lines you posted, line #2 and line #3 would have displayed the content of the $sql variable (line #3 would have also displayed the extra dots and spaces within the double-quoted string. lines #1 and #4 would have literally displayed what is within the single-quotes. if nothing was displayed when you tried to echo the $sql variable, either you either have a php syntax error and the whole page of code isn't running or you put the echo statement at the incorrect point in your code or the code where you put it at isn't being executed. if you want anyone here to try and determine why the echo statement you put into your code didn't do what was expected, you would need to post your current code that contains that echo statement to give us something upon which to help you.
  15. i have a basic why question. why are you trying to have more than one session that you want to share data between? someone in a previous thread asked why you are doing this and your reply was a statement of what you were trying to make work, not why you are doing this. knowing your overall purpose, would perhaps help someone to give a more direct solution, since what you are trying to make work is uncommon.
  16. everyone that is reading this was new to php at one point in time. does that mean you are not going to echo the $sql variable holding the query statement, look at it to see if it even has values in it, and then look at your database table and make sure you have a row with those exact same values? you are the only person here who has access to your server and can do these things to pin down where the problem is at.
  17. you need to actually debug and find out why your script is not matching the username/password. just randomly throwing a bunch of code against the wall to see what sticks isn't programming and will take forever to get something that works. you need to echo out the $sql query statement to see what exactly it is and then look in your database table, using your favorite database management tool, such as phpmyadmin, and see if the username and hashed password values, in the $sql variable that you echoed, exactly match the values in a row in your database table.
  18. i'm not intentionally trying to give you a hard time, i promise. but the posted code is a copy/paste fail. you have code that's not accomplishing anything useful (a select query on the logs table), duplicate code (checking the session variable and running a select query on the users table, two different times), and code that's out of date and not secure (the magic quotes/addslashes business). rather than to follow along with the bad code that Dreamweaver produces, you need to actually learn to program and write your own code that does what you want it to do. you need to start with having a stated goal. do you want to log ALL log-in attempts, successful ones and incorrect ones, or just the successful ones? what data do you want to store (what data is available)? some suggestions - ip address, username, datetime, and a success/fail status. next, you would form and run the INSERT query at the correct point in your program logic. the code you have posted doesn't actually have any log-in logic in it to be able to help you. in fact, the posted code isn't using any form variables, so it's unlikely that this is your log-in authentication code at all. if you are logging just the successful log-in attempts, you would form and run the INSERT query inside the successful login code. if you are logging both successful and failed log-in attempts, you would just set up the success/fail status value in the code and then form and run the INSERT query after the point where you have determined the correct/failed log-in state.
  19. this is wrong advice. the $_POST array is always set by php. all the super-global arrays are set, even if they are empty. to detect if a post method form has been submitted, you either need to test if a specific, non-optional/non-disabled, field in the form is set, which your code is doing with the if(isset($_POST['submit'])) {, provided you always click on the submit button to submit the form, or you can test if $_SERVER['REQUEST_METHOD'] == 'POST' if all you want to detect is if any post method form was submitted. once you have detected that a form has been submitted, you don't need to individually test if text/password/textarea fields are set, they will be if you don't have any coding errors in your form. and in fact, if you do have coding errors, you wouldn't want to use isset() to qualify the references to those type of fields as it would hide the fact that your form doesn't have fields by those expected names.
  20. there is NO default sorting on database tables. the ordering in a result set is the order that the rows have in the table. this is typically the order in which they were inserted, but as you delete, insert, update, index, backup/restore, ... the data, the order of the rows can get changed. if you want data retrieved in a specific known order, you must use an ORDER BY term in your query (note: a GROUP BY also performs an ORDER BY since the rows must be sorted before they can be grouped, but you can apply your own ORDER BY after the GROUP BY to order the resulting groups the way you want them to be retrieved.)
  21. if you changed the memory limit and you are still getting memory errors, with the total memory mentioned in the error changing to match the new limit you set, your code has a logic error (usually a loop/array problem of some kind) and it will consume all available memory, no matter how much you make available. you must find what is causing the problem in order to fix it. if you cannot determine what is causing the problem youself, you will need to post all the relevant code, less any database credentials.
  22. since this code seemed familiar, i went looking through your previous threads, and found that i had helped with bits of it before. this code is responsible for retrieving and displaying the content of the shopping basket. you would do what maxxd has suggested above, and join the postage table with the existing basket/products join query to get the Post_Cost for each item in the basket. while you are looping over the result of that ONE query, you would detect and save the highest Post_Cost value. you could also, in the loop, store the Post_Cost values into an array, and just use php's max() function on that array to get the highest Post_Cost value. you, or who originally wrote this, easily have two times more php code that what is needed, resulting in it taking 5-10 times longer to find and fix any problems or just make changes to what the code is doing (and reducing the chance of someone helping with it as who wants to read through a wall of verbose and repetitive code that can be replaced with a couple of statements.) taking the time to reorganize and reduce the code, will actually save time overall, and make it easier to switch from using the depreciated mysql_ functions, since there will be less overall calls to the mysql_ functions and all the database logic that stores, updates, and retrieves the data for the page will (should) be grouped near the start of the code on the page. the html on the page will (should) be grouped at the end, with only simple php echo, conditional, and loop statements in it. edit: assuming you use a single joined query and that you have a Post_Cost associated with each item in the basket, the following pseudo logic is all you would need to find the highest Post_Cost value - $Post_cost = array(); while(...){ // your existing while loop $Post_cost[] = $row['Post_Cost']; // save each post cost in the array } // end of your existing while loop $highest_post_cost = max($Post_cost); // find the maximum value in the array and if you want the $postagerate = 15.00; amount to be the minimum postage value, just put that value into the $Post_cost array before the start of the while(){} loop.
  23. string data values that are put into an sql query statement must be escaped, using your database library's string escape function (or use prepared queries) and numerical data values that are put into an sql query statement must be filtered/validated/cast as the appropriate numerical data type (or use prepared queries) in order to prevent sql errors and to prevent sql injection. btw - if you have that many fields being put into a query, you should be dynamically building the query using code, rather than typing out the whole query statement. this would also make it easier for your code to escape/filter/validate/cast values (or use prepared queries) since you would be looping over the fields/data values, rather than have each one hard-coded and individually written out.
  24. in whatever sql query is being run right before the code you posted, just use MAX(Post_Cost) in the query to get the highest post cost value for the set of matching rows.
  25. you would just make your series of numbered variables into an array with an index being the sensor number - $array[1] = array (7,8,9,10,11,12); $array[4] = array (13,14,15,16,17,18); $array[6] = array (1,2,3,4,5,6); your echo statement, inside the looping code, would simply be - echo $array[$i][$x]; or you could simply loop over the data directly using foreach($array as $sub_array){...}
×
×
  • 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.