-
Posts
5,451 -
Joined
-
Days Won
175
Everything posted by mac_gyver
-
if the information you posted above is a control panel that's modifying the master php.ini, the settings won't take affect until you stop/start the web server. and you still must check what settings php is actually using by using a phpinfo() statement, as things like syntax errors in the php.ini and the wrong php.ini being used, will cause default php settings to be used, not the ones you have set.
-
the simple html dom object is huge, even for a small amount of html, like the str_get_html('<html><body>Hello!</body></html>') example in the documentation (don't know if this is a bug or intentional.) edit: the str_get_html example from the documentation uses 11K bytes of memory. creating the html dom object for the thread on this forum that we are looking at, for a non-logged in visitor, uses 2M+ (2,416,456) bytes of memory. you need to extract out the data you need inside of the loop and only store the data, not the simple html dom object itself.
-
you need logic in your code to detect that the form was submitted and only use the submitted data when it has.
-
this and your last 3 threads have been posted in the wrong forum section, requiring someone on the staff to move them. the Php Regex form section is for help with regular expressions, i.e. pattern matching. it is not for other types of programming questions.
-
your program likely has a logic error in it, so that it will consume all available memory, no matter how much you make available. 512M bytes of memory is a substantial amount of memory. you would need to debug what the code is doing in order to find the problem. if you want us to help, you would need to post the code needed to reproduce the problem, less any sort of private values it may contain.
-
Introduce script/form from another page
mac_gyver replied to MartynLearnsPHP's topic in Javascript Help
^^^ because he's dealing with picking and assigning discrete things, the number of seats at each table (which could vary, but probably should have an input method that sets a default value to use that matches the majority of the tables at any event) and individual guests assigned to the seats at any table. -
i need help woth my form validation [;s
mac_gyver replied to Michael_Baxter's topic in PHP Coding Help
@rwhite35, the two lines setting error_reporting/display_errors are two different settings and both are necessary to insure that all run-time errors are reported and that those reported errors are displayed and the lines initializing the variables are technically correct, but unnecessary and even error prone, as it requires you to type and then maintain those statements to match the actual form. the code suggested/at the linked to post, using arrays is the correct and clean way of dealing with sets of data. -
the information that blacknight posted has nothing to do with the problem. i suggest you read what tryingtolearn posted.
-
have you confirmed that the session settings you have set are actually in effect, using a phpinfo(); statement in a .php script file? are you on shared web hosting and are using the common/default shared session.save_path setting? if so, your session data files are in the common /tmp location and the shortest session.gc_maxlifetime setting of all the scripts running on the shared web server is what controls which files are deleted when session garbage collection runs. if this is the case, you need to set your own session.save_path setting so that your session data files are only affected by your session settings. also, you need an exit; statement after your header(...); redirect statement to prevent the remainder of the code on your page from running. as it is, your 'protected' code still runs every time you page gets requested when you are not logged in, which can cause untended side affects, such as values changing/being cleared, and anyone can still access your protected pages by simply ignoring the header redirect.
-
i need help woth my form validation [;s
mac_gyver replied to Michael_Baxter's topic in PHP Coding Help
to solve most of your problems, of getting your code to display any validation errors and to not run your database code when there are errors, you need an easy way of remembering what errors were detected that you can also easily test to see if there are errors. the best way of doing this is to use an array variable. as each error is detected, you would store the error message as an element in the array. to test at any point if there are errors, you would check if the array is empty or not. to display all the errors, you would loop over the non-empty array. also, by using an array to hold the errors, you won't need to initialize all the separate hard-coded error variables. in fact, there was a recent similar thread, where the same suggestions were made - http://forums.phpfreaks.com/topic/294898-required-fields/?do=findComment&comment=1506734 -
Stacking function within ternary initial expression
mac_gyver replied to rwhite35's topic in PHP Coding Help
this kind of micro optimization is counter productive. the amount of memory the bytecode for the unset statement and the variable reference operand it contains, is the same or more than the amount of memory you would be freeing up. on top of that, you have wasted the processing time needed to parse, tokenize, and then run the extra code. -
Introduce script/form from another page
mac_gyver replied to MartynLearnsPHP's topic in Javascript Help
i'll address your first two pieces of code first, as this may suggest ways of solving your current problem. even if you are dynamically producing the repeated sections of javascript/html, that only differ in the values/id's they operate on, this is not how to do this. you should use jquery class, element, and $(this) selector, so that one general purpose instance of the jquery/jquery ui code can operate on the form corresponding to any dialog reveal button. same for the form validation logic upon submission. see the following example - $(document).ready(function(){ jQuery(function($) { $('.mybutton').each(function() { $.data(this, 'dialog', $(this).next('.mydialog').dialog({ autoOpen: false }) ); }).click(function() { $.data(this, 'dialog').dialog('open'); return false; }); }); //validating Form Fields..... $(".submit").click(function(e){ var form = $(this).closest("form"); // the form that was submitted var nam=form.find("input[name='name']").val(); var seat=form.find("select[name='seat']").val(); if( seat ==='' || nam ==='') { alert("Please complete both fields"); e.preventDefault(); } else { alert("Table formatted successfully"); } }); }); <button class='mybutton'>Table 1</button> <div class="mydialog" title="Table Format"> <form action="" method="post"> <label>Table Name:</label><br/> <input type="text" name="name"><br/> <label>Number of Seats:</label><br/> <select name='seat'> <option value=''>---Please Select---</option> <option value='0'>0</option> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> <option value='9'>9</option> <option value='10'>10</option> <option value='11'>11</option> <option value='12'>12</option> <option value='13'>13</option> <option value='14'>14</option> <option value='15'>15</option> <option value='16'>16</option> <option value='17'>17</option> <option value='18'>18</option> <option value='19'>19</option> <option value='20'>20</option> <option value='21'>21</option> <option value='22'>22</option> <option value='23'>23</option> <option value='24'>24</option> </select><br/><br> <input type="hidden" name="id" value="<?php echo $tableid; ?>" > <input type="hidden" name="token" value="<?php if(isset($token)) {echo $token;} else {echo $token = Token::generate(); } ?>" > <input type="submit" class='submit' value="Submit" /> </form> </div> i also hope that in the sample code you posted, that you are dynamically generating that via php code inside of a loop, as apposed to hand coding all of that n number of times? how does this apply to your current problem and the last code you posted? don't repeat code (DRY - Don't Repeat Yourself) when the only thing that's different between the instances of the same logic is the input data it operates on. your php code is a wall of repeated code, eight times at least, and i even suspect that you have, or plan to, repeat this in differently named/numbered files for each possible table? you should instead have one instance of the code (in a function or a class as needed) that you can reuse for any possible input values to retrieve and produce the output that you want. this is the whole point of having variables in programming languages, so that one instance of code can operate on dynamic inputs, as apposed to having static code that can only produce a fixed result. lastly, your php code shows that you have a bad database design, that has each table row laid out like a spreadsheet, with multiple different types of data, and multiple numbered fields within each type, within one row. this is partly the cause of your verbose code. you should instead have the data normalized, with each row holding only one piece of data of the type of the database table it's in. your queries to find things (and insert/update) will be much simpler and your php code will be much simpler too. if you find that you are altering or dynamically creating columns in tables as the number of data items change, it is a sign that your table(s) are not designed correctly. -
your code has a typo error on line 57 and throws the following php syntax error - Parse error: syntax error, unexpected 'dbactive' (T_STRING), expecting '(' in your_file.php on line 57 look at line 57 in your code and try to determine what's missing on that line (the error message actually says.) you need to have php's error_reporting set to E_ALL and display_errors set to ON in your php.ini on your development system to get php to help you, by reporting all the errors it detects. parse errors like this one prevent your code from ever running, so putting any sort of error_reporting/display_errors settings in your code won't do anything in this case. also, by having these settings in your php.ini, you don't ever need to remember to put them into code for testing and remove them when you put code onto a live server. fixing the typo error on line 57 will let your code run and display the form.
-
yes, that's okay. using one database connection through out the code on the page.
-
your code is technically correct, but there are some issues with some things - 1) since the column names can be anything, you should enclose them with identifier quote characters, which for mysql is a back-tick `. 2) by using the column_comment to control skipped columns, you cannot put a useful comment on those columns. it would be better that if a column name doesn't exist in the array of input data ($_REQUEST in your code), to leave that column out of the query. 3) at the point of running your database level code, you shouldn't know or care where the input data is coming from. the $_REQUEST array of input data should instead be a general php array variable, so that the data can come from any source, such as a form, a csv file, or computed values, without needing to change any of the lower level code. 4) if your table name is dynamic and comes from user supplied input, you will need to validate that it is only and exactly a permitted table name, since there's no protection you can use in the INSERT query for the supplied table name (you can use a prepared query for the SELECT column_name FROM ... query to safely supply the table name in that query.) 5) i hope in general that you are not making a database connection, running one query, then closing the database connection. this is a killer on your database and can cause a noticeable increase in the time it takes your page to be generated on the server. and if you want, you can write that code using only php array functions - $pdo = new PDO("mysql:host=" . SQL_Server . ";dbname=" . SQL_Database, SQL_User, SQL_Pass); function _add_colon($val){ // add the : to the array key/index names return ":$val"; } $sql = $pdo->query("SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'table' AND column_comment <> 'skip'"); $cols = $sql->fetchAll(PDO::FETCH_COLUMN); // fetch just the column_name values as an array $keys = array_map('_add_colon',array_keys($arr)); // $arr is the general purpose array holding the input data $data = array_combine($keys,$arr); // named place holders are used since the order of the columns and input data can be different without any loop in this code to assign values in the same order $query = "INSERT INTO table (`".implode('`,`',$cols)."`) VALUES (:".implode(',:',$cols).")"; // form query in a variable so you can echo/log it for debugging $sql = $pdo->prepare($query); $sql->execute($data); $pdo = null;
-
afaik, there's no built in way this could be done directly by the database. you would need to normalize the addresses, by removing punctuation, converting different white-space characters to a single type (a space), converting groups of multiple white-space characters to a single one, and then replacing abbreviations with the whole words. at that point, barring typo errors in the original data, duplicates would be identical. for the case of typo's, you could then use SOUNDEX() to find same sounding addresses (doesn't test numbers though.) you could also use a levenshtein function (not available in mysql, but could be created as a user written function) to find how many characters are different between two normalized addresses. this would take into account the numbers in the address, whereas SOUNDEX() only operates on alphabetical characters.
-
we can only help you with specific questions and the specific code concerning each specific question. by just dumping multiple files and hundreds of lines of code on a forum, not posted using the forum's bbcode tags, no one is going to help you for free. you need to pick one problem at a time and troubleshoot what's happening to narrow down and just post the code that's relevant to that problem. randomly trying a bunch of different things, without a targeted purpose and goal for each of the things you try, generally doesn't produce any results. if you have a problem with sql injection, you need to do things that are relevant to the portion of your code where the sql query is being built and executed.
-
you forgot to tell us what error, symptom, or incorrect result you got, and what the expected result should have been from your code. without knowing what you saw and what you expected when you ran your code, all we could do is offer a bunch of random guesses that would just be a waste of everyone's time.
-
the stripslashs() code goes before any code you have to escape the data.
- 6 replies
-
- 1
-
- backslashes
- php
-
(and 2 more)
Tagged with:
-
use the get_magic_quotes_gpc() function in some conditional logic - if (get_magic_quotes_gpc()) { $_POST['categoria'] = stripslashes($_POST['categoria']); // example for one value } if you have a bunch of data values to apply this to, you can use php's array_map() (single dimensional data only) or array_walk_recursive() (multi-dimensional data, requires a user written call-back function) to apply stripslashes() to every element of the $_POST array so that you don't need to write out code for each different post variable.
- 6 replies
-
- backslashes
- php
-
(and 2 more)
Tagged with:
-
your server has magic_quotes_gpc on, see this link - http://php.net/manual/en/security.magicquotes.php you either need to turn the setting off, upgrade your php version, or you need to detect if the setting is on in your code and use stripslashes() on the data before you apply your own escaping to the data.
- 6 replies
-
- backslashes
- php
-
(and 2 more)
Tagged with:
-
your first step would be to learn enough of the php language so that you could make an attempt at doing this. programming help does not mean free programming services.
- 1 reply
-
- 1
-
there's nothing about defined constants that are operation system dependent, though your code concerning the values being assigned to the defined constants could be doing something that's php version/configuration dependent. you would need to debug why the constants are empty. we would need to see the code to help, including the type of php opening tag being used in the file. also, in the posted code, your strings are enclosed by curly/smart quotes, not straight-quotes, so php may not be seeing them as the strings you think they are. edit: also2, - how do you know they are defined, do you have php's error reporting and display/log errors set so that you would be getting undefined constant notices if they are not defined?
-
the main site's login block has nothing to do with the forum and shouldn't be used to login to the forum. when you clicked on the links on the main site it redirected you to the forum page, where you were already logged in.