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. Ahh, that makes sense. I use the Netbeans IDE, too, and really like it except for the Code Hints always popping up too soon and getting in my way. Nate, has that been an issue for you? Maybe something is messed up in my configuration.
  2. Are you sure you posted this in the right forum? I just scanned Chapter 6 for PHP and MySQL 4th Edition and there are no PHP scripts in chapter 6 ... it's all about MySQL.
  3. Paul, you are getting the undefined variable SESSION because you are using $SESSION and it should be $_SESSION. You gotta have that _ in there between the $ and SESSION.
  4. Is it possible the <?php tag is within a heredoc block? It would be considered regular text/html then.
  5. That countdown timer is really cool! I would think you could tackle your first issue by retrieving the individual parts of the date from the database, then using them to construct the Date object in JS. Use the MySQL date functions YEAR(), MONTH(), DAYOFMONTH(), HOUR() and MINUTE() on your date field. Sorry, I have no idea on the second issue. Go Portland Timbers FC!
  6. Is there a blank line or space at the beginning of index.php? A byte-order-mark (BOM)?
  7. Found this JS function via a Google search: http://www.softcomplex.com/forum/viewthread_2814/ Looks like it should work for you.
  8. It is probably best to have output_buffering turned off in php.ini. You can invoke output buffering whenever you need to by including the PHP Output Control Functions that are available. For your second script, here is a snippet from some code that I use (slightly modified): $location = $_SERVER['DOCUMENT_ROOT'] . '/pdf/myFile.pdf'; $filename = 'myFile.pdf'; $filesize = filesize ($_SERVER['DOCUMENT_ROOT'] . '/pdf/myFile.pdf'); // download file header ("Content-Type: application/pdf"); header ("Content-Disposition: attachment; filename=\"$filename\""); header ("Content-Length: $filesize"); header ("Content-Transfer-Encoding: binary"); readfile ($location); A couple of things to note: I use the superglobal $_SERVER['DOCUMENT_ROOT'] instead of typing the path to the document root, since my development environment is wildly different than my server environment in terms of the location of the document root. The script will work in both environments without modification. I use the filesize() function to get the file size so I don't have to check it every time. I'm letting the browser know that it's a binary file by using header ("Content-Transfer-Encoding: binary"). The example code you provided didn't include this, but maybe you had it and didn't include it. readfile() is needed to send the file. Again, maybe your example wasn't the full code you used. Hope this helps!
  9. From the PHP Manual: So you could do something like: if (mysqli_affected_rows ($dbc) == 1) { // If it ran OK echo "Password Updated"; } elseif (mysqli_affected_rows ($dbc) === 0) { // use three equal signs so there is no confusion with a false return echo "Password unchanged because it was the same as on record"; } elseif (mysqli_affected_rows ($dbc) == -1) { // update query failed echo "Oopsie! System error."; }
  10. That query will SELECT a user_id if the email address is found in the users table only if the user_id NOT (!=) the same as the current user. So if a dataset is returned, it would indicate that another user_id is already using that email address.
  11. Welcome to the forum, CambridgeK! In regards to your first issue, it is functioning correctly. You are using the header() function to change window.location, which is the URL of the current webpage, so that is why it is redirecting. In regards to your second issue, try changing the filename part of the Content-Disposition statement to just filename=\"/NJTransit.pdf\"\n" (assuming it is located in your document root) -- I think you are giving too much of a path. I believe the browser is looking for an URL to the document, not the file system path.
  12. I'm making the assumption that your database resource link is stored in $dbc. If you use a different variable name, you'll need to change that conditional. Be sure to check the PHP Manual page on the proper use of error_code(). The example block of code should only attempt to process your PDO statements if there were no errors in your last database operation. I can't provide too much help here, since I've never used PDO myself. In fact, we have such an old version of PHP on our server, I've stuck to procedural coding, so I'm not very well versed in OOP.
  13. Xerte Online Toolkits is an eLearning authoring tool that is PHP/MySQL based. It's free and open-source.
  14. You could check for an error before running both open_session() and write_session(). if ( $dbc->errorCode() == '01' ) { // no error, proceed to open_session and write_session } else { // an error happened, use errorInfo() to get details } More info in the PHP Manual.
  15. If your header.html file were included in another .php file, it would work okay. But on it's own, the server wouldn't run it through the PHP interpreter because it doesn't have a .php extension. The server uses the extension to determine whether it needs to send it through the interpreter. So, if you had an index.php with include 'header.html'; it should work fine because the index.php file will be run through the PHP interpreter, along with any files it includes.
  16. I received my copy on Monday. Great job, Larry! It's already cleared up some misconceptions I've had, and I'm only on chapter 2! And I've noticed that Firefox (10.0.2) has much better HTML5 support than IE (9.0.8112.16421), not that that surprises me.
  17. You have to include the connection script or code on every page that uses it. That's because web pages are stateless. You either have to pass data from one page to the next, or store it on one page and retrieve it on the next.
  18. In addition to Rob's suggestion, you could use a .htaccess file in the directory housing the video to protect it from browsing. This will prevent any browser from accessing the directory (but PHP will still be able to access it): # disable directory browsing Options All -Indexes # prevent folder listing IndexIgnore * # prevent access to any file <FilesMatch "^.*$"> Order Allow,Deny Deny from all </FilesMatch>
  19. (Phew, that was a lot of scrolling to get to the reply area! ) Your error is occurring because you haven't connected to the database yet. $dbc is the database connection link, which is required parameter of mysqli_real_escape_string().
  20. One of your queries is failing. In one of your queries you address table 'user' and in the other one you address 'users' ... so one of those is looking for a table that doesn't exist. I always test to see if the query ran okay. $r will tell you: $q = "DELETE FROM user WHERE user_id=$id LIMIT 1"; $r = @mysqli_query ($dbc, $q); if (!$r) { // query failed echo "<p>Query: $q</p>\n\n<p>MySQL Error: " . mysqli_error ($dbc) . "</p>\n\n"; // or send via mail if you don't want an error visible to users } else { // query okay // do your mysqli_affected_rows() or mysqli_num_rows() statements }
  21. No, I'm not using any frameworks. And I mostly code in the procedural style and hardly ever do any OOP. Right now I'm working with JSP pages, which is new to me. I wish there were better documentation for JSP. I've been kind of spoiled by PHP's documentation. And of course, Larry hasn't written a book on JSP to de-mystify it!
  22. I think your error is actually on line 7, but PHP doesn't notice until it hits the semi-colon on line 8. I think line 7 should be: $newProject=new Project();
  23. Windows Server may not like .htaccess as a file name. I found this on Google that may help you: http://forum.mambo-foundation.org/showthread.php?t=1857 If the server is using IIS rather than Apache, you might find this article useful: http://learn.iis.net/page.aspx/557/translate-htaccess-content-to-iis-webconfig/
  24. Your first error is a file not found error. The error appears to be in index.php, and indicates that the link to your forgot password script is incorrect. Your second error, "Undefined variable: dbc" <-- this is your database connection variable, but your login.inc.php does not have your login code. You need to include your config.inc.php file before you use mysqli_real_escape_string() because it needs the database connection resource ($dbc).
  25. For testing PHP, you must use localhost as the address. This is because PHP is a running via the webserver (localhost) and if you open it as a file you are bypassing the webserver, so your browser just sees normal text rather than the parsed PHP code.
×
×
  • Create New...