Jump to content
Larry Ullman's Book Forums

Paul Swanson

Members
  • Posts

    163
  • Joined

  • Last visited

  • Days Won

    19

Everything posted by Paul Swanson

  1. Try: mysql -u larry -p The host name is optional. Are you getting prompted for the password? And what is the full error? MySQL generally tries to tell you approximately where in your statement it is detecting an error.
  2. You can deal with "headers already sent" by using output buffering. I don't have the 3rd Edition, but in the 2nd Edition there is a section devoted to output buffering in Chapter 11. Check the index of your book and you should find it. As for your fatal error, it looks like you have your error handler function in an included file (configr.inc.php), but you are re-declaring it in the script displaying the error, or maybe it is in another include file. Basically, the error message is stating that you can't have two functions with the same name, even if it is the same function.
  3. I think the easiest method would be to use <span title="your definition text here">word</span>. No need for javascript, you could do the whole thing in PHP with queries from the database for the words and its related definition. The title attribute will display as a "tool tip" when your cursor is over the <span>. You can't style the popup, though.
  4. Another approach would be to run the textarea input values through htmlentities(). There are options for handling quotes, and you might want to consider specifying the ENT_QUOTES flag to convert both single and double quotes to their respective HTML entity. htmlentities() also converts < and > to < and &gt: which will prevent someone from entering javascript or other code. If you view the source on this page, you'll see that is what the forum software does. Keep in mind, though, that if you want your users to be able to mark some text as bold, italic, etc. they will not be able to do so unless you use a rich text editor widget, such as Tiny_MCE. Also, there is a function to reverse the conversion: html_entity_decode() that will revert the entities to the original characters, should you need to do so. Finally, htmlspecialchars() does an entity conversion, but on a smaller subset of characters. You might find that to be sufficient for your needs. There is a decode function for that, too. See the manual pages I've provided links to for documentation. I would still run the entire converted string through mysqli_real_escape_string, just as an extra precaution.
  5. If you go to the Database Extensions page in the PHP Manual, you'll find the Mysqli extensions are the next item down from MySQL.The Mysqli functions are listed by the OOP syntax, but if you view the OOP page you'll also get the procedural syntax. But personally, I usually just type the function name in the 'search for' box at the top of the page.
  6. You'll have to use concatenation to use PHP functions within a string echoed by PHP: <?php echo '<form action="" method="post"> <p>Lastname:<input type="text" name="last_name" size="20" maxlength="20" value="' . (isset ($_POST['last_name']) ? $_POST['last_name'] : '') . '" /></p>'; ?>
  7. When Larry wrote the book, a release of PHP6 was planned, with the major feature being Unicode support. But it was taking so long to get Unicode support implemented, that a decision was made (after the book was released) to make the changes into a branch, rather than a full version. So this book's title has turned into Larry's "Dewey Defeats Truman" error.
  8. Paul, have you checked your Spam folder? Maybe nothing is wrong with Mercury Mail or your code, your email service may be intercepting the message because the domain name isn't real.
  9. Upgrade to Firefox 5, it allows you to resize textarea fields after the browser has rendered them.
  10. Yes, those would produce different results. Functions use the arguments passed to them in the same order as the function definition, not by the names. The names are for the benefit of us poor humans, so we can more easily understand what the variable is supposed to represent. Say you have a function that takes 3 arguments, and prints a sentence from them: function make_sentence($word1, $word2, $word3) { echo "Hey $word1, compare $word2 to $word3 and let me know what you think."; } You can call this function and submit 3 strings for the variables: make_sentence('Fred', 'paper', 'pencil'); // Hey Fred, compare paper to pencil and let me know what you think. In the function, the first argument passed to it will be assigned to $word1 because that is the first argument in the function definition. It doesn't matter what name is given to the argument. Consider this: $word1 = 'Fred'; $word2 = 'paper'; $word3 = 'pencil'; make_sentence($word1, $word2, $word3); // same output as example 2 make_sentence($word2, $word3, $word1); // Hey paper, compare pencil to Fred and let me know what you think. I hope that helps clarify it for you.
  11. Use PHP to write the javascript, just like any other text. This example uses the heredoc syntax. <?php echo <<<EOT <script type="text/javascript"> data:[$value1, $value2, $value3]; </script> EOT; ?> Or, you could embed PHP tags within javascript: <script type="text/javascript"> data:[<?php echo $value1 . ',' . $value2 . ',' . $value3; ?>]; </script> It's easier to use PHP variables with javascript than it is to use javascript variables with PHP. For that you would write the javascript variable to a cookie, then use PHP to read the cookie.
  12. I agree with HartleySan's contention that it's best to separate HTML and JS. In practice, I use a separate file for most JS and use function calls for events. I felt it would be clearer to the original poster by mixing them in my example. Glad it's working for you, chop.
  13. DATEDIFF() looks to be what you want. It returns the number of days between two dates. Divide by 7 to get the number of weeks, and use PHP's modulus operator (%) to get the remainder for calculating the extra days.
  14. This is a business account. <input type="radio" name="acct_type" value="business" onclick="javascript:document.getElementById('demo').style.display='block';" /> This is a personal account. <input type="radio" name="acct_type" value="personal" onclick="javascript:document.getElementById('demo').style.display='none';" /> <div id="demo" style="display:none;">Street Address: <input name="wk_addr" type="text" /><br /> City: <input name="city" type="text" /> State: <input name="state" type="text" /> </div> I believe that should work for you. Alternately, you could toggle the visibility property between hidden and visible, but that method leaves the space the div would take up even when it's hidden. Using display:none removes the space the div would take up.
  15. What I do for something like this is create the text fields for the business information in a <div> with a CSS style of display:none, When they click the radio button that indicates it is a business account, use javascript to change the display style to 'block.' This will show the fields in the browser. If they click the other button, set the display to 'none.' For validation, you can just use PHP to check which button was selected, and validate the business info fields if they selected business account, but do nothing if they selected personal account.
  16. I think you may have more than a single issue on this. The error message is indicating the problem is happening before your values, it's actually with the field names. I suspect the culprit is drop, which is a command in SQL. Try wrapping that field name in back-ticks (it's the character that shares the tilde (~) key). Your SELECT query should only return one row, since you shouldn't be allowing duplicate user_id's, so there is no need for a while loop. And I would check for the number of rows before attempting to fetch it. $q = "SELECT user_id FROM dsf_users WHERE email='$e'"; $r = mysqli_query ($dbc, $q) OR trigger_error ("Query: $q\n<br />MySQL Error: " . mysql_error ($dbc)); if (mysqli_num_rows ($r) == 1) { $dsf_user = mysqli_fetch_array ($r, MYSQLI_ASSOC); // note the variable name is singular now, only going to be one user if ($_SESSION['quote_type'] == 'curtains') { $q = "INSERT INTO curtains (user_id, `drop`, track_pole, track_pole_width, heading_tape, lining, fullness, interlined, fabric_width, current_status, curtain_total_cost, curtain_quote_date) VALUES ({$dsf_user['user_id']}, {$_SESSION['drop'}, '{$_SESSION['track_pole']}', {$_SESSION['track_pole_width']},'{$_SESSION['heading_tape']}', '{$_SESSION['lining']}', {$_SESSION['fullness']}, '{$_SESSION['interlined']}', {$_SESSION['fabric_width'}, 'quote', {$_SESSION['curtain_total_cost']}, NOW())"; $r = mysqli_query ($dbc, $q) OR trigger_error ("Query: $q\n<br />MySQL Error: " . mysql_error ($dbc)); } else { echo 'it worked for blinds'; } } I've placed single quotes around some of the values, since in the error message those values appear to be strings. I think the while loop was messing you up with the user_id, as it would move to the next pointer in the array fetched by MySQL, but that row wouldn't have any values as the query would only return one row.
  17. I use Netbeans 7.0 for Windows. Like Antonio says, use File > Save As. I could browse to any folder on my system.
  18. You could add an onFocus() event to set the <span> text to an empty string when the user clicks or tabs into the field. That should clear the 'directory name unavailable' message. Assuming your input field is named 'directory_name_label': function clear_directoryname() { // clear directory name response field document.getElementById('directory_name_label').innerHTML = ''; } In the form field <input> element, add: onfocus="clear_directoryname()"
  19. Nothing jumps out as looking wrong. Right after you run the query, add this: echo '<p>MySQL Error: ' . mysql_error() . '</p>'; Does MySQL report any errors?
  20. You might consider running anything you insert as text in the database through htmlentities(). It should convert à to à ; Then be sure to use htmlentities() on any text you are searching for, and it should search for the entity code instead of the character. I haven't tried it, but unless the semi-colon causes a problem, it seems like it should work. And you should be able to print the converted text directly in the browser and have it display the character. If you need to you can convert it back by using html_entity_decode().
  21. Maybe you could borrow a Windows PC? You must know someone who has a PC that they don't use anymore. It doesn't have to be very powerful. Anything with Windows XP should work.
  22. Is the problem that you receive error messages when the page loads, or is the field just not sticky? It looks like what you have would correctly make the field sticky, but you should be seeing 'undefined variable' messages when the page loads because the $_POST variables won't exist until the form is submitted. Try this: <select name="font_size"> <option value="">Font Size</option> <option value="xx-small" <?php if (isset ($_POST['font_size']) && $_POST['font_size']=="xx-small") {print "selected=selected";} ?> >XX-Small</option> <option value="x-small" <?php if (isset ($_POST['font_size']) && $_POST['font_size']=="x-small") {print "selected=selected";} ?> >X-Small</option> </select> The code now looks to see if the $_POST['font_size'] variable exists before trying the comparison, so you shouldn't see any "undefined variable 'font_size'" messages.
  23. I think it will always report just one row affected because you are only inserting one row in the loop. You can count the total number of rows added by initializing a counter variable before you enter the while loop, and increment it by adding the results of mysqli_affected_rows() during each loop iteration. Then check the value of your counter variable after the while loop completes: $affectedRows = 0; while ($genres_entree = mysqli_fetch_array($result2, MYSQLI_NUM)) { $query5 = "INSERT INTO referents_genders (id_referent, id_gramm_gender) VALUES ($id_referent, $genres_entree[0])"; $result5 = @mysqli_query($bdd, $query5); $affectedRows += mysqli_affected_rows($bdd); } echo $affectedRows; // should be the total number of rows added
×
×
  • Create New...