Jump to content
Larry Ullman's Book Forums

margaux

Members
  • Posts

    453
  • Joined

  • Last visited

  • Days Won

    52

Posts 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.

    • Upvote 1
  2. Look at the topic of your post 
     

     

    Post Displays As One Big Paragraph

     

    Which of your scripts displays the post? That's the one you need to edit. You've asked about displaying posts not inserting posts. 

     

     

    You need to find the code that displays the post...   After a SELECT statement where you get all the posts, you'll have some echo statements.
     
     

     

  3. Other options would be to use use str_replace to replace newline characters with the html break tag when OUTPUTTING the post

    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.

    • Upvote 1
  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.

    • Upvote 2
  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.

     

    • Upvote 2
  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. 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.';
    }
    

    • Upvote 1
  9. 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.

    • Upvote 1
  10. I personally don't like it in most cases, as everything I've ever read suggests that most users using the displaying of a page in pieces as the main indicator that the page is actually being loaded.
    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.
  11. 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?

  12. 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

    id username type IF(date_expires >= NOW(), true, false)

    3 marie admin 0

    where

    id=3, username=marie, type=admin, IF(date_expires >= NOW(), true, false) = 0

     

     

     

    "Impossible WHERE noticed after reading const table . . . "
    means the WHERE clause is not being met by any rows in the table, so that's your first port of call.
    • Upvote 1
  13. 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.

    • Upvote 1
  14. Effortless Ecommerce doesn't cover

    "Providing monthly content with different keys to access"
    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.

  15. Although this function could access $_POST['email'] and $_POST['pass'] directly, it’s better if the function is passed these values, making the function more independent.

    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.

×
×
  • Create New...