Jump to content

I-AM-OBODO

Members
  • Posts

    439
  • Joined

  • Last visited

Posts posted by I-AM-OBODO

  1. your loop should only be retrieving the data, forming the $message body with the data values, clearing any previous To: address (see the ClearAddresses() method), set the To: address from the data, and call the send() method. all the rest of the phpmailer related logic should exist only once and come before the start of your loop.

     

    you would also want to check if the send() method indicated success or failure. if it failed, log the error information and the user's email address. if it was successful, you would probably want to set a status value somewhere to indicate that the email was sent (though this is no guarantee that it was received) so that you don't repeatedly send the same reminder email.

     

    Thanks. I have just modified the code. But I'm not sure if i got the ClearAddresses() method usage correctly.

  2. Ok. Thanks guys.

    i've modified the code.

    But @mac_gyver I'm not sure how to use the ClearAddresses() method. Hope what i did is right.

    @jacques1, i know sending all the mails at once will curse flooding, was thinking i'd find a way around that later but thanks for reminding. but how will the script know the first hundred mails it has sent? or does it mean i will have to create another table so that after sending a 100 it marks them as sent/1 as the case maybe it updates the table column and loop again for those not sent. another problem i envisage is the time when the script needs to run again cos there's limit it can run for x hour.

     

    Thanks

     

    my modified code

     
     if(isset($_POST['send_reminder'])){
        
    $sql = "SELECT * FROM users WHERE status = '$status' LIMIT 100";
    $stmt = $pdo->query($sql);
    $stmt->execute();
    
    $message="Hello $name,<br>
    <p>
    This is to remind you that your subscription will expire in $expiry_day.
    </p>
    <p>
    Details as follows:
    Name: $name<br>
    Account Number: $acct_no<br>
    Email: $email_addresses<br>
    Expire in days: $expiry_day<br>
    Expiry Date: $expiry_date
    </p>
    <p>
    Thank you
    </p>
    ";
    
    $mail = new PHPMailer;
    
    //$mail->SMTPDebug = 3;                               // Enable verbose debug output
    
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'mail.server.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'mails@services.cap';                 // SMTP username
    $mail->Password = 'password';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to
    
    $mail->From = 'mails@services.cap';
    $mail->FromName = 'Club 404';
    
    
    
    $mail->WordWrap = 587;                                 // Set word wrap to 50 characters
    
    $mail->AddEmbeddedImage('../img/logo.png', 'my_logo');
    $mail->isHTML(true);                                  // Set email format to HTML
    
    $mail->Subject = 'REMINDER ON CLUB EXPIRY DATE';
    
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
    $name = $row['name'];
    $acct_no = $row['acct_no'];
    $email_addresses = $row['email'];  
    $expiry_date = $row['expiry_date'];
    $expiry_day = $row['expiry_day'];
    
    
    //$mail->addAddress($email_addresses);     // Add a recipient
    $mail->ClearAllRecipients($email_addresses);// not too sure how to use it
    $mail->Body = $mess;
    
    if(!$mail->send()) {
        echo 'Problem sending message.';
    } else {
        echo 'Message has been sent successfully';
    }
    }
    
     }
    
  3. Hi all.

     

    How can i send mail to multiple users at the same time with each user getting their own related data.

    I'm using php mailer as an engine to send the mail.

    Based on this, i'd have loved to setup a cron for it but i do not know how, so i figure i'd just do it manually before i get to know how to setup a cron job.

     

    It's just to send a reminder to users and each user has a different subscription expiry time. I want each user to get their respective expiration date, expiry day etc.

     

    Thanks

     

     

     
     if(isset($_POST['send_reminder'])){
        
    $sql = "SELECT * FROM users WHERE status = '$status'";
    $stmt = $pdo->query($sql);
    $stmt->execute();
    
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
    $name = $row['name'];
    $acct_no = $row['acct_no'];
    $email_addresses = $row['email'];  
    $expiry_date = $row['expiry_date'];
    $expiry_day = $row['expiry_day'];
    
    }
     
    $message="Hello $name,<br>
    <p>
    This is to remind you that your subscription will expire in $expiry_day.
    </p>
    <p>
    Details as follows:
    Name: $name<br>
    Account Number: $acct_no<br>
    Email: $email_addresses<br>
    Expire in days: $expiry_day<br>
    Expiry Date: $expiry_date
    </p>
    <p>
    Thank you
    </p>
     
    $mail = new PHPMailer;
    
    //$mail->SMTPDebug = 3;                               // Enable verbose debug output
    
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'mail.server.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'mails@services.cap';                 // SMTP username
    $mail->Password = 'password';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to
    
    $mail->From = mails@services.cap';
    $mail->FromName = 'Club 404';
    $mail->addAddress($email_addresses);     // Add a recipient
    
    
    $mail->WordWrap = 587;                                 // Set word wrap to 50 characters
    
    $mail->AddEmbeddedImage("../img/logo.png", "my_logo");
    $mail->isHTML(true);                                  // Set email format to HTML
    
    $mail->Subject = 'REMINDER ON CLUB EXPIRY DATE';
    $mail->Body    = $mess;
    $mail->send();
     
    }
     
    
  4. Because he doesn't know the full scope and purpose of your database. I agree with Jacques1 in that you should not delete rows from one table just to populate the same data into another table. There are some legitimate reasons why that might be appropriate, but I'm confident that is not the case here. If you need the data for historical purposes, just have a column in the table for a "deleted" flag.

     

    Then, YOU need to analyze your table. Are there columns that need to be unique (other than an internal primary key)? If so, those constraints could be moved to the business logic. But, assuming there are no unique fields other than the primary key it is much simpler. Then you would just need to make one last decision.

     

    It is assumed that most/all current queries should not return/operate on these "deleted" rows. depending on how many queries you have already built and/or the complexity you expect there will be you could 1) Modify the queries to exclude/include the deleted records as needed or 2) Create a VIEW with the records already filtered based on the deleted field and user that in the applicable queries.

     

    Got it. Thanks

  5. Simply marking rows as deleted is obviously much easier to implement and allows you to get rid of the extra table. However, there are two problems you need to be aware of:

    • Whenever you query the table, you have to remember to exclude deleted rows. This can be fixed with a view which automatically filters the rows.
    • Hidden rows can lead to a lot of confusion when they cause constraint violations. For example, let's say one of the columns is UNIQUE. When a user deletes the rows, they obviously think they can just reuse the value. But instead the database system complains about a conflict with some phantom row which shouldn't even exist (from the user's perspective).

    Your implementation also sounds weird. Why are you using strings? This is very confusing and error-prone. You should be using a BOOLEAN (this is actually an integer type, but MySQL knows how to interpret the values correctly). Use FALSE as the default value and TRUE to delete rows.

     

    Thanks. But you still did not mention which is best?

  6. Thanks all. My Mistake. And i have implemented a different case similar to what Ch0cu3r suggested. What i did was create a column with default value as "NONE" so when the delete command is issued, instead of deleting it updates the "NONE" to "DELETED" so that should i want to issue a query of deleted records, i just use a where delete_status = 'DELETED' and to view all the records: where delete_status = "NONE".

    It works fine but i dunno if it has any side effect.

     

    What's the advantage one has over the other (moving to another table and updating/creating another column)?

     

    Thanks all again!!!!!

  7. I tried below but still wouldnt work

     

     

     
     
    $checkbox_ids = implode(',', $_POST['check_list']);
    $sql = "INSERT INTO cash_user_deleted_transaction SELECT * FROM $tbl_name WHERE id IN($checkbox_ids)";
    $stmt=$pdo->prepare($sql);
    $stmt->execute();
     
    if($stmt-.rowCount()){
     
    echo "inserted";
    }else{
    echo "not inserted";
    }
    
  8. Because you are echo'ing the RECORD DELETED message inside the foreach loop, which is looping over each id from the submitted checkboxes. If you only want that messsage displayed once then you have echo it outside the foreach loop once it has deleted all records. Ofcourse you will need to check if all the selected records where deleted, for that you will have to check the affected rows

     

    Rather than looping over each id, then a manually doing SELECT query, followed by an INSERT query you can do it all in one query using a INSERT SELECT

    Example

    $checkbox_ids = implode(',', $_POST['check_list']);
    $sql = "INSERT INTO cash_user_deleted_transaction SELECT * FROM $tbl_name WHERE id IN($checkbox_ids)";
    

    Or rather than copying the data to another table, why not add a new column which marks that row as deleted, then all you need to do is an update query? Eg

    ALTER TABLE $table_name ADD `deleted` ENUM('0','1') NOT NULL DEFAULT '0';
    $checkbox_ids = implode(',', $_POST['check_list']);
    UPDATE $table_name SET deleted = 1 WHERE id IN($checkbox_ids);
    

    To query records that are not deleted apply  delete = 0  to your where clause. To get deleted records you would use deleted = 1 in the where clause.

     

    $checkbox_ids = implode(',', $_POST['check_list']);

    $sql = "INSERT INTO cash_user_deleted_transaction SELECT * FROM $tbl_name WHERE id IN($checkbox_ids)";

     

    Does this mean the insert statement here dont need the "values" attributes?

     

    will give it a go,

     

    thanks

  9. Hi all.

     

    I'm having an issue with my code. I dunno why it's not working as intended.

    I want to delete selected rows and insert them into another table just in case i want to recall them. So far the delete is working but i'm having two issues with it.

     

    1. when i select 5 rows and press delete, it echos result for the 5 rows instead of just one echo result.

    2. I cannot insert it into another table.

     

    Thanks

     

    here's my code

     

     

     
    <?php
    
    $stmt = $pdo->prepare(
    "SELECT * FROM $tbl_name
    ORDER BY trans_date DESC"
    );
    $stmt->execute();
    
     <form action="" method="post">  
    <table class='table-responsive table-condensed table-striped'>
    
    <tr>
    <td align="center" bgcolor="#444444"><font color='#fff'><strong>#</strong></font></td>
    <td align='center' bgcolor="#444444"><font color='#fff'>Client Username</font></td>
    <td align='center' bgcolor="#444444"><font color='#fff'>Loan Number</font></td>
    <td align='center' bgcolor="#444444"><font color='#fff'>Amount</font></td>
    <td align="center" bgcolor="#444444"><font color='#fff'><strong>Repayment Amount</strong></font></td>
    <td align="center" bgcolor="#444444"><font color='#fff'><strong>Loan Date</strong></font></td>
    <td align="center" bgcolor="#444444"><font color='#fff'><strong>Due Date</strong></font></td>
    <td align="center" bgcolor="#444444"><font color='#fff'><strong>BTN</strong></font></td>
    <td align="center" bgcolor="#444444"><font color='#fff'><strong>FIN</strong></font></td>
    <td align="center" bgcolor="#444444"><font color='#fff'><strong>Bank Acct Number</strong></font></td>
    <td align="center" bgcolor="#444444"><font color='#fff'><strong>Date Closed</strong></font></td>
    <td align="center" bgcolor="#444444"><font color='#fff'><strong>Closed From</strong></font></td>
    </tr>
    
    <?php
    // keeps getting the next row until there are no more to get
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    ?>
    
    <tr>
    <td align="center"><input name="check_list[]" type="checkbox" value="<?php echo $row['id']; ?>" ></td>
    <td><?php     echo $row['email']; ?></td>
    <td><?php     echo $row['loan_number']; ?></td>
    <td><?php     echo number_format($row['amount_borrow'],2); ?></td>
    <td><?php     echo number_format($row['payback_amount'],2); ?></td>
    <td><?php    echo $row['trans_date']; ?></td>
    <td><?php    echo $row['payback_date']; ?></td>
    <td><?php    echo $row['branch_transit_number']; ?></td>
    <td><?php    echo $row['financial_institution_number']; ?></td>
    <td><?php    echo $row['bank_account_number']; ?></td>
    <td><?php    echo $row['date_closed']; ?></td>
    <td><?php    echo $row['closed_from']; ?></td>
    </tr>
    <?php
    }
    ?>
    </table>
    <input name="delete" type="submit" class="btn btn-default btn-delete" id="delete" value="DELETE SELECTED">
    </form>
    
    
     <?php
    
    
    if(isset($_POST['delete'])){
        
    $table=$pdo->query("ALTER TABLE cash_user_transaction AUTO_INCREMENT = 1");
    $table->execute();
    
        if(!empty($_POST['check_list'])){
            foreach($_POST['check_list'] as $selected){
    
    $stmt = $pdo->prepare("SELECT * FROM $tbl_name WHERE id = '$selected'");
    $stmt->execute();
    while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {    
    $email = $row['email'];
    $loan_number = $row['loan_humber'];
    $amount_borrow = $row['amount_borrow'];
    $terms_agreement=$row['terms_agreement'];
    $terms_agreement_days=$row['terms_agreement_days'];
    $cost_borrow=$row['cost_borrow'];
    $trans_date=$row['trans_date'];
    $payback_date=$row['payback_date'];
    $payback_amount=$row['payback_amount'];
    $branch_transit_number=$row['branch_transit_number'];
    $financial_institution_number=$row['financial_institution_number'];
    $bank_account_number=$row['bank_account_number'];
    $status=$row['status'];
    $initial=$row['initial'];
    $pay_frequency=$row['pay_frequency'];
    $refinance_request=$row['refinance_request'];
    $date_closed=$row['date_closed'];
    $disbursed_status=$row['disbursed_status'];
    $date_disbursed=$row['date_disbursed'];
    $closed_from=$row['closed_from'];
    }
    
        if($stmt->rowCount()){
    $stmt = $pdo->prepare("INSERT INTO cash_user_deleted_transaction
            (email, loan_number, amount_borrow, terms_agreement, terms_agreement_days, cost_borrow, trans_date, payback_date, payback_amount, branch_transit_number, financial_institution_number, bank_account_number, status, initial, pay_frequency, refinance_request, date_closed, disbursed_status, date_disbursed, closed_from, date_deleted)
            
            VALUES(:email, :loan_number, :amount_borrow, :terms_agreement, :terms_agreement_days, :cost_borrow, :trans_date, :payback_date, :payback_amount, :branch_transit_number, :financial_institution_number, :bank_account_number, :status, :initial, :pay_frequency, :refinance_request, :date_closed, :disbursed_status, :date_disbursed, :closed_from, NOW())");
            
    $stmt->execute(array(
    ':email'=>$email,
    ':loan_number'=>$loan_humber,
    ':amount_borrow'=>$amount_borrow,
    ':terms_agreement'=>$terms_agreement,
    ':terms_agreement_days'=>$terms_agreement_days,
    ':cost_borrow'=>$cost_borrow,
    ':trans_date'=>$trans_date,
    ':payback_date'=>$payback_date,
    ':payback_amount'=>$payback_amount,
    ':branch_transit_number'=>$branch_transit_number,
    ':financial_institution_number'=>$financial_institution_number,
    ':bank_account_number'=>$bank_account_number,
    ':status'=>$status,
    ':initial'=>$initial,
    ':pay_frequency'=>$pay_frequency,
    ':refinance_request'=>$refinance_request,
    ':date_closed'=>$date_closed,
    ':disbursed_status'=>$disbursed_status,
    ':date_disbursed'=>$date_disbursed,
    ':closed_from'=>$closed_from
    ));    
    
    $stmt = $pdo->prepare("DELETE FROM $tbl_name WHERE id=:id");
    $stmt->bindValue(':id', $selected, PDO::PARAM_STR);
    $stmt->execute();
        echo "<div class='bg-success alert alert-success text-center'>RECORD DELETED</div>";
        
    }else{
        echo "<div class='bg-warning alert alert-warning text-center'>RECORD NOT DELETED</div>";
        echo $pay_frequency;
        echo "<br>";
        echo $status;
        echo "<br>";
        echo $amount_borrow;
    
    }
                
            }
        }
        
    }
    
    ?>
     
    
  10. So if you point your browser to localhost/laravel/public/css/styles.css, it doesn't work?

     

    Can you post your directory structure?

     

    My directory structure

    app

    - Console

    -Events

    - Exeptions

    - Http

    - Jobs

    - Listeners

    - Policies

    - Providers

    -- user

    bootstrap

    - cache

    -- app

    -- autoload

    config

    -- app

    -- auth

    -- broadcasting

    -- cache

    -- compile

    -- database

    -- filesystems

    -- mail

    -- queue

    -- services

    -- session

    -- view

    database

    - factories

    - migrations

    - seeds

    public

    - css

    - fonts

    - js

    -- htaccess

    -- favicon

    -- index

    -- robots

    resources

    - assets

    - lang

    - views

    storage

    - app

    - framework

    - logs

    tests

    - ExampleTest

    - TestCase

    vendor

    - so many folders

  11. My directory structure

    app

    - Console

    -Events

    - Exeptions

    - Http

    - Jobs

    - Listeners

    - Policies

    - Providers

    -- user

    bootstrap

    - cache

    -- app

    -- autoload

    config

    -- app

    -- auth

    -- broadcasting

    -- cache

    -- compile

    -- database

    -- filesystems

    -- mail

    -- queue

    -- services

    -- session

    -- view

    database

    - factories

    - migrations

    - seeds

    public

    - css

    - fonts

    - js

    -- htaccess

    -- favicon

    -- index

    -- robots

    resources

    - assets

    - lang

    - views

    storage

    - app

    - framework

    - logs

    tests

    - ExampleTest

    - TestCase

    vendor

    - so many folders

  12. If your assets are in public/css, and it's only loading css, then it looks like you should change the asset path to include public.

     

    <link rel="stylesheet" href="{!! asset('public/css/bootstrap.min.css') !!}">
    <link rel="stylesheet" href="{!! asset('public/css/styles.css') !!}">

    Tried it as well but to no avail :(

  13. What URL is it trying to load? Look in the network tab on Chrome Developer Tools.

     

    On the network tab in chrome it's not showing any url at all. just blank but on view source

     

    localhost/laravel/index

    localhost/laravel/css/styles.css

    localhost/laravel/css/bootstrap.min.css

    localhost/laravel/css/bootstrap-theme.min.css

    localhost/laravel/js/bootstrap.min.js

     

    again i noticed it has 8 error notifications and when i checked, i saw that the path to my styles is not seen:

    Failed to load resource: the server responded with a status of 404 (Not Found)

     

    what could be wrong. but when i load the bootstrap style from the cdn, it works perfectly!!

  14. Hi all.

     

    No matter what i tried my links just wont work on my laravel app.  My css folder is in the public folder. public/css. I dunno what is wrong. I installed laravel with composer and i am running windows 7 and wamp.

    this is the link i used:

     

    <link rel="stylesheet" href="{!! asset('css/bootstrap.min.css') !!}">
    <link rel="stylesheet" href="{!! asset('css/styles.css') !!}">

     

    Thanks

  15. Thanks all.

     

    Finally i got it to work. I noticed that the point where the regenerating starts is not the next page but on the first page (reason i don't understand though)

    I had to create a hidden field and assign the random number to it and then i did an insert with the post value and after that reassigned the value to a session.

    Viola! it did the magic!

     

    PS: The code shown is not the complete code but the modified code/logic that was giving me trouble and that worked the trouble.

     

    Here's my code

     

     

     
    $number = mt_rand(1000, 9999);
    
    $name = "John Doe";
    
    echo $name;
    echo "<br>";
    echo "Your tally nuber is: ". $number ;
    
    if(isset($_POST['submit'])){
    
    //database insert stuff
    $_SESSION['numb'] = $_POST['numb'];
    header("location: nextpage.php");
    
    }else{
    
    echo "could not complete action";
    
    }
    //html form
    <form method="post" action="">
    <input name="numb" type="hidden" value="<?php echo $number; ?>">
    <input name="submit" type="submit" value="NEXT" >
    </form>
    
    
    //page two
    
    session_start();
     
    $number = $_SESSION['numb'];
    
    echo $number;
     
    
  16. The code you posted, is that copy and pasted right from your work or did you modify it for us? It's broken by the looks of it.

     

    Maybe it's throwing an error but redirecting to the other page before you see the message. Comment out the header and see what happens.

     

    i doubt there's any error

  17. There seems to be a little problem with my first post but the problem still lingers.

    I generate the code on the first page so that it can pass on the value generated to the second page.

    here's a modification of my code

    //page one
    session_start();
    
    //generate the number
    // i even tried $_SESSION['number'] =  mt_rand(1000, 9999); but to no avail
    $number = mt_rand(1000, 9999);
    
    $name = "John Doe";
    
    echo $name;
    echo "<br>";
    echo "Your tally nuber is: ". $number ;
    
    if(isset($_POST['submit'])){
    
    //database insert stuff
    $_SESSION['number'] = $number;
    header("location: nextpage.php");
    
    }else{
    
    echo "could not complete action";
    
    }
    //html form cos
    <form method="post" action="">
    <input name="submit" type="submit" value="NEXT" >
    </form>
    
    
    //page two
    
    session_start();
    
    echo $_SESSION['number']; //but it regenerates another number
     
    
  18.  

    Sounds to me you most likely need to wrap the code that generates the number in a condition, so it only generates the number when the session variable does not exist. Eg

    if(!isset($_SESSION['num']))
    {
        // generate new random number
    }
    
    // use random number
    

    Tried that but still didnt work. still regenerates number

  19. Hi all.

    I generated a random number and assigned it a variable to be used through out the session but on getting to the next page, the value changes. It is regenerating another number which isnt the intention. I have tried severally but no way!

    i really cannot figure out why the value changes in my second page.

     
    $loan =  mt_rand(1000, 9999);
    $name = "John";
     
    if(isset($_POST['continue'])){
        
    $_SESSION['num'] = $number;
     
    $sql = ("INSERT INTO table (name, token_number) VALUES(:name, :token_number)
    $stmt=$pdo->prepare($sql);
    $stmt->execute(array(
    ':name'=>$name;
    ':token_number'=>$_SESSION['num']
    ));
     
    if($stmt->rowCount()==1){
     
    header("location: nextpage.php");
     
    }else{
     
    echo "Something went wrong";
     
    }
     
    }
    
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.