Jump to content

ianhaney

Members
  • Posts

    330
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by ianhaney

  1. No probs, below is the coding I have

     

    <?php
    
    // PHPMailer classes into the global namespace
    use PHPMailer\PHPMailer\PHPMailer; 
    use PHPMailer\PHPMailer\Exception;
    // Base files 
    require 'PHPMailer/src/Exception.php';
    require 'PHPMailer/src/PHPMailer.php';
    require 'PHPMailer/src/SMTP.php';
    // create object of PHPMailer class with boolean parameter which sets/unsets exception.
    $mail = new PHPMailer(true);                              
    try {
        //$mail->isSMTP(); // using SMTP protocol
        $mail->Host = 'hostname'; // SMTP host as gmail 
        $mail->SMTPAuth = true;  // enable smtp authentication
        $mail->Username = 'emailaddress';  // sender gmail host              
        $mail->Password = 'emailaddresspassword'; // sender gmail host password                          
        $mail->SMTPSecure = 'ssl';  // for encrypted connection                           
        $mail->Port = 587;   // port for SMTP     
    
        $mail->setFrom('emailaddress', "Sender"); // sender's email and name
        $mail->addAddress('emailaddress', "Receiver");  // receiver's email and name
    
        $mail->Subject = 'New Online Order';
        $mail->Body    = "A new order has been received. The order information is below" . "\r\n\r\n" . "Club One: " . $_POST["club1"] . "\r\n" . "Country One: " . $_POST["country1"] . "\r\n" . "Ref No: " . $_POST["refno1"] . "\r\n" . "Quantity: " . $_POST["quantity1"] . "\r\n" . "Total Price Line: " . "\243" . $_POST["totalprice1"] . "\r\n\r\n" . "Club Two: " . $_POST["club2"] . "\r\n" . "Country Two: " . $_POST["country2"] . "\r\n" . "Ref No: " . $_POST["refno2"] . "\r\n" . "Quantity: " . $_POST["quantity2"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice2"] . "\r\n\r\n" . "Club Three: " . $_POST["club3"] . "\r\n" . "Country Three: " . $_POST["country3"] . "\r\n" . "Ref No: " . $_POST["refno3"] . "\r\n" . "Quantity: " . $_POST["quantity3"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice3"] . "\r\n\r\n" . "Club Four: " . $_POST["club4"] . "\r\n" . "Country Four: " . $_POST["country4"] . "\r\n" . "Ref No: " . $_POST["refno4"] . "\r\n" . "Quantity: " . $_POST["quantity4"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice4"] . "\r\n\r\n" . "Club Five: " . $_POST["club5"] . "\r\n" . "Country Five: " . $_POST["country5"] . "\r\n" . "Ref No: " . $_POST["refno5"] . "\r\n" . "Quantity: " . $_POST["quantity5"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice5"] . "\r\n\r\n" . "Club Six: " . $_POST["club6"] . "\r\n" . "Country Six: " . $_POST["country6"] . "\r\n" . "Ref No: " . $_POST["refno6"] . "\r\n" . "Quantity: " . $_POST["quantity6"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice6"] . "\r\n\r\n" . "Club Seven: " . $_POST["club7"] . "\r\n" . "Country Seven: " . $_POST["country7"] . "\r\n" . "Ref No: " . $_POST["refno7"] . "\r\n" . "Quantity: " . $_POST["quantity7"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice7"] . "\r\n\r\n" . "Club Eight: " . $_POST["club8"] . "\r\n" . "Country Eight: " . $_POST["country8"] . "\r\n" . "Ref No: " . $_POST["refno8"] . "\r\n" . "Quantity: " . $_POST["quantity8"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice8"] . "\r\n\r\n" . "Club Nine: " . $_POST["club9"] . "\r\n" . "Country Nine: " . $_POST["country9"] . "\r\n" . "Ref No: " . $_POST["refno9"] . "\r\n" . "Quantity: " . $_POST["quantity9"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice9"] . "\r\n\r\n" . "Club Ten: " . $_POST["club10"] . "\r\n" . "Country Ten: " . $_POST["country10"] . "\r\n" . "Ref No: " . $_POST["refno10"] . "\r\n" . "Quantity: " . $_POST["quantity10"] . "\r\n" . "Total Price Line: " . "\243".$_POST["totalprice10"] . "\r\n\r\n" . "Name: " . $_POST["name"] . "\r\n" . "Address Line 1: " . $_POST["addressline1"] . "\r\n" . "Address Line 2: " . $_POST["addressline2"] . "\r\n" . "Postcode: " . $_POST["postcode"] . "\r\n" . "Email: " . $_POST["email"] . "\r\n\r\n" . "Catalogue Subscription: " . $_POST["catalogue"];
    
        $mail->send();
        header('Location:thank-you.html');
    } catch (Exception $e) { // handle error.
        echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
    }
    ?>

     

  2. I am trying to get phpmailer working but not having much luck with it. I am not receiving the email

    Below is the code I have

    <?php
    //index.php
    
    $error = '';
    $quantity1 = '';
    $totalprice1 = '';
    
    $subtotal = '';
    $postage = '';
    $grandtotal = '';
    
    $name = '';
    $addressline1 = '';
    $postcode = '';
    $email = '';
    
    function clean_text($string)
    {
     $string = trim($string);
     $string = stripslashes($string);
     $string = htmlspecialchars($string);
     return $string;
    }
    
    if(isset($_POST["submit"]))
    {
    if(empty($_POST["quantity1"]))
     {
      $error .= '<p><label class="text-danger">Please enter the quantity required</label></p>';
     }
        
    if(empty($_POST["totalprice1"]))
     {
      $error .= '<p><label class="text-danger">Please enter the total price required</label></p>';
     }
        
    if(empty($_POST["subtotal"]))
     {
      $error .= '<p><label class="text-danger">Please enter the subtotal</label></p>';
     }
        
    if(empty($_POST["postage"]))
     {
      $error .= '<p><label class="text-danger">Please enter the postage</label></p>';
     }
        
    if(empty($_POST["grandtotal"]))
     {
      $error .= '<p><label class="text-danger">Please enter the grand total</label></p>';
     }
        
     if(empty($_POST["name"]))
     {
      $error .= '<p><label class="text-danger">Please Enter your name</label></p>';
     }
     else
     {
      $name = clean_text($_POST["name"]);
      if(!preg_match("/^[a-zA-Z ]*$/",$name))
      {
       $error .= '<p><label class="text-danger">Only letters and white space allowed</label></p>';
      }
     }
        
    if(empty($_POST["addressline1"]))
     {
      $error .= '<p><label class="text-danger">Please enter your address line 1</label></p>';
     }
        
    if(empty($_POST["postcode"]))
     {
      $error .= '<p><label class="text-danger">Please enter your postcode</label></p>';
     }
        
     if(empty($_POST["email"]))
     {
      $error .= '<p><label class="text-danger">Please Enter your Email</label></p>';
     }
     else
     {
      $email = clean_text($_POST["email"]);
      if(!filter_var($email, FILTER_VALIDATE_EMAIL))
      {
       $error .= '<p><label class="text-danger">Invalid email format</label></p>';
      }
     }
     if($error == '')
     {
      require 'phpmailer/class.phpmailer.php';
      $mail = new PHPMailer(true);
      $mail->SMTPDebug = 1; // to see exactly what's the issue
      $mail->IsSMTP();        //Sets Mailer to send message using SMTP
      $mail->Host = 'hostname';  //Sets the SMTP hosts
      $mail->Port = '587';        //Sets the default SMTP server port
      $mail->SMTPAuth = true;       //Sets SMTP authentication. Utilizes the Username and Password variables
      $mail->Username = 'emailaddress';     //Sets SMTP username
      $mail->Password = 'emailaddresspassword';     //Sets SMTP password
      $mail->SMTPSecure = '';       //Sets connection prefix. Options are "", "ssl" or "tls"
      $mail->From = $_POST["email"];     //Sets the From email address for the message
      $mail->FromName = $_POST["name"];    //Sets the From name of the message
      $mail->AddAddress('emailaddress', 'Name');//Adds a "To" address
      $mail->AddCC($_POST["email"], $_POST["name"]); //Adds a "Cc" address
      $mail->WordWrap = 50;       //Sets word wrapping on the body of the message to a given number of characters
      $mail->IsHTML(true);       //Sets message type to HTML    
      $mail->Subject = "Online Badge Order";    //Sets the Subject of the message
         
      $mail->Body = "The order information is below" . "<br><br>" . "Club One: " . $_POST["club1"] . "<br>" . "Country One: " . $_POST["country1"] . "<br>" . "Ref No: " . $_POST["refno1"] . "<br>" . "Quantity: " . "<br>" . $_POST["quantity1"] . "<br>" . "Total Price Line: " . "\243" . $_POST["totalprice1"] . "<br><br>" . "Club Two: " . $_POST["club2"] . "<br>" . "Country Two: " . $_POST["country2"] . "<br>" . "Ref No: " . $_POST["refno2"] . "<br>" . "Quantity: " . $_POST["quantity2"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice2"] . "<br><br>" . "Club Three: " . $_POST["club3"] . "<br>" . "Country Three: " . $_POST["country3"] . "<br>" . "Ref No: " . $_POST["refno3"] . "<br>" . "Quantity: " . $_POST["quantity3"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice3"] . "<br><br>" . "Club Four: " . $_POST["club4"] . "<br>" . "Country Four: " . $_POST["country4"] . "<br>" . "Ref No: " . $_POST["refno4"] . "<br>" . "Quantity: " . $_POST["quantity4"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice4"] . "<br><br>" . "Club Five: " . $_POST["club5"] . "<br>" . "Country Five: " . $_POST["country5"] . "<br>" . "Ref No: " . $_POST["refno5"] . "<br>" . "Quantity: " . $_POST["quantity5"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice5"] . "<br><br>" . "Club Six: " . $_POST["club6"] . "<br>" . "Country Six: " . $_POST["country6"] . "<br>" . "Ref No: " . $_POST["refno6"] . "<br>" . "Quantity: " . $_POST["quantity6"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice6"] . "<br><br>" . "Club Seven: " . $_POST["club7"] . "<br>" . "Country Seven: " . $_POST["country7"] . "<br>" . "Ref No: " . $_POST["refno7"] . "<br>" . "Quantity: " . $_POST["quantity7"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice7"] . "<br><br>" . "Club Eight: " . $_POST["club8"] . "<br>" . "Country Eight: " . $_POST["country8"] . "<br>" . "Ref No: " . $_POST["refno8"] . "<br>" . "Quantity: " . $_POST["quantity8"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice8"] . "<br><br>" . "Club Nine: " . $_POST["club9"] . "<br>" . "Country Nine: " . $_POST["country9"] . "<br>" . "Ref No: " . $_POST["refno9"] . "<br>" . "Quantity: " . $_POST["quantity9"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice9"] . "<br><br>" . "Club Ten: " . $_POST["club10"] . "<br>" . "Country Ten: " . $_POST["country10"] . "<br>" . "Ref No: " . $_POST["refno10"] . "<br>" . "Quantity: " . $_POST["quantity10"] . "<br>" . "Total Price Line: " . "\243".$_POST["totalprice10"];    //An HTML or plain text message body
         
      if($mail->Send())        //Send an Email. Return true on success or false on error
      {
       header('Location:thank-you.html');
      }
      else
      {
       $error = '<label class="text-danger">There is an Error</label>';
      }
         
    $quantity1 = '';
    $totalprice1 = '';
    
    $subtotal = '';
    $postage = '';
    $grandtotal = '';
    
    $name = '';
    $addressline1 = '';
    $postcode = '';
    $email = '';
     }
    }
    
    ?>

     

  3. I would like to pull in Facebook reviews from my Facebook page and display them on a page on my website but am new to doing that so just seeing if there is any sample code I can get from somewhere to have a look at please?

    I have got a page access token from Facebook developers but unsure what the coding would be like to pull the reviews in

  4. I have followed the coding from the link in your post reply but no results are showing when I do a search and what name I am searching for should return 1 result, good thing is I have no errors but not sure what I am missing

     

    I have the following code now

    <?php
    
    //load database connection
        $host = "localhost";
        $user = "";
        $password = "";
        $database_name = "";
        $pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION	
        ));
    $search=$_POST['search'];
    $sql=$pdo->prepare("SELECT select id, fullname, address, emailaddress, phonenumber, mobilenumber, amountloan, term, homeowner, DATE_FORMAT(loanappdate, '%d/%m/%Y') AS 'loanappdate' from unsecured_loans where fullname LIKE '%$search%'");
    // Search from MySQL database table
    $sql->bindValue(1, "%$search%", PDO::PARAM_STR);
            
    		// were any rows found?                
    if ($row = $sql->fetchObject())
    {
            // display records in a table
            echo "<table class='records'>";
            
            // set table headers
            echo "<tr>
            <th>ID</th>
            <th>Full Name</th>
            <th>Address</th>
    		<th>Email Address</th>
            <th>Phone Number</th>
            <th>Mobile Number</th>
    		<th>Unsecured Loan Amount</th>
    		<th>Term(Months)</th>
    		<th>Applicant Status</th>
    		<th>Unsecured Loan Application Date</th>
            <th colspan='1'>Actions</th>
            </tr>";
            
           
            do {
                    // set up a row for each record
                    echo "<tr>";
                    echo "<td>" . $row->id . "</td>";
                    echo "<td>" . $row->fullname . "</td>";
                    echo "<td>" . $row->address . "</td>";
                    echo "<td>" . $row->emailaddress . "</td>";
    				echo "<td>" . $row->phonenumber . "</td>";
    				echo "<td>" . $row->mobilenumber . "</td>";
    				echo "<td>" . '£' . $row->amountloan . "</td>";
    				echo "<td>" . $row->term . "</td>";
    				echo "<td>" . $row->homeowner . "</td>";
                    echo "<td>" . $row->loanappdate . "</td>";
                    echo '<td><a onClick=\"javascript: return confirm("Are you sure you wish to delete this applicant?");\" href="delete.php?id=" . $row->id . "">Delete</a></td>';
                    echo "</tr>";
            }  while ($row = $sql->fetchObject());
            
            echo "</table>";
    }
    // if there are no records in the database, display an alert message
    else
    {
            echo "No results to display!";
    }
    
    ?>
    
  5. Hi

     

    I am making a search form where the admin can search for a name using a input field and returns the results for records that match the name, that side of it works but I can't get the id record number retrieved from the db and make it a clickable link but I get the following error in the id column

     

    Notice: Trying to get property of non-object in /home/firstqualityfina/public_html/admin/unsecured-loan-applicants/search-unsecured-loan-applicant-results.php on line 97

     

    On line 97 is the following

    echo "<a href='view-specific-unsecured-loan-applicant.php?id=" . $results->id ."'>".$results->id . "</a>";
    

    The whole code looks like the following

    <?php
    //load database connection
        $host = "localhost";
        $user = "";
        $password = "";
        $database_name = "";
        $pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION	
        ));
    // Search from MySQL database table
    $search=$_POST['search'];
    $query = $pdo->prepare("select id, fullname, address, emailaddress, phonenumber, mobilenumber, amountloan, term, homeowner, DATE_FORMAT(loanappdate, '%d/%m/%Y') AS 'loanappdate' from unsecured_loans where fullname LIKE '%$search%' LIMIT 0 , 10");
    $query->bindValue(1, "%$search%", PDO::PARAM_STR);
    $query->execute();
    
    $query->execute();
    // Display search result
             if (!$query->rowCount() == 0) {
    			 	echo "<div style='clear: both;'>";
    				echo "<br><br>";
    echo "<table class='records'>";
    echo "<thead>";
    echo "<tr>";
    echo "<th>ID</th>";
    echo "<th>Full Name</th>";
    echo "<th>Address</th>";
    echo "<th>Email Address</th>";
    echo "<th>Phone Number</th>";
    echo "<th>Mobile Number</th>";
    echo "<th>Unsecured Loan Amount</th>";
    echo "<th>Term(Months)</th>";
    echo "<th>Applicant Status</th>";
    echo "<th>Unsecured Loan Application Date</th>";
    echo "<th>Actions</th>";
    echo "</tr>";
               echo "</thead>";
    		   
    		   while ($results = $query->fetch()) {
    				echo "<tr><td>";
    				echo "<a href='view-specific-unsecured-loan-applicant.php?id=" . $results->id ."'>".$results->id . "</a>";
    				echo "</td><td>";
                    echo $results['fullname'];
    				echo "</td><td>";
                    echo $results['address'];
    				echo "</td><td>";	
                    echo $results['emailaddress'];
    				echo "</td><td>";	
                    echo $results['phonenumber'];
    				echo "</td><td>";		
                    echo $results['mobilenumber'];
    				echo "</td><td>";		
                    echo '£' . $results['amountloan'];
    				echo "</td><td>";		
                    echo $results['term'];
    				echo "</td><td>";
                    echo $results['homeowner'];
    				echo "</td><td>";
                    echo date("d/m/Y", strtotime($results['loanappdate']));
    				echo "</td><td>";
    				echo '<a onClick=\"javascript: return confirm("Are you sure you wish to delete this applicant?");\" href="delete.php?id=<?= $row["id"]; ?>">Delete</a></td>';
    				echo "</tr>";	
    				echo "</table>";
    				
    		   }
    		 }
    	?>
    

    Thank you in advance

  6. Hello

     

    I am struggling with some coding, I need a script to check if a url stored in my database is indexed in Google and if it is to display a green check image and if it is not then to display a red cross image, below is the code I have that I found by doing some searching

    function indexed($url) {
        $url = 'http://webcache.googleusercontent.com/search?q=cache:' . urlencode($url);
        
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Chrome 10');
        
        if (!curl_exec($ch)) {
            // var_dump('failed');
            return false;
        }
        
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        // var_dump($code);
        return $code == '200';
    }
    

    below is the whole code I have but is displaying an error and all the urls pulled from the database have a red cross but am sure they are indexed in Google

    ini_set('display_startup_errors', 1);
    ini_set('display_errors', 1);
    error_reporting(-1);
    
    // connect to the database
    include('connect-db.php');
    
    function indexed($url) {
        $url = 'http://webcache.googleusercontent.com/search?q=cache:' . urlencode($url);
        
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Chrome 10');
        
        if (!curl_exec($ch)) {
            // var_dump('failed');
            return false;
        }
        
        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        // var_dump($code);
        return $code == '200';
    }
    
    // get the records from the database
    if ($result = $mysqli->query("SELECT id, category, url, DATE_FORMAT(domain_expiry_date, '%d/%m/%Y') AS domain_expiry_date, site_login_url, site_username_login, site_password_login, no_of_posts, tf, cf, domain_name_owner, DATE_FORMAT(domain_owner_dob, '%d/%m/%Y') AS domain_owner_dob, domain_owner_address, domain_owner_email, domain_owner_phone, email_account, email_account_address, email_username, email_password, registrar, registrar_username, registrar_password, hosting_company, hosting_username, hosting_password, DATE_FORMAT(hosting_expiry_date, '%d/%m/%Y') AS hosting_expiry_date, hosting_cpanel_url, hosting_cpanel_username, hosting_cpanel_password, sites_linked_out_to, DATE_FORMAT(last_post_date, '%d/%m/%Y') AS last_post_date FROM websites"))
    
    {
    // display records if there are records to display
    if ($result->num_rows > 0)
    {
    	
    // display records in a table
    echo "<table class='records'>";
    
    // set table headers
    echo '<tr>
    <th>URL</th>
    <th>Indexed</th>
    
    </tr>';
    
    while ($row = $result->fetch_object())
    {
    	
    	$index = indexed($row->url);
    	
    	// set up a row for each record
    echo "<tr>";
    echo "<td class='expand'><a href='http://" . $row->url . "' target='_blank'>" . $row->url . "</a></td>";
    echo "<td class='shrink'><img src='images/" . (($index->indexed) ? 'green-check.png' : 'red-cross.png') . "' style='width: 30px; height: 30px;'></td>";
    echo "</tr>";
    }
    
    echo "</table>";
    
    // retrieve and show the data 
    
    }
    
    // if there are no records in the database, display an alert message
    else
    {
    echo "No results to display!";
    }
    
    }
    
    // show an error if there is an issue with the database query
    else
    {
    echo "Error: " . $mysqli->error;
    }
    
    // close database connection
    $mysqli->close();
    

    Notice: Trying to get property of non-object in /home/cloudnetworkhero/public_html/network/websites-info/indexed.php on line 54

  7. Hi, I have a update, I have been playing around with the script and have now managed to get it to send the email and update just the records that have dates that are going to expire in 7 days but it don't seem to be looping through to check all dates and include multiple dates in the email, can someone check my coding please as my email only includes one date where as it should include two dates

     

    my code is below

     



    <?php

    $db = mysqli_connect("localhost" , "", "") or die("Check connection parameters!");
    // Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)
    mysqli_select_db($db,"") or die(mysqli_error($db));

    if (mysqli_connect_error()) {
    die ('Failed to connect to MySQL');
    } else {
    /*SUCCESS MSG*/
    echo '';
    }

    $sqlCommand = "SELECT
    u.id
    , domain_name_owner
    , url
    , DATE_FORMAT(domain_expiry_date, '%e %M %Y') as domain_expiry_date
    , domain_owner_email
    FROM websites u
    WHERE domain_expiry_date BETWEEN CURDATE() AND CURDATE()+INTERVAL 7 DAY
    ";

    $query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));

    $current_visitor=0;
    $current_email = '';
    $headers = "From: noreply@domain.co.uk\r\n";
    $subject = "Domain Name Expiry Date(s)";
    $message = '';

    //fetch the data from the database
    while ($row = mysqli_fetch_array($query)) {

    $arr_ids[] = $row['id'];

    // has visitor_id changed
    if ($row['id'] != $current_visitor) {
    // send email to current visitor
    if ($current_visitor != 0) {
    $to = $current_email;
    $sendmail = mail($to, $subject, $message, $headers);
    if ($sendmail) {
    echo nl2br($message);
    echo "<b>Email Successfully Sent</b><br><br>";
    } else {
    echo "<b>Error in Sending of Email to $to</b><br><br>";
    }
    }
    $current_visitor = $row['id'];
    $current_email = $row['domain_owner_email'];
    $message = "Domain Name Owner: {$row['domain_name_owner']} \n\n";

    }
    $message .= "Your Domain Name {$row['url']} expiry date is: {$row['domain_expiry_date']}\n";

    }
    // send email to final visitor
    if ($current_visitor != 0) {
    $to = $current_email;
    $sendmail = mail($to, $subject, $message, $headers);
    if ($sendmail) {
    echo nl2br($message);

    echo "<b>Email Successfully Sent</b><br><br>";
    } else {
    echo "<b>Error in Sending of Email to $to</b><br><br>";
    }

    if (isset($arr_ids)){
    $sql = "UPDATE websites SET date_notified_of_domain_expiry = NOW() WHERE id IN (";
    $sql .= implode("," , $arr_ids);
    $sql .= ");";
    print $sql;

    }

    //$db->query($sql);
    $db->query($sql) or die(mysqli_error($db));

    // Free the results
    mysqli_free_result($query);

    //close the connection
    mysqli_close($db);
    }
    ?>

  8. I have been having a go bit more with the coding and have now the following and it is updating the date_notified_of_domain_Expiry column now but is doing it for all records and not just the one row that the email has been sent out for, below is my updated coding

    $sqlCommand = "SELECT 
            u.id
            , domain_name_owner
            , url
            , DATE_FORMAT(domain_expiry_date, '%e %M %Y') as domain_expiry_date
            , domain_owner_email
            FROM websites u
            WHERE domain_expiry_date BETWEEN CURDATE() AND CURDATE()+INTERVAL 7 DAY
    		";
    
    $id = 'id';
    	
    	$sql = "UPDATE websites SET date_notified_of_domain_expiry = NOW() WHERE id = $id";
    	print $sql;
    

    I just can't get it to update only the one row for the date is within 7 days, it should be only updating row 4 but instead is updating all rows 1-4

     

    do I need another where clause in after $id so would be AND second where clause

  9. I have been playing around with the coding and now got the following code

    $sql = "UPDATE websites SET date_notified_of_domain_expiry = NOW() WHERE id = '" . $row['id'] . "'";
    	print $sql;
    

    the error has gone and on the page, it is outputting the following

     

    UPDATE websites SET date_notified_of_domain_expiry = NOW() WHERE id = ''

     

    it's just the where clause that needs sorting so it only updates the rows that the email gets pinged out for and not all the rows/records

     

    at the mo it is not updating the date_notified_of_domain_expiry column with the current date and time

  10. Thank you for replying

     

    I changed the coding to the following and it is producing the following error

    //$db->query($sql);
    $db->query($sql) or die(mysqli_error($db));
    

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

     

    the query I have is below

    $sql = "UPDATE websites SET date_notified_of_domain_expiry = NOW() WHERE id = " . $row['id'];
    
  11. Hi

     

    I am using the php email reminder script that I had help with when was doing the script and have got the email sending out after bit of tweaking to suit this new project but the date notified column is not updating to the current date and time, below is the coding I have so far

    <?php
    ini_set('display_startup_errors',1);
    ini_set('display_errors',1);
    error_reporting(-1);
    ?>
    
    <html>
    <title>Automatic Email</title>
    <body>
    
    <?php
    
    $db = mysqli_connect("" , "", "") or die("Check connection parameters!"); 
    // Optionally skip select_db and use: mysqli_connect(host,user,pass,dbname)  
    mysqli_select_db($db,"") or die(mysqli_error($db));
    
    if (mysqli_connect_error()) {
        die ('Failed to connect to MySQL');
    } else {
    	/*SUCCESS MSG*/
    	echo '';
    }
    
    $sqlCommand = "SELECT 
            u.id
            , domain_name_owner
            , url
            , DATE_FORMAT(domain_expiry_date, '%e %M %Y') as domain_expiry_date
            , domain_owner_email
            FROM websites u
            WHERE domain_expiry_date BETWEEN CURDATE() AND CURDATE()+INTERVAL 7 DAY
            ";
    		
    $query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db));
    
    //fetch the data from the database 
    
    $current_visitor=0;
    $current_email = '';
    $headers = "From: noreply@domain.co.uk\r\n";    
    $subject = "Domain Name Expiry Date(s)";
    $message = '';
    $renewals = array();
    $notifications = array();
    
    //fetch the data from the database 
    while ($row = mysqli_fetch_array($query)) {
    	
    	// has visitor_id changed
    	if ($row['id'] != $current_visitor) {
    		// send email to current visitor
    		if ($current_visitor != 0) {
    			$to = $current_email;
    			$sendmail = mail($to, $subject, $message, $headers);
    			if ($sendmail) {
    				echo nl2br($message);
    			    echo "<b>Email Successfully Sent</b><br><br>";
    			    // success, so add renewal ids to notifications
    			    $notifications = array_merge($notifications,$renewals);
    			} else { 
    			    echo "<b>Error in Sending of Email to $to</b><br><br>";
    			}
    		}
    		$current_visitor = $row['id'];
    		$current_email = $row['domain_owner_email'];
    		$message = "Domain Name Owner: {$row['domain_name_owner']} \n\n";
    		$renewals = array();
    	}
    	$message .= "Your Domain Name {$row['url']} expiry date is: {$row['domain_expiry_date']}\n";
    
    }
    // send email to final visitor
    if ($current_visitor != 0) {
    	$to = $current_email;
    	$sendmail = mail($to, $subject, $message, $headers);
    	if ($sendmail) {
    		echo nl2br($message);
    		
    		echo "<b>Email Successfully Sent</b><br><br>";
    		// success, so add to notifications
    		$notifications = array_merge($notifications,$renewals);
    	} else { 
    		echo "<b>Error in Sending of Email to $to</b><br><br>";
    	}
    	
    	$sql = "UPDATE websites SET date_notified_of_domain_expiry = NOW() WHERE id = " . $row['id'];
    	
    }
    
    
    // update successful notifications
    $id = $notifications;
    
    $db->query($sql) ;
    
    // Free the results  
    mysqli_free_result($query);
    
    //close the connection
    mysqli_close($db);
    ?>
    
    </body>
    </html>
    

    I do need to the script to email out when a domain name is due to expire in 7 days

     

    Sorry have tried to solve it on my own

  12. Sorry I have gone a different way with it and using a text input field instead rather than text boxes but got one little issue, each time I load the page I get this notice

     

    Notice: Undefined index: search in /home/broadway/public_html/admin/product-keys-sold/search-by-software-title.php on line 53

     

    but as soon as I do a search, the notice disappears, below is the new coding I have

     



    <form action="" method="post">
    <input type="text" name="search">
    <input type="submit" name="submit" value="Search">
    </form>

    <?php

    $servername = 'localhost';
    $username = 'dbuser';
    $password = 'password';
    $dbname = 'dbtable';

    $search_value= $_POST['search'];

    $con=new mysqli($servername,$username,$password,$dbname);

    if($con->connect_error){
    echo 'Connection Faild: '.$con->connect_error;

    }else{
    $sql="select id, software_title, customers_email, DATE_FORMAT(date_purchased, '%d/%m/%Y') AS date_purchased, sent from product_keys_sold where software_title LIKE '%$search_value%' ORDER BY id";

    $res=$con->query($sql);

    // display records in a table
    echo "<table class='records'>";

    // set table headers
    echo "<tr>
    <th>ID</th>
    <th>Software Title</th>
    <th>Customers Email</th>
    <th>Date Purchased</th>
    <th>Sent</th>
    <th colspan='2'>Actions</th>
    </tr>";

    while($row=$res->fetch_assoc()){
    echo "<tr>";
    echo "<td><a href='view-specific-product-keys-sold.php?id=" . $row['id'] . "'>".$row['id'] . "</a></td>";
    echo '<td>' . $row["software_title"]; '</td>';
    echo '<td>' . $row["customers_email"]; '</td>';
    echo '<td>' . $row["date_purchased"]; '</td>';
    echo '<td>' . $row["sent"]; '</td>';
    echo "<td><a href='add-update-keys-sold.php?id=" . $row['id'] . "'>Edit</a></td>";
    echo "<td><a href='delete.php?id=" . $row['id'] . "'>Delete</a></td>";
    echo "</tr>";
    }

    echo '</table>';

    }

    ?>


     

    the form works perfect, just need to get rid of that notice, I know I have error reporting on and I know the notice will prob not show when I remove the error reporting but will be nice to get the coding right first

  13. Hi

     

    I am trying to filter data pulled in from the database but can't seem to get it working, I want it to show filtered product titles when I check a checkbox, I am using php, mysqli and ajax

     

    I am not getting any errors displaying, below is my coding

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
    <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
    
    <?php
        $db=new mysqli('localhost','dbuser','dbpassword','dbname');
        $all_row=$db->query("SELECT * FROM tablename");
    ?>
    
    <form id="search_form">
        <div class="well">
        <h4 class="text-info">Search by Size</h4>
        <input value="32" class="sort_rang" name="software_title[]"  type="checkbox"> Microsoft Office Professional Plus 2010
        <input value="36" class="sort_rang" name="software_title[]"  type="checkbox"> Microsoft Office Professional Plus 2013
        </div>
        </form>
    </p>
    
    <div class="ajax_result">
    <?php if(isset($all_row) && is_object($all_row) && count($all_row)): $i=1;?>
    <?php foreach ($all_row as $key => $software_title) { ?>       
    <div class="col-sm-3 col-md-3">
    <div class="well">
    <h2 class="text-info"><?php echo $software_title['software_title']; ?></h2>
    <p><span class="label label-info">Software Title : 
    <?php echo $software_title['software_title']; ?></span></p>                      
    <hr>
    </div>
    </div>        
    <?php } ?>
    <?php endif; ?>
    </div>
    
    <script type="text/javascript">
    $(document).on('change','.sort_rang',function(){
       var url = "ajax-search.php";
       $.ajax({
         type: "POST",
         url: url,
         data: $("#search_form").serialize(),
         success: function(data)
         {                  
            $('.ajax_result').html(data);
         }               
       });
      return false;
    });
    </script>
    

    Below is my ajax-search.php coding

    <?php
        $db=new mysqli('localhost','dbuser','dbpassword','dbname');
        $sql="SELECT * FROM dbtablename";
        extract($_POST);
        if(isset($size)) 
            $sql.=" WHERE software_title IN (".implode(',', $software_title).")";
        $all_row=$db->query($sql);
    ?>
    <?php if(isset($all_row) && is_object($all_row) && count($all_row)): $i=1;?>
        <?php foreach ($all_row as $key => $software_title) { ?>       
        <div class="col-sm-3 col-md-3">
            <div class="well">
                <h2 class="text-info"><?php echo $software_title['software_title']; ?></h2>
                <p><span class="label label-info">Software Title :
                 <?php echo $software_title['software_title']; ?></span></p>         
                <hr>
            </div>
        </div>
       <?php } ?>
    <?php endif; ?> 

    Can anyone help me please?

     

    Thank you in advance

  14. Hi


     


    I need some help please, I have a form that stores data in the db but now I would like to be able to store a filepath in a db table and the actual txt file on the server, I have managed to get the filepath stored in the db but the file does not upload on the server


     


    also once that is done, I would like to download that txt file that relates to the id number of the record data added to the db


     


    hope that makes sense, below is the coding I have



    <?php

    ini_set('display_startup_errors', 1);
    ini_set('display_errors', 1);
    error_reporting(-1);

    require_once("../session.php");

    require_once("../class.user.php");
    $auth_user = new USER();


    $user_id = $_SESSION['user_session'];

    $stmt = $auth_user->runQuery("SELECT * FROM users WHERE user_id=:user_id");
    $stmt->execute(array(":user_id"=>$user_id));

    $userRow=$stmt->fetch(PDO::FETCH_ASSOC);

    ?>

    <?php
    /*
    Allows the user to both create new records and edit existing records
    */

    // connect to the database
    include("connect-db.php");

    // creates the new/edit record form
    // since this form is used multiple times in this file, I have made it a function that is easily reusable
    function renderForm($service = '', $website_design_price = '', $seo_price = '', $textfiles = '', $error = '', $id = '')
    { ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>
    <?php if ($id != '') { echo "Edit Price List"; } else { echo "New Price List"; } ?>
    </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="css/admin-styles.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <h1><?php if ($id != '') { echo "Edit Contact"; } else { echo "New Contact"; } ?></h1>
    <?php if ($error != '') {
    echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error
    . "</div>";
    } ?>

    <form action="" method="post" class="basic-grey" enctype="multipart/form-data">
    <div>
    <?php if ($id != '') { ?>
    <input type="hidden" name="id" value="<?php echo $id; ?>" />
    <p>ID: <?php echo $id; ?></p>
    <?php } ?>

    <label>Service: *</label> <input type="text" name="service" value="<?php echo $service; ?>"/>
    <br/>
    <label>Website Design Price: *</label> <input type="text" name="website_design_price" value="<?php echo $website_design_price; ?>"/>
    <br>
    <label>SEO Price: *</label> <input type="text" name="seo_price" value="<?php echo $seo_price; ?>"/>
    <br>
    <label>text file for this category: *</label> <input type="hidden" name="size" value="350000"> <input type="file" name="textfile">
    <p>* required</p>
    <br>
    <input type="submit" name="submit" value="Submit" />
    </div>
    </form>
    </body>
    </html>

    <?php }

    /*

    EDIT RECORD

    */

    // if the 'id' variable is set in the URL, we know that we need to edit a record
    if (isset($_GET['id']))
    {
    // if the form's submit button is clicked, we need to process the form
    if (isset($_POST['submit']))
    {
    // make sure the 'id' in the URL is valid
    if (is_numeric($_POST['id']))
    {

    //This is the directory where images will be saved
    $target = "/home/sites/broadwaymediadesigns.co.uk/public_html/admin/price-list/txtfileuploads/";
    $target = $target . basename( $_FILES['textfile']['name']);

    // get variables from the URL/form
    $id = $_POST['id'];
    $service = htmlentities($_POST['service'], ENT_QUOTES);
    $website_design_price = htmlentities($_POST['website_design_price'], ENT_QUOTES);
    $seo_price = htmlentities($_POST['seo_price'], ENT_QUOTES);
    $textfiles = ($_FILES['textfile']['name']);

    // check that firstname and lastname are both not empty
    if ($service == '' || $website_design_price == '' || $seo_price == '')
    {
    // if they are empty, show an error message and display the form
    $error = 'ERROR: Please fill in all required fields!';
    renderForm($service, $website_design_price, $seo_price, $error, $id);
    }
    else
    {
    // if everything is fine, update the record in the database
    if ($stmt = $mysqli->prepare("UPDATE pricelist SET service = ?, website_design_price = ?, seo_price = ?, textfile = ? WHERE id=?"))
    {
    $stmt->bind_param("ssssi", $service, $website_design_price, $seo_price, $textfiles, $id);
    $stmt->execute();
    $stmt->close();
    }

    //Writes the photo to the server
    if(move_uploaded_file($_FILES['textfile']['tmp_name'], $target))
    {
    echo "Uploaded and added all ok";
    }

    // show an error message if the query has an error
    else
    {
    echo "ERROR: could not prepare SQL statement.";
    }

    // redirect the user once the form is updated
    header("Location: view-price-list.php");
    }
    }
    // if the 'id' variable is not valid, show an error message
    else
    {
    echo "Error!";
    }
    }
    // if the form hasn't been submitted yet, get the info from the database and show the form
    else
    {
    // make sure the 'id' value is valid
    if (is_numeric($_GET['id']) && $_GET['id'] > 0)
    {
    // get 'id' from URL
    $id = $_GET['id'];

    // get the recod from the database
    if($stmt = $mysqli->prepare("SELECT * FROM pricelist WHERE id=?"))
    {
    $stmt->bind_param("i", $id);
    $stmt->execute();

    $stmt->bind_result($id, $service, $website_design_price, $seo_price, $textfiles);
    $stmt->fetch();

    // show the form
    renderForm($service, $website_design_price, $seo_price, $textfiles, NULL, $id);

    $stmt->close();
    }
    // show an error if the query has an error
    else
    {
    echo "Error: could not prepare SQL statement";
    }
    }
    // if the 'id' value is not valid, redirect the user back to the view.php page
    else
    {
    header("Location: view-price-list.php");
    }
    }
    }

    /*

    NEW RECORD

    */
    // if the 'id' variable is not set in the URL, we must be creating a new record
    else
    {
    // if the form's submit button is clicked, we need to process the form
    if (isset($_POST['submit']))
    {

    // This is the directory where images will be saved
    $target = "txtfileuploads";
    $target = $target . basename( $_FILES['textfile']['name']);

    // get the form data
    $service = htmlentities($_POST['service'], ENT_QUOTES);
    $website_design_price = htmlentities($_POST['website_design_price'], ENT_QUOTES);
    $seo_price = htmlentities($_POST['seo_price'], ENT_QUOTES);
    $textfiles = ($_FILES['textfile']['name']);

    // check that firstname and lastname are both not empty
    if ($service == '' || $website_design_price == '' || $seo_price == '')
    {
    // if they are empty, show an error message and display the form
    $error = 'ERROR: Please fill in all required fields!';
    renderForm($service, $website_design_price, $seo_price, $error);

    }
    else
    {
    // insert the new record into the database
    if ($stmt = $mysqli->prepare("INSERT pricelist (service, website_design_price, seo_price, textfile) VALUES (?, ?, ?, ?)"))
    {
    $stmt->bind_param("ssss", $service, $website_design_price, $seo_price, $textfiles);
    $stmt->execute();
    $stmt->close();
    }
    // show an error if the query has an error
    else
    {
    echo "ERROR: Could not prepare SQL statement.";
    }

    // redirec the user
    header("Location: view-price-list.php");
    }

    }
    // if the form hasn't been submitted yet, show the form
    else
    {
    renderForm();
    }
    }

    // close the mysqli connection
    $mysqli->close();
    ?>

    Thank you in advance


     


    Ian


  15. Hi

    I need bit of help, I want to display the total amount earned in a month for the past three months

    I am sort of there but got stuck

    I want the page to look like the following

    Profit in April: £amount
    Profit in May: £amount
    Profit in June: £amount

    the mysql columns I need adding together are the following, I know how to do this part

    deposit_paid
    rembl_paid_amount

    the bit I am stuck on is the following

    I got a mysql column called date_deposit_paid and date_rembl_paid and am unsure how to get the data added from them two date fields so for example if a deposit is paid in May and the remaining balance is paid in June, I need the amounts to show under the correct month, below is the coding I have

    <?php 
    $mysqli = new mysqli('localhost','password', 'db'); 
    
    $sql = "SELECT MONTHNAME(date_deposit_paid) as month, MONTHNAME(date_rembl_paid) as month, SUM(deposit_paid + rembl_paid_amount) as total FROM projects  
    WHERE date_deposit_paid AND date_rembl_paid BETWEEN LAST_DAY(CURDATE()) + INTERVAL 1 DAY - INTERVAL 3 MONTH AND LAST_DAY(CURDATE()) 
    GROUP BY YEAR(date_deposit_paid), MONTH(date_deposit_paid), YEAR(date_rembl_paid), MONTH(date_rembl_paid) 
    ORDER BY MONTH(date_deposit_paid), MONTH(date_rembl_paid) ASC"; 
    $result = $mysqli->query($sql); 
    
    if ($result->num_rows > 0) { 
        while($row = $result->fetch_assoc()) { 
        echo "<tr> 
        <td>".'Profit Made in '.$row["month"]."</td> 
        <td>" . '£' .$row["total"]."</td> 
        </tr>"; 
        } 
    } else { 
        echo "0 results"; 
    } 
    $mysqli->close(); 
    ?>
    

    Hope it makes sense

    Thank you in advance

×
×
  • 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.