Jump to content
Larry Ullman's Book Forums

markifornia

Members
  • Posts

    112
  • Joined

  • Last visited

Everything posted by markifornia

  1. Thank you Bahaa I will use this method. Is this the most common way? Do you have a snippet of code sample, it doesn't have to be elegant. I just wanted to get an idea of how it is done. Thanks, Mark
  2. Thanks bahaa, what is assiged to $sdbc? Is it the below: mysqli_query($dbc, $q); Also, is the function missing another parameter of $ID? function uniqueEmail($email) Very useful functions, I've never created functions with query statements, I like this idea. It's awesome.
  3. Thanks for all your responses. To both Jonathan and Antonio, thanks for presenting the script in different ways. It helped me understand what was really going on behind the scenes. I could not understand it at first, I was also unsure about the way I comprehended it. But to reiterate (directed at Antionio's explanation): In it's most simplest form: The variable takes on a new value each time it is passed through the ternary operator, correct? Either way, I believe this is how I think it works. It makes sense. @bahaa - Your suggestion also a worth considering in future projects. This method will be most widely used once CSS3 is most widely supported by all the browsers.
  4. As noted on page 283: (condition) ? value T : value F. Will return a value after being evaluated based on the condition. line 61: $bg = '#eeeeee'; // Set the initial background color. line 63 - 65: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color echo '<tr bgcolor="' . $bg . '"> .... } Firstly: I don't understand how the $bg variable is defined twice, yet $bg will still hold the value #eeeeee. Consider the following: $var = 'Hello'; $var = 'World'; Wouldn't the new value now be 'World' not 'Hello' ? Secondly, It says "For the first row, $bg is equal to #eeeeee. For the second row, $bg is not equal to #eeeeee." How can the second row not be equal to #eeeeee, when $bg's initial value is #eeeeee. Based on the ternary operator, $bg does equal #eeeeee, therefore the condition is true, thus the second row would also be #ffffff. The result is that every row would be #ffffff, because $bg = #eeeeee. Thanks, Mark
  5. Thanks Larry. Here is a very simplified example for form.html for the form markup, handler.php as the handler. form.html <form action="edit.php" method="post"> <tr> <td>Name: <input type="text" name="name" value=""></td> </tr> <tr> <td>Address: <input type="text" name="address" value=""></td> </tr> <tr> <td><input type="submit" name="submit" value="submit"></td> </tr> </form> _____________ handler.php $name = $_POST['name']'; $address = $_POST['address']; $n = "INSERT INTO users (user_id, name) VALUES ('$name'); // users table $a = "INSERT INTO address (user_id, address) VALUES ('$address')"; // address table I just realized my question now is, how to insert data into multiple tables for one unique user id? Put simple, which user (for instance in an admin environment) user added a record. Would I use the session id? I understand there are two methods: (1) using a hidden field (2) passing the values to the URL using $_GET. Thanks, Mark
  6. I have just finished Chapter 9, to get a feel for were I'm at in my reading. Chapter 6 (Advanced SQL and MySQL) does an excellent job of explaining database design and relating tables through primary and foreign keys. I understand how to SELECT columns from multiple tables using table JOINS. Ok, my question is: How do you INSERT data across multiple tables? When working with forms, should forms correspond to one table at a time? Say the form has name, email fields that corresponds to the users table. And then the same form also has address fields that correspond to the location table. I might of been getting ahead of myself here as Chapter 11 explains how to track users through sessions, I have skimmed the chapter a little as I've become very curious. I don't know to much about sessions at this point. Is sessions the practical most widely used method for accomplishing this? Thanks, Mark
  7. Has Larry Ullman written any books on building this kind of web application? If so, please suggest. If not, it would be awesome if Larry put one together. This may not be a popular request, nor am I aware that it's okay to request such a thing. Nonetheless, I would be stoked if even one of them was in bookstores. -Mark
  8. What an interesting query, it took a while to get my head around it. I could almost write up so many different versions of how it could be explained, at least for myself. Nonetheless, you've explained it clearly, thanks Paul! ... Line 60 if (mysql_affect_rows($r) == 0 ) { // The query did not find another email that matches the current users email address // UPDATE query } else { // The query found another email address in the database that matches the current users email address // already registered }
  9. I didn't even know the comparison can take a negative value such as -1. This is the solution I was looking for. } elseif (mysqli_affected_rows ($dbc) == -1) { // update query failed Thanks Paul!
  10. On page 274, it explains why the query is written this way, the reason below: "To write one query that will work for both possibilities, don't check to see if the email address is being used, but rather see if it's being used by anyone else..." On Line 53: $q = "SELECT user_id FROM users WHERE email='$e' and user_id != $id"; I don't see how this code is checking to see if being used by anyone else, I'm confused with this query. Is there an easier way this could be explained or elaborated more for better comprehension? Thanks, Mark
  11. Thanks Larry, I got to chapter 9 on page 274 there is a suggestion to change the error message to indicate that no alterations where made if mysqli_affected_rows() returns 0. Can't I just say their password has been updated even though behind the scenes it technically didn't?
  12. This question pertains to Chapter 8: Script 8.7, Line 55 if(mysqli_affected_rows($dbc) == 1) { // If it ran OK Then at the end of the chapter in TIPS, it says: "If an UPDATE query runs but does not actually change the value of any column (for example, a password is replaced with the same password), mysqli_affected_rows() will return 0." OK, I fully understand this. But... How do we modify the code so that if a user accidentally puts in the same data for each field, it outputs another message instead of outputting a SYSTEM ERROR? I'm going chapter by chapter so I don't know if this is addressed in later chapters, if anyone could advise some sort of direction, even loose logic, I can take a stab at it. My idea would be to create a new else statement: $q = "SELECT pass FROM users WHERE pass = '$np'"; $r = @mysqli_query($dbc, $q); while($row = mysqli_fetch_array($r, MYSQLI_ASSOC) { if ($row['pass'] == $np) { If the current password and the new password match, then echo something // echo something } } I could be off here, so any advise appreciated. thanks
×
×
  • Create New...