Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,449
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. it would take having your actual and complete code, less any database credentials, to help you. there is no magic involved in programming. if that's your complete and actual form and you only have the one opening <form > tag on that page, it will submit to the page in the action=' ... ' attribute. the only way it would not is if you had another opening <form > tag earlier on that page and the form you showed us is inside of the first form or the code is actually going to the nm_login.php page and being redirected from that page to the index.php page. any chance you are doing url rewriting in your .htaccess file?
  2. this is from line 14 of your pseudo code - the form is submitting to the nm_login.php page. when the code on that page is successful, it is intentionally redirecting somewhere besides the nm_login.php page. the code is doing what it was written to do.
  3. your form processing code is redirecting, likely to index.php, upon a successful login. i would say it is probably doing what it was written to do.
  4. the <script ... tag, which loads the external javascript, is only needed once (usually in the <head></head> of the HTML document.) the correct syntax should be - <script type='text/javascript' src='http://www.thetimezoneconverter.com/js/ttzc.js'></script> you can then put any number of instances of the widget on your page - <script>new TTZC.Widget({ version:'inline', t:'4:45 PM',tz:'London'}).display();</script> the point of php (or any other server side language) is to dynamically produce and output the markup/content that makes up a web page. wherever your source time data is stored, you would retrieve it, loop over it, and echo the above line of markup, replacing the static time in the t:'4:47 PM' parameter with each successive value from your data.
  5. your first step will be to use an array name for the form field - name='event[x]' (where the x is the event number 1,2,3...) this will let you use php's array functions to operate on the data. the submitted values will be an array in $_POST['event']. to filter out the empty values, you would use array_filter(). count() would then given you a count of the remaining elements.
  6. sorry to jump in here, but your approach is backwards. you are creating $maxclothrows empty entries at one point, apparently putting some values in an another point, and wanting to remove the remaining empty entires after the point where you have put in the actual data. the correct approach would be to initialize/create just the entries you need at the point where the actual values are being retrieved at. why can you not do this directly? and if you did have a need to first create $maxclothrows empty entries, the place in the code where you would test for and remove the remaining empty ones would be right after the point where you have put in the actual data. so, what is your code that is putting in the actual data values?
  7. notepad++ also has a convert ASCII=>HEX plugin.
  8. you need to use an editor that displays the hexadecimal values of the characters so that you can see what they actually are.
  9. his function name was probably because Halloween is coming - http://horror-movies.wikia.com/wiki/Chucky
  10. define: this query is failing? what result is it producing and what is wrong with that result?
  11. your distance(){} function is a php function. it only exists in the context of the php code. you are trying to use it in your sql query statement, which with respect to the php code is just a string you are building. it's only an sql query statement once it has been sent to the database server. to do what you are trying, calculate the distance in the query, so that it will be the fastest and most efficient solution, you would need to define and store a procedure in your database that performs the same calculation using sql statements.
  12. it works because database.php is including the template file - include 'jokes.html.php'; that's the way it is supposed to work. you are not supposed to browse directly to jokes.html.php. it's not a complete web page. it is only the template file that uses the $jokes array. it is only supposed to be included into the file where the $jokes array is being produced.
  13. input-processing-output this is the sequence/flow that all programming should follow. you can apply this methodology to just one line of code, a block of related code, or the entire program. whatever context you are looking at, it will have some definable input(s), processing, and output(s). for any step in your logic, you need to condition, filter, and validate the relevant input(s) values (the input may be just the fact that your code was requested/executed and is not an actual value.) then, if the input(s) values are valid and error free, you can use those input values and move onto the processing you need for any step in your logic. finally, produce any output the step in your logic is responsible for. this can be output that is displayed or data that is used in the following steps in your program. by doing this last, for any step in your logic, you insure that any changes due to the inputs will be present in the output. now for your current problem. the main functional body of your php code expects, as an input to it, a Phrase Number to access the correct line in the 'words.txt' file. you would also like to be able to increment the Phrase Number when $action == "NEXT PHRASE". the Phrase Number should also initially start at zero and it should be limited to the line count ( minus 1 ) of the 'words.txt' file. an example of how you might do this (this code is using the $_SESSION[..] variable directly, rather than coping to/from another php variable, and renames this session variable to indicate what the value in it means, it's the current phrase the code is using, not the next one) - if(!isset($_SESSION['PhraseNumber'])){ $_SESSION['PhraseNumber'] = 0; // initialize to zero (the first line in the file) } $action = $_POST['action']; // this input needs to be conditioned/filtered/validated as appropriate if($action == "NEXT PHRASE"){ $_SESSION['PhraseNumber']++; // increment to the next phrase in the file $action = ''; // start at the first step in the main logic below } $theText = textLoader('words.txt'); // you can put logic here to test count($theText) and $_SESSION['PhraseNumber'] to detect when all phrases have been used. the $action variable is being cleared (in real life you would redirect back to the same page to clear any $_POST data) so that the rest of your code starts at the - if (!$action) { step, which starts over with whatever phrase happens to be the current one.
  14. again, there is nothing technically wrong with the code, provided the query is working and the code, especially the file name in the include statement, is the actual code, what is the exact error message you got? you also never confirmed that you actually have checked in your program that the $jokes array contains the expected data. in programming you cannot ASSUME anything when you don't get the expected results, you must actually check what the data is and confirm it, in multiple places, as needed, to pin down where it is working and at what point it is not working.
  15. there's nothing technically wrong with the snippets of code you posted, provided they are in the same program scope, the loop is actually fetching the data into the $jokes array, and your code is not clearing the $jokes array between where it is being loaded and where it is being used. is the code you posted your actual code and have you confirmed that $jokes actually contains the expected result from the while(){} loop?
  16. all you have stated is your code isn't working in this version. what exactly is it doing that leads you to believe it isn't working and at what point in it when you were debugging it is it doing what you expect and at what point it is not? you have got to narrow down the problem to just one relevant block of code, not the whole thing, since we don't have the ability to run your whole code with your data... however, writing code like the following has no point other than to take up your time typing and debugging extra syntax - there's no php produced values in that block and you are immediately echoing it after you create it. just put a closing php tag before the block of html markup and then an opening php tag after it. and if you did have any php produced values to put into that, you would just make it one php statement and either directly echo it or assign the whole thing to one php variable.
  17. this is from the 5.5.0 change log - are you setting the error_reporting/display_errors before you are making the connection?
  18. as to your Notice: Array to string conversion ... error message, the reason it went-a-way is because you added an exit(); statement to stop your code from running. the error is because $_FILES['Poster'] is an array and you are trying to put it into your query statement. you are going to need to research more about what happens when php receives an uploaded file before you will be able to do this in your code. here's the php.net section on processing uploaded files (reading the whole section would be useful) - http://us1.php.net/manual/en/features.file-upload.php
  19. you need to slow down and work on one thing at a time. your last posted code isn't actually checking if your form was submitted at all and contains an exit() statement that is killing your code at that point, which is probably why you aren't getting any output. 1) to start with, you need a conditional statement around all your form processing code so that it only executes when a form has been submitted. because you are trying to upload a file, the $_POST and $_FILES arrays can be empty due to one particular upload size error and you need to test some other value besides a $_POST or $_FILES element to detect that a form was submitted. the best way is to check if($_SERVER['REQUEST_METHOD'] == 'POST'){ all your form processing code goes here... } 2) next, for ALL of your form fields, you must validate that they contain expected values before you use any of the data. for the upload file field you will also need to verify that the upload worked before you can test or use any of the uploaded file information. you should report back to the visitor exactly what is wrong with the data they submitted for each form field. 3) your insert query statement should be of the form that list the columns. this will prevent a bunch of problems, will let you leave out the id field value, and let anyone looking at your code know what your table/query is actually doing - INSERT INTO table_name (columns,...) VALUES (values,...) 4) you either need to escape your string data before putting it into the query or use a prepared query, to prevent query errors and sql injection. 5) lastly, the mysql_ database library is depreciated starting in php5.5 and all new code, or anyone learning how to do this, should be using either the mysqli or PDO database libraries. since uploading files seems to be a popular subject lately, see the following thread for info about uploaded files - http://forums.phpfreaks.com/topic/282596-how-to-handle-file-from-multiple-upload/?do=findComment&comment=1452535
  20. that's because ASP, in a macro sort of way, hides a lot of the underlying details and removes the choices from the programmer. you do things the ASP way, because it provides the way to do it and there's only that one way. php is a more general programming language, similar to C. you, the programmer, deal with all the details, decisions, and choices yourself. i.e. for a time value - what format is it being input as; is your code validating/processing/formatting it for use internally; is your database column the correct DATA TYPE to store it efficiently and write efficient queries to use the value; does your application have a need to display it in a different format than what it is stored internally in the database... php is definitely a detail orientated, the programmer is in the driver seat, language.
  21. you mean like the same errors you got with the code from AbraCadaver's post?
  22. best as i can tell, that's the only problem/question in your post, everything else being a statement of what you are doing. you would keep track of money, the same as any bank/credit account, with a separate transaction record added for each credit (+amount) and debit (-amount). you can calculate the total at any time by simply summing the amounts for any account number. each record would include all the relevant information about it, such as when it was made (date/time), the amount (+/-), who caused the transaction (the owner, shop staff, ...), description (what it was used for/due to).
  23. why did you change the code in the first place? other than it using php5.4 syntax, there's nothing wrong with that line.
  24. in general, having the complied code of a database engine searching for values in data is going to be faster than using interpreted php script for the same task.
  25. this is similar to what Ch0cu3r posted above. you are missing the point of what functions/methods do and how, if at all, they interact. i also think you think you must use $this->variable_name for every variable. that's not true. you only use that for class properties that you want to share between methods. the only class properties you should have are the ones that your class needs to share between methods or that need to be public for external access. don't use class properties for every variable you use inside a method. you can use a regular php variable, such as $row, inside of method/function and it will be local only to the method/function.
×
×
  • 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.