Jump to content
Larry Ullman's Book Forums

Josee

Members
  • Posts

    111
  • Joined

  • Last visited

  • Days Won

    6

Posts posted by Josee

  1. Hello, Larry,

     

    I don't think that "a bad e-book reflects poorly" on you or any author. It reflects badly on publishers. And I can't see any other reason, on their part, for selling protected PDFs than trying to avoid pirate versions. Which they don't. That's just the point I'm trying to make: given the number of pirate versions on the web, pirates have obviously found ways round the protections. These protected PDFs are only annoying to ordinary, paying customers who just want to use a book as a book, and a computer as a computer. I don't think there's any justification to treating all e-book readers as potential thieves just because a few of them may be.

     

    I finally bought the Kindle version. It's just as bad, from my point of view, as a protected PDF (the limitations are more or less the same), but the printed version is not yet available in France and no date is given. I was just surprised to find that reading a Kindle version on a computer (I haven't got a Kindle) is actually better in some ways than reading a PDF, because the Kindle version is "responsive": it adapts to the viewport width.

  2. That's really a matter of taste, of course. I never forget which ebooks I have, and for programming books I really prefer ebooks. As I've got a large screen, I keep the ebook on one side of the screen, my text editor next to it, and can easily alternate between reading and testing.

     

    I've also discovered that I can't change the file preferences so as to choose the zooming factor once for all, and indicate where I stopped reading so that the file opens at the right page on the next day.

     

    Did you say "they may be living in the past"? With a vengeance! (Mine…)

  3. Sadly, I've just cancelled my order, for in the meanwhile I've discovered that Peachpit and I don't have the same conception of e-books. To them, e-books are apparently just pictures of printed books that you can read on a computer, iPad, etc. To me, they should be numerical books that I can use as I want, which means

    — adding bookmarks,

    — adding links within the file and with other files,

    — copying a few lines to paste them in another file.

     

    You can't do any of these things in their PDFs. To be fair, you can add comments and notes, which is good. But it's not enough for me, especially when I've made a point of buying the books, instead of just looking for pirate versions on the web.

  4. Hello,

    You should be able to use variables. For instance, here is what I do for the "description" meta tag, and for the CSS files:

     

    • In the header:

    <meta name="description" content="<?php print $meta_description ?>"

    <link rel="stylesheet" type="text/css" href="<?php print BASE_URL.$style ?>" />

     

    • Near the top of each page:

    $meta_description = "Some description";

    $style = 'css/some_file.css';

     

    I hope this helps,

    • Upvote 1
  5. Hello, everyone,

     

    Peachpit (the publisher of Larry's books) has the following offer at the moment:

     

    Offer valid through February 21, 2012. PRESIDENT coupon provides 40% discount off the list price of two, or 50% off on three eBooks or videos, or any combination of eBooks and videos. PRESIDENT coupon may not be combined with any other offer, and is not valid for book + eBook bundles or eBook Deal of the Week featured titles.

     

    I'm just mentioning this because it applies to Larry's JavaScript book (ebook version only). Although its official publication date is 22 February and it's only on pre-order yet, you can include it in the two or three ebooks entitled to this discount.

     

    In case you hadn't guessed, I'm really looking forward to reading this book!

    • Upvote 1
  6. For your forms to accept French diacritics, you just need to add them to the regular expression, like this (since the match is case insensitive, no need to add lower-case characters):

    preg_match('/^[A-Z ÀÂÄÆÇÈÉÊËÎÏÔŒÙÛÜŸ\'.-]{2,20}$/i', $_POST['first_name'])

     

    And if you want them to accept all European languages using the Latin alphabet, this should do it (all on one line, of course):

    preg_match('/^[A-Z ÀÁÂÃÄĀĂĄÅÆÇĆĈĊČĎĐÐÈÉÊËĒĔĖĘĚĜĞĠĢĤĦÌÍÎÏĨĪĬĮİ

    IJĴĶĸĹĻĽĿŁÑŃŅŇʼnŊÒÓÔÕØŌŎŐŒŔŖŘߌŜŞŠŢŤŦÙÚÛÜŨŪŬŮŰŲŴÝŸŶŹŻŽſÞð\'.-]

    {2,20}$/i', $_POST['first_name'])

     

    I hope this helps,

    • Upvote 1
  7. I think your mistake is that you are just opening the file in your browser (if that's the case, the address begins with file://) instead of running it through your local server (in that case, the address begins with http://, and probably looks like http://localhost:8888/directory/predefined.php). You need to run it through your XAMPP server so that the server can interpret the PHP code. See Larry's explanations on page 4.

     

    I hope this helps,

  8. Hello, Zrakot,

     

    Try this script from different locations (on your computer/local host, on your webhost's server, and in different folders).

    It should help you with URIs and URLs:

     

    <!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>Server test</title>

    <style type="text/css">

    .bleu { color: #2200cc; /* blue */ }

    h2 { margin-top: 2em; margin-bottom: 0.7em; }

    h3 { margin-top: 1.2em; margin-bottom: 0.5em; }

    p { margin-top: 0 }

    </style>

    </head>

    <body>

     

    <h3>IP address of the server host</h3>

    <p><span class="bleu">$_SERVER['SERVER_ADDR']</span> =

    <?php echo $_SERVER['SERVER_ADDR'] ?>

    </p>

     

    <h3>Server name</h3>

    <p><span class="bleu">$_SERVER['SERVER_NAME']</span> =

    <?php echo $_SERVER['SERVER_NAME'] ?>

    </p>

     

    <h2>URIs</h2>

    <h3>Root folder</h3>

    <p>(PHP manual: "The document root directory under which the current script is executing, as defined in the server's configuration file.")<br />

    <span class="bleu">$_SERVER['DOCUMENT_ROOT']</span> =

    <?php echo $_SERVER['DOCUMENT_ROOT'] ?>

    </p>

     

    <h3>Absolute path for this script from root folder</h3>

    <p>(PHP manual: "The filename of the currently executing script, relative to the document root.")<br />

    <span class="bleu">$_SERVER['PHP_SELF']</span> =

    <?php echo $_SERVER['PHP_SELF'] ?>

    </p>

     

    <h3>Absolute path for this script</h3>

    <p><span class="bleu">$_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF']</span> =

    <?php echo $_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF'] ?>

    </p>

     

    <h3>Absolute pathname of the currently executing script</h3>

    <p><span class="bleu">$_SERVER['SCRIPT_FILENAME']</span> =

    <?php echo $_SERVER['SCRIPT_FILENAME'] ?>

    </p>

     

    <h3>Current script's path</h3>

    <p>(PHP manual: This is useful for pages which need to point to themselves. The __FILE__ constant contains the full path and filename of the current (i.e. included) file.)<br />

    <span class="bleu">$_SERVER['SCRIPT_NAME']</span> =

    <?php echo $_SERVER['SCRIPT_NAME'] ?>

    </p>

     

    <h3>Folder where this script is kept</h3>

    <p><span class="bleu">dirname($_SERVER['PHP_SELF'])</span> =

    <?php echo dirname($_SERVER['PHP_SELF']) ?>

    </p>

     

    <h2>URLs</h2>

    <h3>Host name</h3>

    <p>(PHP manual: Contents of the <em>Host</em>: header from the current request, if there is one.)<br />

    <span class="bleu">$_SERVER['HTTP_HOST']</span> =

    <?php echo $_SERVER['HTTP_HOST'] ?>

    </p>

     

    <h3>Complete URL</h3>

    <p><span class="bleu">$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']</span>

    <?php echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'] ?>

    </p>

     

    <h2>User's IP Address</h2>

    <p>(PHP manual: "The IP address from which the user is viewing the current page.")<br />

    <span class="bleu">$_SERVER['REMOTE_ADDR']</span> =

    <?php echo $_SERVER['REMOTE_ADDR'] ?>

    </p>

     

    </body>

    </html>

  9. You still need to delete the quotation mark at the beginning of the query. That's why the error message shows """ at the beginning of your query.

     

    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"SELECT c.comment, DATE_FORMAT(c.dateSub, '%M, %Y') AS ds, CONCAT(u.firstName, '' at line 1

    • Upvote 1
  10. in script '/homepages/41/d12345679/htdocs/mysite/login5/htdocs/register.php' on line 10: require(/kunden/homepages/41/d12345679/htdocs/mysite./mysqli_connect.php) [function.require]: failed to open stream: No such file or directory

     

    It just means that on line 10 of the register.php file you are not giving the right path (URI) for your mysqli_connect.php file. And this is probably because this URI should not include htdocs/. It should probably end with d12345679/mysite/mysqli_connect.php.

     

    This topic from the previous forum may help you (see neil_g_cnd's answer, nearly at the bottom of the page).

     

    I hope this helps,

  11. Hello, Marie,

     

    Your server probably has Magic Quotes on. Look at the escape_data() function at the bottom of page 55. It will show you both how to check that this is the case – just echo the result of if (get_magic_quotes_gpc( )) – and how to solve the problem once for all.

     

    But, since you are from Canada, also note that the regular expression, as it is, won't allow for French names with diacritics, such as "Jean-François Desfossés". It only allows the English alphabet.

    • Upvote 1
  12. Hello, roberts,

     

    I think one solution would be to add "multiple" to your dropdown menu, so that "season" would become an array instead of a scalar value. Instead of:

    <select name="season"><?php

    $physios=array( "All" => "All employees",

    "Chefs" => "Chefs",

    "Wait" => "Wait" );

     

    you would have:

     

    <select name="season[]" multiple="multiple" size="2"><?php

    $physios=array("Chefs" => "Chefs", "Wait" => "Wait");

     

    Thanks to "multiple", users can select either one or both options. 'Size="2"' means two lines will be visible in your drop-down menu (both options in your case). I never remember off-hand, but I think we use the command key to select more than one option.

     

    I hope this helps,

  13. Hello,

     

    First, my very best wishes to everyone for this new year 2012.

     

    … And my first question for 2012!

     

    I'm trying to enlarge the create_form_input() function from chapter 4 so that it also takes care of labels. I've managed to do practically everything I want it to do, except that I would like the $label_text argument to have a default value, and I haven't found a solution yet. The idea is that the label text would be based on the $name variable in this way:

    $label_text = ucwords(str_replace('_', ' ', $name));

    If there was only English to be taken into account, I could just hardcode it into the function. There would be no $label_text parameter, and I would just write:

    <label for="'.$name.'">'.ucwords(str_replace('_', ' ', $name)).'</label>

    so that if the value of $name is 'first_name', the label text is 'First Name'.

     

    But, since I want this function to handle the label text whatever language is used, I need a $label_text argument. I first thought of making ucwords(str_replace('_', ' ', $name)) the default value for the $label_text parameter, but I don't know how to achieve this since the PHP manual states that "The default value must be a constant expression, not (for example) a variable, a class member or a function call."

     

    I then thought of passing this function parameter by reference, and the beginning of the function now looks like this:

    function create_form_input2($name, $type, $size_rows, $maxlength_cols, $label_class, &$label_text, $input_class, $errors, $span_class='') {

    $value = false;

    if (isset($_POST[$name])) $value = $_POST[$name];

    $label_text = ucwords(str_replace('_', ' ', $name));

     

    It works if I keep the variable for this parameter:

    create_form_input2('first_name', 'text', '30', '30', 'left', $label_text, 'margin_left', $erreurs);

    This is what I get:

     

    form110.jpg

     

    But if I try using a string, I get the following error message:

    Fatal error: Cannot pass parameter 6 by reference in ecom1/index.php5 on line 27

    Line 27 being:

    create_form_input2('first_name', 'text', '30', '30', 'above', 'Prénom', 'below', $erreurs);

    which means that I still don't understand "references" :( .

     

    If someone could help me find a solution, I'd be really grateful.

     

    Below: first, a few CSS classes I created so that I could either have the label and the input on the same line (as on the screen shot above), or the input below the label.

    Then, my attempt at rewriting the function.

    Then the form.

     

    ###############

    # CSS classes #

    ###############

    form label.left, form span.left {

    position: absolute;

    width: 8em;

    font-size: 1em;

    text-align: right;

    }

    form input.margin_left, form textarea.margin_left {

    margin-left: 8.7em;

    text-align: left;

    }

    form label.above, form input.below, form textarea.below, form span.above {

    display: block;

    }

     

    #######################

    # The function itself #

    #######################

    function create_form_input2($name, $type, $size_rows, $maxlength_cols, 
    $label_class, &$label_text, $input_class, $errors, $span_class='') {
      $value = false;
    
      if (isset($_POST[$name])) $value = $_POST[$name];
    
      // Label text based on $name.
      $label_text = ucwords(str_replace('_', ' ', $name));
    
      if ($value && get_magic_quotes_gpc()) $value = stripslashes($value);
    
      // Check the input type.
      if (($type == 'text') || ($type == 'password')) {
         // Create the input.
         echo '<p><label class="'.$label_class.'" for="'.$name.'">
         '.$label_text.'</label>';
         echo '<input type="'.$type.'" name="'.$name.'" id="'.$name.'" 
         size="'.$size_rows.'" maxlength="'.$maxlength_cols.'" ';
    
         // Add the input's value, if applicable.
         if ($value) echo 'value="'.htmlspecialchars($value).'"';
    
         echo ' class="'.$input_class;
    
         // Check for an error.
         if (array_key_exists($name, $errors)) {
            echo ' error" /> <span class="error '.$span_class.'">'
            .$errors[$name].'</span></p>';
         }
         else {
            echo '" /></p>';
         }
      }
      // Check if the input type is a textarea.
      elseif ($type == 'textarea') {
         echo '<p><label class="'.$label_class.'" for="'.$name.'">'
         .$label_text.'</label>';
    
         // Display the error first, so that it's more obvious.
         if (array_key_exists($name, $errors)) echo '<br />
         <span class="error '.$span_class.'">'.$errors[$name].'</span>';
    
         // Create the textarea.
         echo '<textarea name="'.$name.'" id="'.$name.'" rows="'.$size_rows.'" 
         cols="'.$maxlength_cols.'" class="'.$input_class;
    
         // Add the 'error' class, if applicable.
         if (array_key_exists($name, $errors)) {
            echo ' error">';
         } else {
            echo '">';
         }
    
         // Add the value to the textarea.
         if ($value) echo $value;
         echo '<textarea></p>';
      } // End of primary IF-ELSE.
    } // End of the create_form_input() function.

     

    ########

    # Form #

    ########

     

    <form method="post" action="" accept-charset="utf-8">

    <?php

    $erreurs = array ('first_name' => 'Please enter your first name.', 'last_name' => 'Please enter your last name.', 'comment' => 'Please enter your comment.');

     

    // The first three function calls work and produce the screen shot above.

    create_form_input2('first_name', 'text', '30', '30', 'left',

    $label_text, 'margin_left', $erreurs);

    create_form_input2('last_name', 'text', '30', '30', 'left',

    $label_text, 'margin_left', $erreurs);

    create_form_input2('comment', 'textarea', '10', '70', 'left',

    $label_text, 'margin_left', $erreurs, 'left');

     

    // This is what triggers an error message:

    create_form_input2('first_name', 'text', '30', '30', 'above',

    'Prénom', 'below', $erreurs);

    create_form_input2('last_name', 'text', '30', '30', 'above', 'Nom', 'below', $erreurs);

    create_form_input2('comment', 'textarea', '10', '70', 'above', 'Échos', 'below', $erreurs, 'above');

    ?>

    <input type="submit" name="submit" value="Submit!" class="formbutton clear" />

    </form>

     

    With thanks for your help,

  14. If I understand your question, you'd like to base a classified ads website on the code used by Larry for his forum examples? If you can find a copy of Larry's book at the library, either the 3rd or the 4th edition, it will indeed help you create all the functionality you describe. But, if you are new to PHP and MySQL (or any other database system), be prepared to read the book and learn from chapter 1. Without any previous knowledge, you can't start directly with chapter 15 ("Example–Message Board") from the 3rd edition, for instance, or at least it's not the easiest way of learning all that's needed to create such a website.

    • Upvote 1
  15. If you use UTF-8 in your database and in your php files, you should also have a look at the multibyte functions. For instance, if you want to make a string uppercase, you shouldn't use the strtoupper function, but the mb_strtoupper function instead. Test this, and you'll see why!

     

    <!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="fr" lang="fr">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Set locale</title>
    <link rel="stylesheet" href="includes/styles_tests.css" type="text/css" media="all" />
    </head>
    <body>
    
    <?php
    $str = 'J\'ai reçu de très bons échos à la sortie.';
    $str = strtoupper($str);
    echo '<h3>Using strtoupper</h3>
    <p><code>'.$str.'</code></p>';
    
    date_default_timezone_set('Europe/Paris');
    setlocale(LC_ALL, 'fr_FR.UTF-8');
    $str = 'J\'ai reçu de très bons échos à la sortie.';
    $str = mb_strtoupper($str, "utf-8");
    echo '<h3>Using mb_strtoupper</h3>
    <p><code>'.$str.'</code></p>';
    ?>
    </body>
    </html>

     

    I hope this helps,

    • Upvote 1
×
×
  • Create New...