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 changing the function to this: function validate_text_input($input_name, $err_msg) { global $dbc; global $errors; if (empty($input_name)) { // you're not using $_POST[$input_name] as an argument, just $input_name $errors[] = $err_msg; } else { if (get_magic_quotes_gpc()) { $input_name = mysqli_real_escape_string($dbc, stripslashes(trim($input_name))); } else { $input_name = mysqli_real_escape_string($dbc, trim($input_name)); } return $input_name; } } And call the function like this: $postTitle = validate_text_input($_POST['post_title'], 'Please enter a title for your post.'); $postSubtitle = validate_text_input($_POST['post_subtitle'], 'Please enter a subtitle for the blog post.'); $postBody = validate_text_input($_POST['post_body'], 'Please enter the body of the blog post.'); You want to pass the $_POST variables when you call the function, but the function itself will use the name of the argument in the function definition, and you'll want to assign the return values to a variable that you can use for the form output if $errors is empty.
  2. Since you are dynamically setting the id in PHP, you'll probably have to use a class selector in your CSS and set a class attribute on the text area, instead of using an id selector: .textArea600x400 { width: 600px; height: 400px; } Then add class="textArea600x400" as an attribute of the text area you want to size.
  3. You're welcome. With some fonts it's tough to tell a lower-case L from a one from a capital i.
  4. You have the function name wrong; it should be nl2br(), not n12br(). That's a lower-case L, not the digit one. Read it as "nEW lINE to brEAK" Typography can mess you up sometimes...
  5. Hi Max, Open httpd.conf in \XAMPP\apache\conf and look at both ServerRoot (defaults to C:/xampp/apache) and DocumentRoot (defaults to C:/xampp/htdocs) and make sure they point to the correct locations. You might only have to change the drive letter. Then restart Apache and see if that fixes it.
  6. I use SciTE as a text editor, but do most of my work in NetBeans IDE. Both are free and include brace matching and syntax highlighting. And both support multiple programming languages.
  7. I'm unclear on how your date is stored in the database. Is the value stored in year_complete 1997, or 1997-11-03? If it's just 1997 you don't need to perform any date formats. If it's a full date, you can extract just the year portion by using YEAR(p.year_complete). It also looks like you are storing the year in an array in PHP. For debugging, print out the contents of the array to see if it holds what you expect it to: echo "<pre>\n"; print_r ($year); echo "</pre>\n"; What does that output look like?
  8. Are you accessing the page using an URL? If you just open the file, or launch it by clicking on it, it won't be run through the server. You must access it by entering '//localhost/path/to/your/file' in order for it to work properly.
  9. Try applying the overflow:hidden style to your table cell to counteract the bleeding.
  10. I've been using NetBeans for some time. Yes, it is free. If you are looking for something more lightweight to compare to Notepad++, check out SciTE.
  11. In addition to the excellent advise from HartleySan, there is a problem with how you are referencing the file after making your query: Notice that you fetch the results of your query into $rowi but you are referencing $row (no i) for $imageid and $imagename. That's not going to work...
  12. When you run it locally, do you type http://localhost/form.html to open the form? You should be. If you just double-click the file it does not run through the webserver, which is required for PHP to work properly.
  13. Something seems wrong with your PHP, you should not be seeing variable names with the code you provided. It doesn't seem to recognize HTTP headers (no $_POST or $_REQUEST variables). Add this to handle_form.php, either above or below where you added the code that prints the contents of $_REQUEST and $_POST: echo php_sapi_name () . "<br />"; What does that produce?
  14. Craig, sorry that didn't work for you. I wasn't sure if it would ... I've never used HAVING before. In fact, I had never heard of it until I researched your problem.
  15. Do you have phpMyAdmin? Does it run? If so, when it loads select the mysql database, then browse the users table. Use the Insert link at the top of the page and add a new user/password, and be sure to give it some rights. Then try to connect using the new user in your connection script. Getting any closer?
  16. This looks exactly like your issue. Try using HAVING instead of WHERE. It may only work in conjunction with GROUP BY clauses. Try this: $q = "SELECT postcode, ROUND(DEGREES(ACOS(SIN(RADIANS($lat)) * SIN(RADIANS(latitude)) + COS(RADIANS($lat)) * COS(RADIANS(latitude)) * COS(RADIANS($long - longitude)))) * 69.09, 2) AS distance FROM uk_postcodes ORDER BY distance ASC GROUP BY distance HAVING distance <= 1 LIMIT 100";
  17. Try copying the php.ini file from C:\xampp\php to C:\Windows, then stop and restart Apache.
  18. Interesting. Your code works for me (there are a few minor issues, which I'll let you try to figure out when you have it working). Let's see what you are getting, if anything, from $_REQUEST. In the handle_form.php file, add this just before your comment about creating shorthand: echo "<pre>\n"; print_r ($_REQUEST); // prints the content of $_REQUEST array print_r ($_POST); // prints the content of $_POST array echo "</pre>\n"; That should tell us what is held in those arrays, and maybe we can figure out why they aren't being read by the handle_form.php script.
  19. What version of PHP are you using? If it is less than 4.1 you can't use $_REQUEST as it was added in that version. This is why Larry insists people furnish the versions they are using when asking for help. It's vital information. Even if your version is 4.1 or later, try changing all instances of $_REQUEST to $_POST. Does it work then?
  20. If htmlentities() was used to convert the text entered, pass the text through html_entity_decode() before printing. If htmlspecialchars() was used, then use htmlspecialchars_decode().You may have to break up the text to preserve the ones you want to retain as entities. Edit: Oh wait, I just re-read your post and you're wanting to preserve some of the <, not convert them. I think you are still going to need to break up the text somehow. Then you can convert some entities, but not others. Might be tough to figure out where to break up the text, though. Is there any way you could tag the entities to preserve prior to inserting it into the database? Maybe use ~lt; and ~gt; instead of < and >? Then you could do a string replacement before printing. htmlspecialchars_decode() should be faster than html_entity_decode(), since it works on a smaller subset of entities.
  21. If you are going through these exercises just to learn, you might consider installing XAMPP on your computer. You could set up a user with EXECUTE privileges without changing hosting.
  22. The error messages indicate PHP cannot find the mysqli_connect.php file. Where is the file actually located? PHP is looking in the php folder (the ../ in the path means PHP would look in the parent folder of the current folder, ch08).
  23. Sorry I didn't reply earlier. I had a busy weekend. To start MySQL with any user you need to be at a command line in the folder where the MySQL executable resides (on my Windows XP computer with WAMP installed, it is at C:\Program Files\wamp\mysql\bin). You then just enter the command the way you have been trying: mysql -u username -p You should then get prompted to enter the password. Once you've logged in, your prompt should change to: mysql> And at that point you can enter SQL. You should start by selecting the database with: USE databaseName; Now you can enter queries at the command line.
  24. I don't think you can change the user with an SQL query, you have to start the client as a particular user. mysql -u larry -p isn't SQL, it's a command followed by arguments that are passed to the client application. If you want to start the client as a different user, you need to use Start > Run > cmd and then sign in. In PHP (or ASP, etc.) you will use functions to connect to the database as a specific user, passing the username, password, hostname and database name. You don't access the client the same way as you would if you were running it from a command line. I have the first edition of the book, and chapters 6, 7 and 8 describe how to connect using different scripting languages. I think you are making this harder than it is. To do admin stuff, I always use phpMyAdmin locally, or I use the Linux command line to start the client on our server (because we don't have phpMyAdmin installed there).
×
×
  • Create New...