Jump to content
Larry Ullman's Book Forums

margaux

Members
  • Posts

    453
  • Joined

  • Last visited

  • Days Won

    52

Everything posted by margaux

  1. I highly recommend this issue of Larry's newletter to forum readers. It is full of direction, resources and suggestions for improving your workflow and taking you to the next step as a web developer. Regarding responsive web design resources, Ethan Marcote's book Responsive Web Design is the best resource for first getting started with rwd. After that I would suggest jumping in and converting / building a responsive site. Frameworks - JQuery Mobile is worth getting to know and Pro JQuery Mobile is a decent resource for getting started.
  2. Look at the topic of your post Which of your scripts displays the post? That's the one you need to edit. You've asked about displaying posts not inserting posts.
  3. You need to find the code that displays the post - it will be in a different script than the one you've posted. After a SELECT statement where you get all the posts, you'll have some echo statements. Find the one that echos out the body of the post, probably something like $row['message'] or $row['body'], Use the str_replace or nl2br function on $row['body']e.g. nl2br($row['body']) Nice call Antonio, I had forgotten about that function.
  4. I can understand why you want to keep to 2 tables but you'll be continually having to find workarounds to compensate for not good data design. Good data design is more scaleable and you will learn more in the process. Here's an example of a query across 3 tables: SELECT name, s.id AS contact, phone, email, request, sub_title FROM submitted AS s INNER JOIN submitted_requests AS sr ON s.id = sr.submitted_id INNER JOIN requests AS r ON sr.request_id = r.id ORDER BY name To output in a table you can do something like // Fetch and print all the records.... $contact = 0; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { if ($row['contact'] != $contact) { echo '<tr><td align="left">Name: ' . $row['name'] . '<br />Phone: '.$row['phone'].'<br/>email: '.$row['email'].'</td>'; echo '<td align="left">' .$row['request'] . ' - ' . $row['sub_title']; $contact = $row['contact']; } else { echo '<br/>' .$row['request'] . ' - ' . $row['sub_title']; $contact = $row['contact']; } } echo '</table>'; You'll need to tidy up the output but you get the general idea.
  5. You only need 1 query $q = "SELECT name, phone, email, r.request, sub_title FROM submitted AS s INNER JOIN requests AS r ON s.request = r.id"; If I understand correctly what you are trying to do, I recommend a third table as at the moment you're storing the same submitted details many times over. Submitteds can have many requests and requests can belong to more than one submitted so you need a link table (can't remember the correct term), submitted-requests which would have 3 fields - an id, a submitted_id and a request_id. submitted_id and request_id would need to be set up as indices. Your select statement would have another join. Have a go at doing this yourself and come back if you have any questions.
  6. What are you using to enter text? A simple textarea input field does not recognise formatting or html characters. You will need to employ something like CKEditor or tiny_mce for this additional functionality. I've only used the latter and found it easy to implement but have also heard good things about the former. Other options would be to use use str_replace to replace newline characters with the html break tag when outputting the post e.g. str_replace("\n", '<br>', $row['post']) or when selecting from the database you could use REPLACE to do the same.
  7. These kind of errors require some basic debugging and the error messages give you a good indication of what is causing the problem. In the first case, the files are not in the folders that are being pointed to. Either relocate the files or change the path. In the second case, its usually because there is an error in the mysql query. Run the query directly in something like phpmyadmin and you should get a helpful response. Usually if you cut and paste the error response in google you'll find loads of similar questions with possible solutions to try.
  8. You can add the column using the ALTER TABLE command and give it a default value, e.g. ALTER TABLE `tablename` ADD `registration_date` DATETIME NOT NULL DEFAULT NOW() or the phpmyadmin interface gives you an option to add a column and select its position in relation to the other columns.
  9. What does not working mean? Do you get any error messages? If you've only downloaded the files it won't work. You need to set up the database and modify the configuration files for your set up. Have you read any of the book? Sorry for these questions but your post actually gives very little information on which to reply.
  10. Your insert query will not work for precisely the reason that benjamin.morgan indicated, though that would not explain why you are getting the email error message. However, I'm surprised you're not getting an error regarding the password. // Check for password and match against the confirmed password: if (empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'Your password did not match your confirmed password.'; } else { $p = trim($_POST['pass1']); } } else { $errors[] = 'You forgot to enter your password.'; } The logic here is not correct, you want to check initially for a NOT empty pass1 e.g. // Check for password and match against the confirmed password: if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'Your password did not match your confirmed password.'; } else { $p = trim($_POST['pass1']); } } else { $errors[] = 'You forgot to enter your password.'; }
  11. Your code is somewhat complicated but I think I see what you're trying to do. As you've recognised in form_functions, radio buttons must have the same name in order to be grouped together. However your validation code is testing for $_POST['sex1'] and $_POST['sex2'] which its never going to find. Try simplifying it a bit if (!isset($_POST['sex']) && empty($_POST['sex'])) { $reg_errors['sex'] = 'You have NOT entered your gender type!'; } Of course as written, this code will echo the error message twice, but I'll let you figure out how to rectify that. Also, I know you may just be working on getting the site working but as you're learning, you might as well learn best practices so instead of using a bunch of to position your radio buttons, give them a class and use css to position them.
  12. More than likely its to do with your file structure - you'll need to ensure that the script is looking in the correct folder.
  13. HartleySan, would you confirm that it is a personal dislike of this output buffereing as opposed to bad practice to use it. Generally I don't use ob, but find it helpful to use in cms scripts which give the user options to edit/delete/insert content and then redirect to an appropriate page depending on the selected option. If there is a better approach, I would be interested to learn it.
  14. That's exactly what you want to do. The whole point of checking the expiry date is to handle it gracefully - if the user's account has not expired, show him the content. If the user's account has expired, display a polite message encouraging him to renew his account. I did this example some time ago so can't remember the details precisely but I recall that some content is available to users with expired accounts and the site makes use of a session variable to determine what content a user can access. After your query you need to check the expiry date and if it is false set a session variable - that's what this line does if ($row[3] == 1) $_SESSION['user_not_expired'] = true; Are you sure that you are making use of this variable before displaying content?
  15. SELECT id, username, type, IF(date_expires >= NOW(), true, false) FROM users WHERE (email='$e' AND pass='" . get_password_hash($p) . "') when you enter the above query directly into phpadmin with a valid combination of email and password you should get something like this whereid=3, username=marie, type=admin, IF(date_expires >= NOW(), true, false) = 0 means the WHERE clause is not being met by any rows in the table, so that's your first port of call.
  16. If the registrant has an expiry date earlier than now, $row[3] will return a 0 for false. If the expiry date is in the future you should get a 1 for true. I'm confused by the LIMIT clause, you are only querying the table for 1 record so what is the LIMIT clause there for?
  17. php error messages tend to be quite helpful. Are you sure delete is a function? Try looking it up.
  18. Glad I was able to help. As you start to write your own functions you will find that you need to manipulate the variable type so its a useful lesson. The php manual is a good resource for manipulating and casting types.
  19. Sounds like you have an issue with the encoding you are using. Most sql installations default to utf-8-general-ci or latin-swedish-ci. I am not familiar with the encoding used for russian characters. You will need to find out what charset the russian alphabet uses, then ensure that your database and sql encoding matches. Searching online should bring up some answers for you.
  20. It looks like your $zip variable is cast as an integer. You need to convert it to a string - there are several ways to do so, one way is to cast it using string
  21. Larry uses a constant to facilitate connecting to the database. In the config file you need to define the constant MYSQL e.g. define ('MYSQL', '../mysqli_connect.php'); The second parameter is the absolute path to your connection script. Then any file that needs to connect to the database simply calls the MYSQL constant require_once(MYSQL);
  22. How is it not working? What debugging have you done? Does the sql query return the values you expect? Is this a standalone script or being included by another? Have you started the session? where?
  23. Effortless Ecommerce doesn't cover precisely but after having read the book, I believe you would be able to implement that requirement. You would need to set up a regularly scheduled job to check if new keys need to be sent which you could probably achieve with a cron job. The book does cover site planning, set up, database set up and the programming for most of the functionality. The rest you could learn yourself. In addition to PHP and MySQL, you will need HTML and CSS. Javascript or JQuery and Ajax provide additional enhancements but are not a requirement per se.
  24. The function handles the login process. Larry is saying that the function could use the $_POST values to check the user's credentials but that it is better/more secure to pass the values in variables when the function is called.
  25. HartleySan's code worked for me - I just needed to escape the double quotes for the height and width attributes. You might want to check your file names - if there are spaces in them, using urlencode will add characters to the $_GET['image'] variable and the filename won't be recognised.
×
×
  • Create New...