Jump to content
Larry Ullman's Book Forums

zanimation

Members
  • Content Count

    13
  • Joined

  • Last visited

  • Days Won

    1

zanimation last won the day on February 14 2012

zanimation had the most liked content!

Community Reputation

2 Neutral

About zanimation

  • Rank
    Newbie
  1. Hi Larry, I am actually using PDO, but was having trouble as to where to actually put/call the connection object in my classes. Now I think I have a better idea on what to do, I've got to factor out reading/writing into separate classes (I also want to support XML format, with possibilities for more formats down the road). If I can get a working application up, I might post it for CC.
  2. Hey Edward, I'm kind of in the same situation as you are, trying to get a grip on how to implement OOP in a web context. I'm trying to build a quizzing application using OOP but already having a tough time on where to put the database functionality, so I'm going to attempt to write factory classes. I've just finished viewing the first lecture video in an open Harvard software engineering course, and it looks promising as a supplementary material. Even though it's titled 'mobile' software engineering, they will be going over web development, MVC, frameworks, and all of that. Have a look.
  3. Ok, It turns out that only one underlying table in a view gets affected when performing inserts / updates. To get around this, I tried writing a trigger for the view which auto-inserts into the subtype table, but it also turns out MySQL doesn't support triggers on views. So not sure... I think my only choice would be to use the first possible method I described, which does 2 separate queries. Even though it's a seemingly clunky solution, I think it's not so bad considering they're contained within a transaction.
  4. I have a MySQL database model where I have different types of users, each having common field names, like 'username', 'password', 'first_name', 'last_name', etc. etc. I've designed it so that these common fields are stored in a 'base' table called 'users' and specific fields that apply to each type of user are stored in derived 'sub-tables' for each type of user. Here is what it looks like: I know that this is a better design than having the 'common' fields stored in every 'user' table. The problem I'm having is I'm trying to figure out how I'm going insert a new user. What
  5. Hmm... I haven't read the book, but it seems like what the script was trying to do was to ensure that the user knows the current password in order to enter in a new password, otherwise he/she cannot enter a new password. By removing the second part of the AND clause, you are completely bypassing that validation, so you'll definitely want to leave it in. Instead, let's try to figure out why SHA1 did not work. There are a few reasons why it's not working: Check that the column name 'pass' is consistent in the script and in the database If column names are consistent, check if
  6. Hmm... Not sure if I see anything right away that would cause it not to select. Try this: Right after you echo 'step3', put this: echo mysqli_errno($dbc) . '<br />'; echo mysqli_error($dbc); It will return a mysqli error code and string which should provide more information.
  7. The quotes for your query seem all messed up and mismatched. You also don't need to concatenate anything. Here it is fixed: $query = "INSERT INTO poem_orders (firstname, lastname, email, selectpoemtype, keynames, specificwords, poemisfor, relationship, occasion, overallmessage, anythingelse) VALUES ('$first_name', '$last_name', '$email', '$select_poem_type' '$key_names', '$specific_words', '$poem_is_for', '$relationship', '$occasion', '$over_all_message', '$anything_else')"; It seems you are also not executing your query. You are defining your query, but I see nothing that execut
  8. $dbc = mysqli_connect('localhost', 'login', 'password', 'database'); " . or die('Error connecting to MySQL server.'); It seems you've left the ;" . after mysqli_connect() which is causing your whole sql definition to mess up. Take out the semicolon, quotation, and the period and see if it works: $dbc = mysqli_connect('localhost', 'login', 'password', 'database') or die('Error connecting to MySQL server.');
  9. The question is very vague. I think Larry covers it in his book. If anything, just Google something like 'php login using prepared statements'. Here's basically how I use prepared statements to handle logins (simplified and using the PDO interface): <?php // include connection functions (houses the 'dbConnect()' function) require_once(PATH_TO_INCLUDES_FOLDER . 'connection_inc.php'); if(isset($_POST['login'])) { // connect to database on the read-only account and create a PDO connection object $conn = dbConnect('read'); // define the sq
  10. Since != is a comparison operator(not an assignment operator), you'll want to change: $emphasise != $emphasise; to $emphasise = !$emphasise; Also, here's an alternate modified version of Stuart's code which avoids the need for conditional checks and an extra variable: $string = 'the quick brown fox jumps over the lazy dog'; $words = explode(' ', $string); for($i = 1; $i < count($words); $i += 2) { $words[$i] = '<strong>' . $words[$i] . '</strong>'; } echo implode(' ', $words); If you're going to be using it frequently through
  11. The example script in the book includes the header on the bottom line but it's just a mistake... you'll need to change it to <?php include('templates/footer.html'); ?> (it makes more sense).
  12. Looking at the PHP manual for the mysqli functions: http://us.php.net/manual/en/mysqli.query.php and http://us.php.net/manual/en/mysqli.select-db.php Try reversing the position of the function arguments: $dbc and 'string' e.g. mysqli_select_db($dbc, 'myblog') mysqli_query($dbc, 'CREATE DATABASE myblog') See if that works. Zane
  13. While practicing some of the 'pursue' instructions for ch. 9(p. 256), I think there's an error: Rewrite customize.php so that the script also applies the user's preferences. Hint: You need to take into account the fact that the cookies aren't available immediately after they've been set. Instead, you would write the CSS code using the $_GET values after the form has been submitted, the $_COOKIE values upon first arriving at the page (if the cookies exit), and the default values otherwise. I believe it's supposed to be $_POST, not $_GET. And btw, I'm thoroughly enjoying your book
×
×
  • Create New...