Jump to content
Larry Ullman's Book Forums

Josee

Members
  • Posts

    111
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by Josee

  1. Hello, May I ask those of you who use Eclipse which version they use? Is "Eclipse IDE for JavaScript Web Developers" also OK for PHP, or should I download "Eclipse Classic 3.7.1"? If not, which of the other versions available here: http://www.eclipse.org/downloads/ is the right one for PHP + JavaScript? With thanks for your help,
  2. function check_login($dbc, $username='', $pass='') { else { $u = mysqli_real_escape_string($dbc, trim($username)); // make sure that characters that could disrupt the SQL statement are escaped and then whitespace is trimmed } Shouldn't it be trim($_POST['username'])? As it is, I think you are applying trim() and mysqli_real_escape_string() to the default value of $username, i.e. an empty string.
  3. Your query works (of course ) in my database, except if I mistakenly type an unbreakable space somewhere (on my keyboard, an unbreakable space is option-space). This happens to me now and then, and it's really the kind of typo that's difficult to spot because in phpMyAdmin, for instance, you can't see any difference between an ordinary space and an unbreakable space. Could something like that have happened with this query?
  4. Hello, Jonathon, Are you using the SHA1() function in your query, or the value you quoted?
  5. As for your first question, it depends on how long is your very long string with no spaces. For instance, these two layouts work with not too long strings. But if you test them with strings twice or three times longer in the third column, it won't work, for apparently browsers don't know how to break a string with no spaces at all. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Table</title> <style type="text/css" media="all"> table tr td, table tr th { border: 1px solid gray; padding: 10px; } table.shrinkwrap { table-layout: auto; width: auto; border-collapse: collapse; } table.fixedwidth { table-layout: auto; width: 700px; border-collapse: collapse; } table tr td.auto-width { width: auto; } table.fixedwidth tr td.col100 {width: 100px; } </style> </head> <body> <table class="shrinkwrap"> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3 long string</th> </tr> <tr> <td class="auto-width">this and that and the other</td> <td class="auto-width">00301020</td> <td class="auto-width">Loremipsumdolorsitamet,consectetueradipiscingelit,seddiamnonummynibheuis.</td> </tr> </table> <hr /> <table class="fixedwidth"> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3 long string</th> </tr> <tr> <td class="col100">this and that and the other</td> <td class="col100">00301020</td> <td class="auto-width">Loremipsumdolorsitamet,consectetueradipiscingelit,seddiamnonummynibheuis.</td> </tr> </table> </body> </html>
  6. Thanks for the link, Matt. But isn't there a problem sometimes with the "submit" input field? On Internet Explorer, maybe? I thought that was the reason why Larry often uses the hidden "submitted" field to check for submission. Edit: here it is, from Larry's "PHP 6 and MySQL 5" QuickPro guide:
  7. I know this post is three weeks old, but in case you're interested: I still have a 56kb connection to the Internet (you can't find slower than that!), and your test page works fine for me. I tested both radio buttons, and the definitions appear when I hover over the different words. People used to 8 Gb Internet connexions would probably find it a bit slow, but for me it's fine.
  8. Maybe you could use a hidden field with a different value ("login" or "profile") in each form and check for that?
  9. I'm probably missing something, but wouldn't it be enough to create a $gallery_status variable from the results of your first query, and then use its value for the creation of the navigation menu? Sorry if I missed the point entirely! ;-)
  10. Hello, Sonal, I'm glad it's working for you. You've certainly helped yourself more than I have been able to help you! As for the script, I don't think you need to paste it here if it's similar to the one in Larry's book; I suppose anyone reading this post will have the book, or can download the script from the website. Good luck with your multilingual website!
  11. Thank you for the update, Sonal. Let us know how you manage the integration with PHP and MySQL, will you? I'm sure it can be useful to many people.
  12. I think with this: if(!$problem) { print'<p>Registration is good.</p>'; $_POST = array(); } you are reinitializing, i.e. creating a new empty POST array. So after this line $_POST['first_name'] and the others are FALSE.
  13. Hello, Sonal, I'm not great at fonts, unfortunately, but I think your tests show that your Gujarati fonts are not Unicode. On the following page, from the Unicode official website, maybe you could try to find a free Unicode Gujarati font and download it to your computer so that you can use it in your website. http://www.unicode.org/resources/fonts.html You can also try this website: http://scriptsource.org/cms/scripts/page.php?item_id=default I suppose another solution would be to change the character set for the Gujarati column in your database, but that would probably create more problems than it would solve, particularly if you want to be able to use both English and Gujarati on your web pages. Good luck! Unicode is supposed to make life simpler on the Internet, but I'm afraid it's still a promise for the future, not for right now! EDIT: I just found this website that may be useful to you: http://www.gujaratilexicon.com/downloads/
  14. Do you have the corresponding fonts on your computer? For instance, Bengali can be represented with UTF-8, but I can't see the characters on my computer because I don't have any Bengali font. Two sites I find useful for non-Latin characters: http://www.fileformat.info/info/unicode/block/index.htm Choose a Unicode block in the list, then click on "UTF-8 browser test" to check that you can see these Unicode characters in your browser. http://utf8-characters.com/groups/ This site is useful for details on all characters. I hope this helps,
  15. Thank you for your answer, Larry. I'll probably update Snow Leopard, then, and try again downloading Ruby 1.9.2. (I'll probably install Linux some day, but just out of curiosity, so I'm in no hurry!)
  16. Hello, Larry, I just began your Ruby book this week-end and was enjoying it, when I realised that I was going to have the same problems with Ruby as with PHP: French accents and diacritics! Then I saw you mentioned Ruby 1.9 would include Unicode, and since Ruby 1.9.2 is available, I tried to install it but failed. I'm working on an iMac with system 10.6.2. Ruby 1.8.7 is included. I first tried to build Ruby from the source code but got the following error message (that's just a part of it, of course): Then I went to www.macports.org, but they say I need XCode 3.2.1 in order to install Ruby 1.9.2, and my version of XCode is only 3.1.2. On the Apple website, XCode 3.2.1 is not freely available; you must be a (paying) developer to download it. A friend tells me Mac OS 10.6.8 comes with XCode 3.2.6, but also with Ruby 1.8.7 only, so I'm wondering if it's any use upgrading the system to 10.6.8 and XCode to 3.2.6: do you know if there's some kind of incompatibility between Snow Leopard and Ruby 1.9 that would explain why it's not already installed on system 10.6.8? Would I be better off installing Linux on my Mac (I've got a free partition waiting for it!), and then installing Ruby on the Linux partition? With thanks in advance for your help,
  17. I think this is because you put require_once(MYSQL); in the first "else" (need to determine the number of pages), whereas you also need the bdd connection if the number of pages is in the GET array. Try moving the bdd connection to the top of your script, just before the first "if". I hope this helps,
  18. If you want isolate a few rows from the array returned by a query, you can use mysqli_data_seek and mysqli_fetch_row. I used that for seeking the median value from a database. I'm sure there are many other ways of doing this, but I needed first to group results, then to calculate the median for each group, and this was the simplest way I found (it's just the beginning of the script): foreach ($_POST['menu_langues'] as $key => $id) { // I fetch the results for each group separately and order them // on "l", which is the column I'll use for calculating the median $query = "SELECT t.id_langue AS id, lg.langue AS langue, t.l AS longueur FROM textes AS t INNER JOIN langues AS lg USING (id_langue) WHERE t.id_langue = $id ORDER BY t.l"; if ($result = @mysqli_query($bdd, $query)) { // Number of results $n = mysqli_num_rows($result); // I seek the first row returned by the query // and fetch the content (the minimal value for "l") mysqli_data_seek($result, 0); $mini = mysqli_fetch_row($result); // I seek the last row (its position in the array is equal to n - 1) // and fetch the content (the maximal value for "l") $rgx = $n - 1; mysqli_data_seek($result, $rgx); $maxi = mysqli_fetch_row($result); // If the query returned an odd number of results, // the median value is in the middle row // For instance, with 15 results, the median is in the 8th row, // numbered 7 in the array. if ($nb % 2 == 1) { $rg = $nb / 2; mysqli_data_seek($result, $rg); $rang = mysqli_fetch_row($result); // and so on } } } This couple of functions can be very useful sometimes.
  19. I haven't worked at it since I read your solution, but I think it will work. I had the idea to search for a similar solution since reading #27 from Wicked Cool PHP where they use it (although the $i variable is used in a hidden field), saying it's often the way to go when you know you will have a multidimensional array but don't know how many elements there will be in it in advance. Their example is for a shopping cart: you don't know how many items the customer will buy, so you number them this way. I happened to read this yesterday, just an hour or two before you posted your solution, so I was trying to apply it to your problem and mine, but you were quicker!
  20. Problem solved! My mistake was using a "while" loop, because query $q0 returns only one result. That's why the error message says: called at [(null):0] The "while" loop was "looking" for other rows when there couldn't be any since the query was limited to one row. So, the code that works is simply: if (isset($_POST['submitted'])) { require_once(MYSQL); include('includes/fonctions_outils.php5'); if (empty($_POST['referent'])) { echo '<p class="erreur">Indiquer le référent à chercher.</p>'; } else { // nettoyer() is a user-defined function just applying // mysqli_real_escape_string(), trim() and so on to data. $referent = nettoyer($_POST['referent']); $q0 = "SELECT id_referent, SUBSTRING_INDEX(referent, '_', 1) FROM referents WHERE SUBSTRING_INDEX(referent, '_', 1) = '$referent' AND id_gramm_cat = 2"; $r0 = @mysqli_query($bdd, $q0); $n0 = mysqli_num_rows($r0); if ($n0 > 0) { // No loop, since I'm only querying 1 row. $row0 = mysqli_fetch_array($r0, MYSQLI_NUM); $id_referent = (int) $row0[0]; echo '<h1>'.$id_referent.' '.$row0[1].'</h1>'; } } }
  21. Thank you for your answer. Yes, I use $row0[0], like this: if ($n0 > 0) { while ($row0 = mysqli_fetch_array($r0, MYSQLI_NUM)) { $id_referent = (int) $row0[0]; echo '<h1>'.$id_referent.' '.$row0[1].'</h1>'; … } } That's what generates the <h1> title (2 cingler) you can see just above the table. I also tried suppressing the @ symbol as you suggested, but that didn't change anything. In fact, the script generates exactly what I want at this stage… except for this error message, of course! That's what's frustrating. When I don't get the results I expected, I more or less know where to start looking for mistakes in my scripts, but here, I don't understand what the problem is.
  22. Thank you for posting your solution, Antonio. I'm trying to create a very similar script, although it's for a French dictionary, and was struggling with the $i variable: I knew I had to use it somehow, but was still grappling in the dark!
  23. Hello, Could someone please help me understand an error message? My script is supposed to fetch from the database all the different forms for a French verb and print them, and so it does, just as expected (here is the beginning of the page): except that just after the results I get this error message: '/Users/xxx/Dropbox/Travail/htdocs/xxx/flexions_afficher.php5' line 32 : mysqli_fetch_array() [function.mysqli-fetch-array]: Couldn't fetch mysqli_result Line 32 is the first "while" loop in my script: if (isset($_POST['submitted'])) { require_once(MYSQL); include('includes/fonctions_outils.php5'); if (empty($_POST['referent'])) { echo '<p class="erreur">Indiquer le référent à chercher.</p>'; } else { // nettoyer() is a user-defined function just applying // mysqli_real_escape_string(), trim() and so on to data. $referent = nettoyer($_POST['referent']); $q0 = "SELECT id_referent, SUBSTRING_INDEX(referent, '_', 1) FROM referents WHERE SUBSTRING_INDEX(referent, '_', 1) = '$referent' AND id_gramm_cat = 2"; $r0 = @mysqli_query($bdd, $q0); $n0 = mysqli_num_rows($r0); if ($n0 > 0) { // The following line is line 32. while ($row0 = mysqli_fetch_array($r0, MYSQLI_NUM)) … } } } I'm not sure what to copy from the details of the error message, so here is the end. Please let me know if it's not enough information. [_REQUEST] => Array ( [referent] => cingler, [valider] => Valider, [submitted] => TRUE, [phpSESSID] => b64ad9fd3334351660539297c072d784), [page_title] => Flexions, [HTTP_SESSION_VARS] => Array (), [_SESSION] => Array (), [bdd] => mysqli Object (), [referent] => cingler, [q0] => SELECT id_referent, SUBSTRING_INDEX(referent, '_', 1) FROM referents WHERE SUBSTRING_INDEX(referent, '_', 1) = 'cingler' AND id_gramm_cat = 2, [r0] => mysqli_result Object (), [n0] => 1, [row0] => Array ( [0] => 2, [1] => cingler ), [id_referent] => 2, [q1] => SELECT rf.id_flexion, f.flexion, rf.id_gramm_mood, m.gramm_mood, rf.id_gramm_tense, t.gramm_tense, rf.id_gramm_number, n.gramm_number, rf.id_gramm_person, p.gramm_person, rf.id_gramm_gender, g.gramm_gender FROM referents_flexions AS rf INNER JOIN flexions AS f USING (id_flexion) LEFT JOIN gramm_moods AS m USING (id_gramm_mood) LEFT JOIN gramm_tenses AS t USING (id_gramm_tense) LEFT JOIN gramm_numbers AS n USING (id_gramm_number) LEFT JOIN gramm_persons AS p USING (id_gramm_person) LEFT JOIN gramm_genders AS g USING (id_gramm_gender) WHERE rf.id_referent = 2 ORDER BY rf.id_gramm_mood, rf.id_gramm_tense, rf.id_gramm_number, rf.id_gramm_person, rf.id_gramm_gender, [r1] => mysqli_result Object (), [num1] => 51, [row1] => )) called at [(null):0] #1 mysqli_fetch_array(mysqli_result Object (), 2) called at [/users/xxx/Dropbox/Travail/htdocs/xxx/flexions_afficher.php5:32] Could someone explain why I get this error message, and what it means ? With thanks in advance for your help,
  24. If you want to check that mysqli_num_row($R) is not equal to zero, you should use != 0 or > 0; not !== 0.
  25. It's all in the book, really, if you look at chapters 14 and 15. There are a few explanations from these two chapters that won't work because they apply to PHP 6 only, but it's really a minority. All the functions (mysqli_set_charset(), etc.) are explained. And Larry provides us with a very good introduction to Unicode and all that entails. All the same I also spent ages trying to get my head around all these globalisation problems. I'm afraid that can't be avoided at this stage of PHP and MySQL development. UTF8 is still more of an added layer than an integral part of the languages.
×
×
  • Create New...