Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by phdphd

  1. Well, Christian, you must be right somewhere. I was just writing the following when you sent your post I noticed in my session variables that before sending data to db, linebreaks appear as "\\r\\n". I think this is due to a mysql_real_escape_string processing in my code. So I solved the issue using the statement : $txt = str_replace("\\r\\n", "\r\n", $txt); now text appears correctly laid out in the textarea. Thanks to all of you.
  2. Thanks for your reply. However, for "cosmetics" reasons, I want the text to appear as the user initially wrote it, with the same layout, and without "\r\n". If it works from a manually set variable, then there is no reason why it should not from a text retreived from a database.
  3. Hi All, I am facing an issue I cannot solve and I just do not understand why. In a db table, I've got a field that contains text coming from a textarea in a form. If the user had entered breaklines to divide their text into paragraphs, the breaklines are replaced with "\r\n" strings, so the text in the table field may look like "Hello\r\nHow are you?". This works. Now, assuming that the user wishes to edit that text, I want to retreive that text into a textarea, with the same paragraph layout as that initially used by the user. Here is my code (without the whole db error checking code) : $link = @mysql_connect('localhost', 'root', ''); mysql_select_db('mydb', $link); $sql = 'SELECT * FROM table_name Where field_id="31"'; $rs = mysql_query($sql, $link); $arr = mysql_fetch_array($rs); $txt =$arr['user_input']; $txt = nl2br($txt); echo '<br />retrieved text from db is ' .$txt.'<br />';//Will display "retrieved text from db is Hello\r\nHow are you?" $txt=str_replace("<br />", "", $txt); echo '<br /><textarea name="text" cols="100" rows="15" >'.$txt.'</textarea>';// Will display "Hello\r\nHow are you?" in the textarea Now if manually set a variable called "Hello\r\nHow are you?". The following code $string = "Hello\r\nHow are you?"; $string=nl2br($string); $string=str_replace("<br />", "", $string); echo '<br /><textarea name="text2" cols="100" rows="15" >'.$string.'</textarea>'; Will generate "Hello How are you?" in the textarea. Why can't I manage to make this work with the text retreived from the database ? Thanks for your help. Phd
  4. Thanks all of you for your answers. My PHP code never sets a value for the ID field. It fills only the other fields. Basically the code puts all the data entered by the user in an array where keys are named according to the field names in the DB table, then it builds the insert condition by simulating SQL language and by using array key names as table fields and array values as the table values to be inserted. Should the query fail for any reason (no connection to server/database, wrong table name/field, etc.), and since my website is still under development, typical PHP error messages display. There are anyway no automatic retries in my php code, since it is designed to stop running in such situations and to display a message to the user. Definetely not enough to account for the values skipped. For example, the autoinc counter jumped from 2000203 directly to 9999999 while just a few minutes/hours elapsed between the 2 inserts. I never manually tested 7 millions queries in the meantime, and my code is not designed to do that automatically anyway. All header instructions are followed by exit() instructions. All in all I just wonder whether the "guilty" is not the ZEROFILL setting. It is very strange that the autoinc counter jumped from 2000203 to 9999999. I have the feeling that if I had chosen INT(12) instead of INT (7), it would have jumped from 000002000203 to 999999999999.
  5. Thank you for your answer. Here are my comments. The insert SQL/PHP instruction does not set the ID table field. Basically I have an array containing data gathered from a form like name, address, zip code, city, etc. Then I send this data to the table, each piece in the corresponding field, and let the database set the value in the ID field. I do not insert data massively. And should data already exist in the DB there would be no conflict because I test (SELECT) whether data exists before sending (INSERT) it to the DB. No such a risk yet , my website is still under development on my PC.
  6. Hi All, I defined an autoincrement ID field with 7 digits (int(7) ZEROFILL), so as to get 0000001, 0000002, 0000003, etc., enough for the table to contain as many as 10 000 000 rows. At the beginning all was OK. Then I noticed that the field would "skip" entire ranges. For example, it would directly go from 0000100 to 0000200. Things became very complicated when it went directly to 9999999, which is the last value allowed by int(7), because the next time it set the "10000000" value, which contains 8 digits, whereas it had so far used only 99.9999% of the values available with int(7). The problem is that I really need an 7-digit format for this field. Is there a way to really force the field to use the next available value? Thanks for your help!
  7. Hi PFMaBiSmAd, Let me put it simple in just four words : THANK YOU VERY MUCH ! Sometimes we search the universe while what we are looking for is at our fingertips. I cleared safari's cache, repeated the process and no error occurred. Thank you again. Have a great day. You deserve it.
  8. Hi All, While testing my PHP code on Firefox and Safari, I noticed that one error of type "Parse error: syntax error, unexpected ')'" would display on Safari, but not on FF. Very strange... (Actually there is no extra ')' anyway.) This error appears while clicking repeatedly the back button in the Safari toolbar, once the user has gone through the whole process one way. Doing the same in Firefox does not trigger any error. I thought "Is there really an error on Safari ? If so, it must be possible to record it in a log file". So, to simulate the user's environment, and record all the errors in a .log file, while preventing them to display, I inserted the following lines at the beginning of the script in the file that is mentioned in the error message : error_reporting(E_ALL | E_STRICT); ini_set('error_log', 'test.log'); ini_set('log_errors', 'On'); ini_set('display_errors', 'Off'); Unfortunately, not only I still get the error of type "Parse error: syntax error, unexpected ')'" , but also this error is not recorded into the log file, despite the fact that I did put the error managing code in the PHP file stated in the error message (and that file contains only one PHP script, so no risk to put the error managing code in a wrong script). To test whether that code is functional, I added 1/0; in order to test the division by zero. Now, the error related to the "division by zero" instruction does not display and it is recorded in the .log file, which means that the code is functional. However, the error of type "Parse error: syntax error, unexpected ')'" still displays and does not get recorded into the log file. Any idea of what is going wrong on Safari ? It would be annoying having error messages display in a browser (and possibly reveal some sensitive coding data) while there is actually no error. Thanks for your help.
  9. Thanks for your reply. I was afraid something was wrong in my approach.
  10. Hi All, I have a big problem with session variables getting lost when playing with back/next buttons. This leads to wrong data being displayed, and possibly PHP error messages. From the user's point of view, there is a series of forms to fill in, one form being allowed to display only if ALL previous ones have been correctly filled in. It all works perfectly. But the problem can appear when playing with back/next buttons. Basically, my files are organized as follows. There is a main php file that "drives" the whole structure, where each remaining file contains POST method and SERVER/PHP_SELF action as form settings. This main file contains 2 parts. The first part is where I test/analyse the existence and contents of the POST variables. The second part is where I call the correct form (through an "include" statement) according to the result of the POST test/analysis. For example, if form_1 is correctly filled in, form_2 is called, if not, form_1 is displayed again. In each POST testing, the part that runs if the form is correctly filled in contains two $_SESSION lines. Assuming form_1 POST variable is being analysed, these 2 lines would be something like $_SESSION[form_2_can_be_displayed]=1 and $_SESSION[user_went_through_form_1]=1. $_SESSION[form_2_can_be_displayed] is the variable that is tested for in the second part of the main php file and that will enable to trigger the display of form_2 through an include statement. $_SESSION[user_went_through_form_1] variable is tested for at the beginning of the analysis of POST variable for form_2. In other words, POST variable for form_2 will only be analysed if the user did successfully go through form_1. $_SESSION[user_went_through_form_1] is never unset except at the very beginning of the analysis of POST variable for form_1 in case form_1 had already been successfully submitted by the user. So, as the user moves from form to form, successive $_SESSION[user_went_through_form_XXX] variables get recorded into the global SESSION variable. With such data, I can safely test a POST if ALL previous forms have been passed through. If this condition is not met, a message appears prompting the user to return to the home page. Assuming form_3 POST variable is being parsed, the structure of the test would be something like this (with simplified ELSE details) : If (isset[post_for_form_3]) { If (isset($_SESSION[user_went_through_form_1]) && isset($_SESSION[user_went_through_form_2])) { If (isset($_SESSION([user_went_through_form_3])) { unset $_SESSION([user_went_through_form_3]) } //process the POST variable// If (user-entered data is OK) { $_SESSION([user_went_through_form_3])=1 $_SESSION[form_4_can_be_displayed]=1 } Else { $_SESSION[form_3_can_be_displayed]=1 } } Else { //Instructions to display the "return to home page" message } } As said at the beginning of my post, it all works perfect from the first form to the last one, but afterwards if I randomly play with back/next buttons I may suddenly get the " return to home page" message, meaning that the "isset($_SESSION[user_went_through_form_XXX])" line test has failed. I just do not understand why this happens, because there is no reason why the $_SESSION[user_went_through_form_XXX] should be missing. For example, when falling again on [post_for_form_3], why "isset($_SESSION[user_went_through_form_1])" or "isset($_SESSION[user_went_through_form_2])" should be missing ? These variables were initially set on successful testing of POST variables for form_1 and form_2 and never unset aftewards. Please help ! Thanks !
  11. Hi All, In one of the pages of my site, I extract a series of terms, classified by categories, from a database. Initially, all info was listed in a single column (category name, term list, other category name, other terms list), which left much unused room on the center & right sections of the page. From a CSS code available at http://www.inserthtml.com/2012/01/css3-multi-column-layout-implementation-change-website-design/, I successfully applied a formatting in order to use the whole width of the page. Now the problem is that one category of terms can start at the end of a column and continue at the top of the next one. To force a column break before each category, I associated a <span class="breakhere">category_name</span> tag to the categories and added .breakhere { color: blue; break-before: column; -webkit-column-break-before: column; -moz-column-break-before: column; -ms-column-break-before: column; -o-column-break-before: column; } to the CSS code. This tag is functional since the text does display in blue. However, no column break is applied before the category names. Any idea of what is going wrong ? Thanks !
  12. Hi, Let me rephrase my question. Imagine you developed a long time ago a website for a local audience, and that given its great success you decide to target it to other audiences in other countries. Is there a utility that enables to extract all translatable strings before sending them for translation ? "All" means extracting for example "My Website" from <title>My Website</title> but also from echo 'My Website'; of from echo $a .'My Website'. $b;
  13. Hi All, I want my site to be available in different languages and wonder whether there exists a utility that helps extract from HTML/PHP code all the strings that are likely to be displayed to the user. This will be very helpful when entering the translation process. Any idea or clue ? Thanks.
  14. Well so far I have no specific issue, I am just wondering how to get the best protection against any violation of the website, which is still under construction. There will be a lot of php coding and time spent on it. One of the issues could be redirecting the visitor to another website. I have read in another forum that a hacker can do this by editing a website file. This implies the hacker can access the file. Then other issues can happen : by accessing the php files that make up a website, the hacker can also steal php coding, get database credentials, make any change to the DB, etc, and eventually ruin all the webmaster's efforts, even if the webmaster regularly makes backups of the website and DB. Any suggestions/procedures that a webmaster should follow to implement the highest level of protection are welcome. Thanks. PhD
  15. Sorry, I am not an IT/Internet specialist. Let me try to rephrase again If a hacker just exploits a weakness of the configuration of the server that hosts the website, does this always give them access to the php files of your site and to their contents or do they also need to violate the security procedures set by the webmaster at the website level in order to access the php files? Regards PhD
  16. Thanks for your quick answer. In case of (b), can the hacker open/modify the php files without violating the procedures that the webmaster had set for the website ? Regards, PhD
  17. Let me try to rephrase it. Problem : imagine you own a website that is listed in a Google search results page when the user enters some key words. One day, it appears that when the user clicks the link, the homepage of another website appears instead of the homepage of your website. Questions : (a) can this be due ONLY to a violation of the security procedures implemented by the webmaster for the website (htaccess file, password/login settings, etc) or (b) can it be also achieved by exploiting a weakness of the configuration of the server that hosts your wbsite ? If answer is (b), does a dedicated server (i.e. a server that hosts only your website) offer a better protection ? Thanks. PhD
  18. Hi All, When one clicks a link in a search engine, they might be redirected to another site than the one they want to visit, due to a hacking issue. Let's suppose that the site is hosted on a shared server and that the webmaster of the site cannot be held responsable for this issue. Can there be an issue at server level ? Could the use of a dedicated server bring an additionnal protection ? Thanks for sharing your view. PhD
  19. Wow, very impressive ! Thanks a lot MMDE ! You deserve a gold medal.
  20. Hi, Sorry for being late.... The form will look as follows : <form method="post" action="target.php"><br /> </p>Category1:<br /><br /> <input type="checkbox" name="cat1[]" value="cat_1_val_1">Value 1 of category 1<br/> <input type="checkbox" name="cat1[]" value="cat_1_val_2">Value 2 of category 1<br/> <input type="checkbox" name="cat1[]" value="cat_1_val_3">Value 3 of category 1<br/> <input type="checkbox" name="cat1[]" value="cat_1_val_4">Value 4 of category 1<br/> <input type="checkbox" name="cat1[]" value="cat_1_val_5">Value 5 of category 1<br/> <br /> </p>Category2:<br /><br /> <input type="checkbox" name="cat2[]" value="cat_2_val_1">Value 1 of category 2<br/> <input type="checkbox" name="cat2[]" value="cat_2_val_2">Value 2 of category 2<br/> <input type="checkbox" name="cat2[]" value="cat_2_val_3">Value 3 of category 2<br/> <input type="checkbox" name="cat2[]" value="cat_2_val_4">Value 4 of category 2<br/> <input type="checkbox" name="cat2[]" value="cat_2_val_5">Value 5 of category 2<br/> <br /> </p>Category3:<br /><br /> <input type="checkbox" name="cat3[]" value="cat_3_val_1">Value 1 of category 3<br/> <input type="checkbox" name="cat3[]" value="cat_3_val_2">Value 2 of category 3<br/> <input type="checkbox" name="cat3[]" value="cat_3_val_3">Value 3 of category 3<br/> <input type="checkbox" name="cat3[]" value="cat_3_val_4">Value 4 of category 3<br/> <input type="checkbox" name="cat3[]" value="cat_3_val_5">Value 5 of category 3<br/> <br /> <input type="submit"/> <input type="reset" /></p> </form> Thanks for your help.
  21. Well, I am afraid not at first sight Let me give an example with simple data. The data collected in $_POST can be as follows Array ( [cat1] => Array ( [0] => house [1] => building ) [cat2] => Array ( [0] => cloud [1] => sun ) [cat3] => Array ( [0] => happy [1] => sad ) ) The generated list will then be : house _ cloud _ happy house _ cloud _ sad house _ sun _ happy house _ sun _ sad building_ cloud _ happy building_ cloud _ sad building _ sun _ happy building _ sun _ sad Should the user not select any options in cat2, the generated list would be : house _ happy house _ sad building _ happy building _ sad In other words, the PHP code that generates the list must adapt to whether or not the user did select options in the different categories (whatever the number of categories), because this will determine the number of foreach loops. Thanks in advance !
  22. Hi all, Using a form with check boxes divided into different categories, I collect data selected by the user. I now want to combine each choice in each category with each choice in the other categories and list the combinations to the user. If the user chooses one or more options in each category, it is relatively easy to nest foreach loops, since the number of categories will always be the same. For example, if the form contains three categories of options, the code will be: foreach ($form['cat_1'] as $k1 => $val1) { foreach ($form['cat_2'] as $k2 => $val2) { foreach ($form['cat_3'] as $k3 => $val3) { echo $val1.' _ '.$val2.' _ '.$val3.'<br/>'; } } } Things get complicated if the user does not select options within a given category. More generally, I want to be able to generate the list regardless of the number of categories in which the user selects options. Thank you in advance for your advice.
  23. Thanks a lot requinix for your quick and relevant answer ! It works perfect ! You are definitely the strongest
  24. Hi All, There is a very interesting solved topic here (http://www.phpfreaks.com/forums/index.php?topic=304966.0) about how to access elements in embedded _POST array. But before accessing an element, it might be appropriate to check whether the array it is supposed to be in exists. According to the solution given in the topic indicated above, $_POST['matType'] is an example of embedded array . Is there a way to check if this array exists? Thanks in advance for your help.
  • 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.