Paul Swanson
Members-
Posts
163 -
Joined
-
Last visited
-
Days Won
19
Everything posted by Paul Swanson
-
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.
-
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.
-
Pursue Chapter 12 (#4)
Paul Swanson replied to Lynae's topic in PHP for the Web: Visual QuickStart Guide (4th Edition)
You're welcome. With some fonts it's tough to tell a lower-case L from a one from a capital i. -
Pursue Chapter 12 (#4)
Paul Swanson replied to Lynae's topic in PHP for the Web: Visual QuickStart Guide (4th Edition)
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... -
What Text Editor Do You Use?
Paul Swanson replied to phpRob's topic in PHP for the Web: Visual QuickStart Guide (4th Edition)
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. -
Format Year
Paul Swanson replied to BHB's topic in PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
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? -
Best Free Text Editor
Paul Swanson replied to Silver's topic in Effortless E-Commerce with PHP and MySQL
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. -
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?
-
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?
-
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";
-
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.
-
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?
-
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.
-
Shop.Php Problem - Chapter 8
Paul Swanson replied to Ryan R's topic in Effortless E-Commerce with PHP and MySQL
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. -
Mysql Monitor (Odbc@Localhost)
Paul Swanson replied to Lou's topic in MySQL: Visual QuickStart Guide (2nd Edition)
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. -
Mysql Monitor (Odbc@Localhost)
Paul Swanson replied to Lou's topic in MySQL: Visual QuickStart Guide (2nd Edition)
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).