Jump to content
Larry Ullman's Book Forums

victor

Members
  • Posts

    10
  • Joined

  • Last visited

victor's Achievements

Newbie

Newbie (1/14)

2

Reputation

  1. Hi Graham About removing the closing tag ?> , this what the php manual says: Thanks for your feedback, chapter 11 comming soon...(now jumping to some javascript)..
  2. Hi dean, first suggestion, run away from Godaddy's hosting:), the magic quotes directive was deprecated since PHP version 5.3.0. But, in your case, you can put the following code in a file (you can call it, "magicquotes.inc.php, "magicquotes.php", or whatever works for you, and include it in your main script: magicquotes.php code: <?php if (get_magic_quotes_gpc()) { $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); while (list($key, $val) = each($process)) { foreach ($val as $k => $v) { unset($process[$key][$k]); if (is_array($v)) { $process[$key][stripslashes($k)] = $v; $process[] = &$process[$key][stripslashes($k)]; } else { $process[$key][stripslashes($k)] = stripslashes($v); } } } unset($process); } Include it like this: <?php # Begining of your script include 'includes/magicquotes.php'; ... Or <?php # Begining of your script include $_SERVER['DOCUMENT_ROOT'] . 'includes/magicquotes.php'; ... The php closing tag ?> was left intentionally, because this is an include file. I didn't invent this code, it comes from the PHP manual. Hope that helps. Victor
  3. Pheww, seems my solutions for Chapeter 10 - Pursue points 1 to 3 are working, sharing what I have done : Chapter 10 Pursue - P1 * Solution: Modify the string to be passed when clicked on "Edit" and "Delete" from the "view_users.php" .. // from view_uses.php[/i] [i]// This code goes inside the [/i]while ($row = mysqli_fetch_array($r, MYSQL_ASSOC)){ conditional [i]// Just add the new set of variable/values to the URL[/i] [i]<td align="left"><a href="edit_user.php?id=' . $row['user_id'] . '&fn=' . $row['first_name'] . '&ln=' . $row['last_name'] . '">Edit</a></td>[/i] [i]<td align="left"><a href="delete_user.php?id=' . $row['user_id'] . '&fn=' . $row['first_name'] . '&ln=' . $row['last_name'] . '">Delete</a></td>[/i] [i] This info is passed along the url string, so these new elements are available via $_GET (or $_REQUEST), to use this info, just add a conditional at the begining of "edit_user.php" and "delete_user.php" : <?php # Script - edit_user.php // This page is for editing a user record. // This page is accessed through view_users.php. if (isset($_GET['fn']) && isset($_GET['ln'])){ $fn = $_GET['fn']; $ln = $_GET['ln']; $page_title = "Edit Info for $fn $ln"; } else { $page_title = 'Editing User Info'; } include 'includes/header.html'; .... <?php # Script - delete_user.php // This page is for deleting a user record. // This page is accessed through view_users.php. if (isset($_GET['fn']) && isset($_GET['ln'])){ $fn = $_GET['fn']; $ln = $_GET['ln']; $page_title = "About to Delete user $fn $ln"; } else { $page_title = 'Delete a User'; } ... Pursue - P2 and P3 * Solution: Add two password fields to the form, add conditionals to check if the new pass and confirmation pass match. I put the form code in a separate file called edit_form.php, and add it where the form code goes (you can coment out the form code with /* */ to keep the code in your script). Added if else conditionals for checking if the form values where submitted otherwise display the database values" edit_form.php code: <form action="../edit_user.php" method="post"> <fieldset> <div><label for="first_name">First Name: </label><input type="text" id="first_name" name="first_name" size="15" maxlength="15" value="<?php if(!empty($_POST['first_name'])) { echo $_POST['first_name']; } else { echo $row[0];} ?>" /></div> <div><label for="last_name">Last Name: </label><input type="text" id="last_name" name="last_name" size="15" maxlength="30" value="<?php if(!empty($_POST['last_name'])) { echo $_POST['last_name']; } else { echo $row[1];} ?> " /></div> <div><label for="email">Email Address: </label><input type="text" id="email" name="email" size="20" maxlength="60" value="<?php echo $row[2]; ?>" /></div> <div><label for="pass">New Password:</label><input type="password" name="pass" id="pass" size="10" maxlength="20" value="<?php if(isset($_POST['pass'])) echo $_POST['pass']; ?>"></div> <div><label for="pass1">Confirm Password:</label><input type="password" name="pass1" id="pass1" size="10" maxlength="20" value="<?php if(isset($_POST['pass1'])) echo $_POST['pass1']; ?>"></div> <div><input type="submit" name="submit" value="Submit" /></div> <input type="hidden" name="id" value="<?php echo $id; ?>" /> </fieldset> </form> Insert the form: ... // Create the form: include 'includes/edit_form.php'; ... Add the conditionals for the new password and confirmation password: ... // This code goes inside the if($_SERVER['REQUEST_MEHOD'] == 'POST') { // And ater the check for an email address conditional // Check for a new password and match // against the confirmed password: if (!empty($_POST['pass'])) { if ($_POST['pass'] != $_POST['pass1']) { $errors[] = 'Your new password did not match the confirmed password or you didn\'t enter any.'; } else { $np = mysqli_real_escape_string($dbc, trim($_POST['pass'])); } } else { $errors[] = 'You forgot to enter your new password.'; } .... And modify the query to update the password: .... // This goes inside the if (empty($errors)) { in edit_user.php script // Make the query: $q = "UPDATE users SET first_name='$fn', last_name='$ln', email='$e', pass=SHA1('$np') WHERE user_id=$id LIMIT 1"; $r = @mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. ... I'd really appreciate any correction,and excuse my writing, english is not my mother language , I hope some day I could code better than I write english hahaha Thanks!
  4. As this file will be use as an include file, you can remove the last ?> from your script
  5. This may help you: http://stackoverflow.com/questions/4448467/cant-connect-to-local-mysql-server-through-socket-var-lib-mysql-mysql-sock
  6. Larry and Antonio, thanks for the advice, much appreciated. I guess I will develop my "coding style" with time, knowlege and practice. Yes, Antonio, lots of fun and hours haha, hopefully I got a new "all-terrain" keyboard. Now I realize that the first book I read was very basic, the next books I read just added some confuse to the mix and a bit of frustration. And because of that, I started to look some new material to learn from, and I found PHP Advanced and Object-Oriented Programming in Amazon. It's really like fresh air, but for the sake of my mental health, I'm going through PHP and MySQL for Dynamic Web Sites, my ideas are getting align, and now everything looks clear. Just to say thanks Larry!
  7. Hi Antonio, my concern is to learn how to program in PHP the right way, there are tons of books out there most of them are out-dated, and as a beginner you have to deal with all of these and even worst, those tuts sites where they should teach good coding practices and good samples most of the time have errors and aren't near good. I still have a hope since I found Larry's books , I'll be studying hard...so some day in a near future I'll be in the position of being able to choose "this way" or the "the other" according to the application I would build. Thanks!
  8. Thanks Edward, I get the book covering that part , so I'll be learning that part too, I knew there was a good reason for that, and seems I was missing more than just lil part lol. Sometimes I feel there's no enough time to study all I have to , anyway...I'm going step by step.
  9. Hi Larry I found your book in my pursue for learning more about PHP. I learn procedural programming with PHP and PDO for Database related operations from the first book I bought. With your book I see you are using mysqli and you cover PDO in chapter 8. I know that: 1. Mysqli provides database specific functions. 2. PDO is an abstraction layer, which means you can easily use your database functions no matter which database you are using. 3. If you go to the OOP rute then PDO is the standard for database functions. I know that there are more things, but to make a long story short, for a beginner...who's making his way into PHP and as a starting point with 5.3 flavor and up . * Should I stick to PDO? * Is mandatory to learn mysqli too? I wish you would have used PDO from a very begining in your book. Still have a lot to learn and assimilate. Apart from that...thanks and you got a new reader VĂ­ctor
×
×
  • Create New...