Jump to content

ianhaney

Members
  • Posts

    330
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by ianhaney

  1. 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
  2. Hi ginerjm Thank you for the reply, appreciate it I ended up using the honeypot spam method that I got from the following link and seems to work http://devgrow.com/simple-php-honey-pot/
  3. Hi I am having bit of a issue with a contact form and captcha code where it is not being validated and working, in my mailer.php script, I just get a blank white page after clicking submit on the contact page below is my contact form script <?php if(!empty($errors)){ echo "<p class='err'>".nl2br($errors)."</p>"; } ?> <div id='contact_form_errorloc' class='err'></div> <form method="POST" name="contact_form" action="mailer.php"> <p> <label for='name'>Name: </label><br> <input type="text" name="name" value='<?php echo htmlentities($name) ?>'> </p> <p> <label for='email'>Email: </label><br> <input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'> </p> <p> <label for='phone'>Phone: </label><br> <input type="text" name="phone" value='<?php echo htmlentities($phone) ?>'> </p> <p> How Did You Find Us? <br /> <select name="foundus" required="required"> <option value="">Select...</option> <option value="Google">Google</option> <option value="Facebook">Facebook</option> <option value="Other">Other</option> </select> </p> <p> <label for='message'>Message: </label><br> <textarea name="message" value='<?php echo htmlentities($message) ?>'></textarea> </p> <br /> <p> <img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br> <label for='message'>Enter the code above here :</label><br> <input id="6_letters_code" name="6_letters_code" type="text"><br> <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small> </p> <br /> <input type="submit" value="Submit" name='submit'> </form> <script language="JavaScript"> // Code for validating the form // Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml // for details var frmvalidator = new Validator("contact_form"); //remove the following two lines if you like error message box popups frmvalidator.EnableOnPageErrorDisplaySingleBox(); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("name","req","Please provide your name"); frmvalidator.addValidation("email","req","Please provide your email"); frmvalidator.addValidation("email","email","Please enter a valid email address"); frmvalidator.addValidation("phone","req","Please provide your phone number"); frmvalidator.addValidation("phone","phone","Please enter a valid phone number"); frmvalidator.addValidation("message","req","Please enter your enquiry"); frmvalidator.addValidation("foundus","req","Please select how you found us"); </script> <script language='JavaScript' type='text/javascript'> function refreshCaptcha() { var img = document.images['captchaimg']; img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000; } </script> below is my mailer.php script <?php error_reporting(E_ALL); ini_set('display_errors', 1); $your_email ='email address';// <<=== update to your email address session_start(); $errors = ''; $name = ''; $visitor_email = ''; $phone = ''; $foundus = ''; $message = ''; if(isset($_POST['submit'])) { if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { //Note: the captcha code is compared case insensitively. //if you want case sensitive match, update the check above to // strcmp() $errors .= "n <div class='contact-text-sitemap'>The captcha code does not match!</div>"; } $name = $_POST['name']; $visitor_email = $_POST['email']; $phone = $_POST['phone']; $foundus = $_POST['foundus']; $message = $_POST['message']; ///------------Do Validations------------- if(empty($name)||empty($visitor_email)||empty($phone)||empty($message)) { $errors .= "\n Name, Email, Phone and Message are required fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email value!"; } if(empty($errors)) { //send the email $to = $your_email; $subject="New Website Enquiry"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Name: $name\n". "Email: $visitor_email \n". "Phone: $phone \n". "How Did You Find Us: $foundus \n". "Message: \n ". "$message\n". $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); header('Location: thank-you.php'); } } // Function to validate against any email injection attempts function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?>
  4. Not sure if I did this right as thought I did it wrong above so did the following var_dump($_POST); on the page that outputs the following array(0) { } If I do the following print_r($_POST); That outputs the following on the page Array ( ) Is that what you was looking for regarding the format?
  5. Ahh ok sorry, have I done this right? echo $_POST['from']; echo $_POST['to']; on the page I get the errors Notice: Undefined index: from in /home/sites/it-doneright.co.uk/public_html/admin/software-sales/search-data.php on line 49 Notice: Undefined index: to in /home/sites/it-doneright.co.uk/public_html/admin/software-sales/search-data.php on line 50 line 49 and 50 is the two echo lines
  6. Hi Sorry for my late reply, do you mean the format in the db table, if so sales_month in the db table is date type and I don't have a from and to in my db table?
  7. I solved the undefined index errors but amending the two lines to the following $a = (isset($_POST['from']) ? $_POST['from'] : null); $b = (isset($_POST['to']) ? $_POST['to'] : null); but that does not return any results when I search for two different dates using the form?
  8. I have made these amendments but know I have got it wrong cause of the error messages but just seeing if am close or how to resolve the error messages, once working I will sort out the sql injection I added in the following above the sql query $a=$_POST['from']; $b=$_POST['to']; I added the following to the query WHERE sales_month BETWEEN '$a' AND '$b' I added the form in as well which is below <form action="search-data.php" method="post"> From : <input type="text" name="from" class="tcal" /> To: <input type="text" name="to" class="tcal" /> <input name="" type="submit" value="Search"> </form> With them amendments, I get the followign error messages Notice: Undefined index: from in /home/sites/it-doneright.co.uk/public_html/admin/software-sales/search-data.php on line 42 Notice: Undefined index: to in /home/sites/it-doneright.co.uk/public_html/admin/software-sales/search-data.php on line 43
  9. Hi I have got search results that display all records from a db table and they are paginated so shows 5 records per page but I need to add a form that allows me to select a from date and a to date and then retrieves the records that are between the from and to date, is that possible to do in php html and mysqli as unsure how to do it please if anyone can help me, below is the code I have so far for the pagination that is working <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); include_once("mysqli_connection.php"); // This first query is just to get the total count of rows $sql = "SELECT COUNT(id) FROM purchased_software"; $r = mysqli_query($con,$sql) or die("Error: ".mysqli_error($con)); $query = mysqli_query($con, $sql); $row = mysqli_fetch_row($query); // Here we have the total row count $rows = $row[0]; // This is the number of results we want displayed per page $page_rows = 5; // This tells us the page number of our last page $last = ceil($rows/$page_rows); // This makes sure $last cannot be less than 1 if($last < 1){ $last = 1; } // Establish the $pagenum variable $pagenum = 1; // Get pagenum from URL vars if it is present, else it is = 1 if(isset($_GET['pn'])){ $pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']); } // This makes sure the page number isn't below 1, or more than our $last page if ($pagenum < 1) { $pagenum = 1; } else if ($pagenum > $last) { $pagenum = $last; } // This sets the range of rows to query for the chosen $pagenum $limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows; // This is your query again, it is for grabbing just one page worth of rows by applying $limit $sql = "SELECT id, customer_pp_email, sales_month, software_title, quantity, total_sale, ebay_fees, paypal_fees, software_cost, profit, notes, status, sold_by FROM purchased_software ORDER BY id DESC $limit"; $query = mysqli_query($con, $sql); // This shows the user what page they are on, and the total number of pages $textline1 = "Sales (<b>$rows</b>)"; $textline2 = "Page <b>$pagenum</b> of <b>$last</b>"; // Establish the $paginationCtrls variable $paginationCtrls = ''; // If there is more than 1 page worth of results if($last != 1){ /* First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page. */ if ($pagenum > 1) { $previous = $pagenum - 1; $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'">Previous</a> '; // Render clickable number links that should appear on the left of the target page number for($i = $pagenum-4; $i < $pagenum; $i++){ if($i > 0){ $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> '; } } } // Render the target page number, but without it being a link $paginationCtrls .= ''.$pagenum.' '; // Render clickable number links that should appear on the right of the target page number for($i = $pagenum+1; $i <= $last; $i++){ $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'">'.$i.'</a> '; if($i >= $pagenum+4){ break; } } // This does the same as above, only checking if we are on the last page, and then generating the "Next" if ($pagenum != $last) { $next = $pagenum + 1; $paginationCtrls .= ' <a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'">Next</a> '; } } $list = ''; while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){ $id = $row["id"]; $customer_pp_email = $row["customer_pp_email"]; $sales_month = strftime("%b %d, %Y", strtotime($sales_month)); $software_title = $row["software_title"]; $quantity = $row["quantity"]; $total_sale = $row["total_sale"]; $ebay_fees = $row["ebay_fees"]; $paypal_fees = $row["paypal_fees"]; $software_cost = $row["software_cost"]; $profit = $row["profit"]; $notes = $row["notes"]; $status = $row["status"]; $sold_by = $row["sold_by"]; $list .= '<p>' . $customer_pp_email . $sales_month . $software_title . $quantity . $total_sale . $ebay_fees . $paypal_fees . $software_cost . $profit . $notes . $status . $sold_by.'</p>'; } // Close your database connection mysqli_close($con); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Search Data Between Two Dates</title> <link rel="stylesheet" type="text/css" media="screen" href="css/styles.css" /> </head> <body> <div id="logo"> <img src="images/logo/it-done-right.jpg" alt="" title=""> </div> <br><br> <?php include("nav-menu.php"); ?> <br><br> <div> <h2><?php echo $textline1; ?> Paged</h2> <p><?php echo $textline2; ?></p> <p><?php echo $list; ?></p> <div id="pagination_controls"><?php echo $paginationCtrls; ?></div> </div> </body> </html> Thank you in advance Ian
  10. Oh right ok, I'll look into cleaning it up
  11. Ahh ok, how would the correct way, sorry, I'll try and google it in the mean time
  12. Hi I am trying to paginate my search results but keep getting the followung error Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/sites/it-doneright.co.uk/public_html/admin/software-sales/search-data.php on line 155 below is the line on 155 $total_records = mysqli_num_rows($exec); below is the whole script <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); session_start(); if ($_SESSION['user']=='') { header("Location:../index.php"); } else { include("../config.php"); $sql = $dbh->prepare("SELECT * FROM users WHERE id=?"); $exec = $sql->execute(array($_SESSION['user'])); $user = $exec ? $sql->fetch() : null; } include('connect.php'); $per_page=5; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; } // Page will start from 0 and Multiple by Per Page $start_from = ($page-1) * $per_page; $data = []; if (isset($_GET['d1']) && isset($_GET['d2'])) { $d1 = strtotime($_GET['d1']); $d2 = strtotime($_GET['d2']); if ($d1 && $d2) { $start_date = date('Y-m-d', $d1); $end_date = date('Y-m-d', $d2); $result = $db->prepare("SELECT * FROM purchased_software WHERE sales_month BETWEEN :a AND :b ORDER BY id LIMIT $start_from, $per_page"); $result->bindParam(':a', $start_date); $result->bindParam(':b', $end_date); $exec = $result->execute(); if ($exec) { $data = $result->fetchAll(); } } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Search Data Between Two Dates</title> <link rel="stylesheet" type="text/css" media="screen" href="css/styles.css" /> <link rel="stylesheet" type="text/css" href="css/tcal.css" /> <script type="text/javascript" src="js/tcal.js"></script> </head> <body> <div id="logo"> <img src="images/logo/it-done-right.jpg" alt="" title=""> </div> <script> var t; window.onload=resetTimer; document.onkeypress=resetTimer; function logout() { alert("You are now logged out."); location.href='../logout.php'; } function resetTimer() { clearTimeout(t); t=setTimeout(logout,1800000) //logs out in 30 minutes } </script> <?php if ($user): ?> <div class='home-content'> <center> <h2>Hello, <?= $user['username']; ?></h2> <a href='../logout.php'>Log Out</a> <br><br> <a href='../index.php'>Home</a> </center> </div> <br> <?php endif; ?> <?php include("nav-menu.php"); ?> <br> <form action="search-data.php" method="get"> From : <input type="text" name="d1" class="tcal" value="" /> To: <input type="text" name="d2" class="tcal" value="" /> <input type="submit" value="Search"> </form> <table class="view-repairs"> <thead> <tr> <th>Software ID</th> <th>Customer PayPal Email</th> <th>Sales Date</th> <th>Software Title</th> <th>Quantity</th> <th>Total Sale</th> <th>Ebay Fees</th> <th>PayPal Fees</th> <th>Cost Price</th> <th>Profit</th> <th>Notes</th> <th>Status</th> <th>Actions</th> </tr> </thead> <tbody> <?php foreach ($data as $row): ?> <tr> <td><a href="view-specific-software-sale.php?id=<?= $row['id']; ?>"><?php echo $row['id']; ?></a></td> <td><?php echo $row['customer_pp_email']; ?></td> <td><?php echo date("d/m/Y", strtotime($row['sales_month'])); ?></td> <td><?php echo $row['software_title']; ?></td> <td><?php echo $row['quantity']; ?></td> <td><?php echo $row['total_sale']; ?></td> <td><?php echo $row['ebay_fees']; ?></td> <td><?php echo $row['paypal_fees']; ?></td> <td><?php echo '£' . $row['software_cost']; ?></td> <td><?php echo '£' . $row['profit']; ?></td> <td><?php echo substr($row['notes'], 0, 25); ?></td> <td><?php echo $row['status']; ?></td> <td><a href="add-update-software-sales.php?id=<?= $row['id']; ?>">Edit</a></td> </tr> <?php endforeach; ?> </tbody> </table> <?php $result = $db->prepare("select * from purchased_software"); $exec = $result->execute(); if ($exec) { $data = $result->fetchAll(); } // Count the total records $total_records = mysqli_num_rows($exec); //Using ceil function to divide the total records on per page $total_pages = ceil($total_records / $per_page); //Going to first page echo "<center><a href='search-data.php?page=1'>".'First Page'."</a>"; for ($i=1; $i<=$total_pages; $i++) { echo "<a href='search-data.php?page=".$i."'>".$i."</a>"; }; // Going to last page echo "<a href='search-data.php?page=$total_pages'>".'Last Page'."</a></center>"; ?> <div class="box-right" style="height: 90px !important"> <div class="box-middle-content"> <?php include('connect.php'); $data = []; if (isset($_GET['d1']) && isset($_GET['d2'])) { $d1 = strtotime($_GET['d1']); $d2 = strtotime($_GET['d2']); if ($d1 && $d2) { $start_date = date('Y-m-d', $d1); $end_date = date('Y-m-d', $d2); $result = $db->prepare("SELECT SUM(profit) FROM purchased_software WHERE sales_month BETWEEN :a AND :b"); $result->bindParam(':a', $start_date); $result->bindParam(':b', $end_date); $exec = $result->execute(); if ($exec) { $data = $result->fetchAll(); } } } foreach ($data as $row): echo 'Total Software Profit for ' . $start_date = date('d-m-Y', $d1) . ' AND ' . $end_date = date('d-m-Y', $d2) . '<br>' . '£' . $row['SUM(profit)']; endforeach; ?> </div> </div> <a href="view-software-sales.php">BACK TO VIEW ALL SOFTWARE SALES</a> </body> </html> Thank you in advance Ian
  13. I have altered the coding slightly to try and get it working but got a undefined index: id error below is the script for send-sms-message.php that the error is on <?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'); } $smsid = $db->real_escape_string($_GET['id']); $sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs WHERE id = '$smsid'"; $query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db)); echo '<form method="get" action="send-sms.php">'; echo '<select>'; echo '<option value="">Choose the mobile number</option>'; while($row= mysqli_fetch_assoc($query)){ echo '<option name="id" value="'.$row['id'].'">'.$row['customer_name'].' - '.$row['customer_phone'].'</option>'; } echo '</select>'; echo '<input type="submit" value="Send SMS">'; echo '</form>'; ?>
  14. I have a update I am not getting any errors now but no data is in the select option menu, below is my send-sms-message.php script <?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'); } $smsid = (isset($_GET['id']) ? $_GET['id'] : null); $sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs WHERE id = '$smsid'"; $query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db)); echo '<form action="send-sms.php" method="post">'; echo '<select>'; echo '<option value="">Choose the mobile number</option>'; while($row= mysqli_fetch_assoc($query)){ echo '<option name="id" value="'.$row['id'].'">'.$row['customer_name'].' - '.$row['customer_phone'].'</option>'; } echo '</select>'; echo '<input type="submit" value="Send SMS">'; echo '</form>'; ?>
  15. I am getting a undefined variable: smsid error on my page below is the script from my send-sms-message.php <? session_start(); if($_SESSION['user']==''){ header("Location:index.php"); }else{ include("config.php"); $sql=$dbh->prepare("SELECT * FROM users WHERE id=?"); $sql->execute(array($_SESSION['user'])); while($r=$sql->fetch()){ echo "<div class='home-content'>"; echo "<center><h2>Hello, ".$r['username']."</h2>"; echo "<a href='logout.php'>Log Out</a></center>"; echo "</div>"; echo "<br>"; } } ?> <?php include("nav-menu.php"); ?> <?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'); } $sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs WHERE id = '" . $smsid . "'"; $query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db)); echo '<form action="send-sms.php" method="post">'; echo '<select name="customer_phone">'; echo '<option value="">Choose the mobile number</option>'; while($row= mysqli_fetch_assoc($query)){ echo '<option value="'.$row['id'].'">'.$row['customer_name'].' - '.$row['customer_phone'].'</option>'; } echo '</select>'; echo '<input type="submit" value="Send SMS">'; echo '</form>'; ?> I made it $smsid as $id is already being used by the checking of the user being logged in or not or can it be used as is a different db table as thought using $id twice might confuse the script if used in different db tables
  16. Hi Thank you for the reply, I have added a WHERE clause in now and listened to the suggesstions you provided and changed the select option value to id instead of customer_phone So in send-sms.php I don't need the while line of code in there, is that right? I will be putting security in once is all working to only admin staff can login, actually I will put that in now
  17. UPDATE: Hi, sorry got a update, it seems to be working now but I think it is looping cause of the while code in the send-sms-message.php and send-sms.php scripts and sending to all numbers and not just the one I choose within the select menu, is it possible just to check the code please below is the send-sms-message.php script <?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'); } $sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs"; $query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db)); echo '<form action="send-sms.php" method="post">'; echo '<select name="customer_phone">'; echo '<option value="">Choose the mobile number</option>'; while($row= mysqli_fetch_assoc($query)){ echo '<option value="'.$row['customer_phone'].'">'.$row['customer_name'].' - '.$row['customer_phone'].'</option>'; } echo '</select>'; echo '<input type="submit" value="Send SMS">'; echo '</form>'; ?> below is the send-sms.php script <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); function sendSMS($username, $password, $customer_phone, $message, $originator) { $URL = 'http://api.textmarketer.co.uk/gateway/'."?username=$username&password=$password&option=xml"; $URL .= "&to=$customer_phone&message=".urlencode($message).'&orig='.urlencode($originator); $fp = fopen($URL, 'r'); return fread($fp, 1024); } $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'); } $sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs"; $query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db)); //fetch the data from the database while ($row = mysqli_fetch_array($query)) { $customer_phone = $row['customer_phone']; if (isset($_POST["submit"])) { //var_dump($customer_phone); } // Example of use $response = sendSMS('DJkGc7', '97q84F', $customer_phone, 'Your PC/Laptop is ready for collection', 'ITDoneRight'); //var_dump($response); } ?>
  18. Sorry, if I hard code the mobile number in as per the script below, the sms works and comes through but need it to send the sms to the mobile number I select from the select menu on the send-sms-message.php page $response = sendSMS('DJkGc7', '97q84F', '447538503276', "Your PC/Laptop is ready for collection", 'ITDoneRight'); Can anyone help me please as am really stuck with it
  19. Hi I have a form with a select menu that is populated by data pulled in from the db and I select a mobile number that I want to send a sms text to but it don't seem to be working, I am using text marketer and their api script. I can't seem to work out why the sms is not being sent, I am not getting any script errors on either file, below is the send-sms-message.php script that has the form in <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); $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'); } $sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs"; $query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db)); echo '<form action="send-sms.php" method="post">'; echo '<select>'; echo '<option value="">Choose the mobile number</option>'; while($row= mysqli_fetch_assoc($query)){ echo '<option value="'.$row['customer_name'].$row['customer_phone'].'">'.$row['customer_name'].' - '.$row['customer_phone'].'</option>'; } echo '</select>'; echo '<input type="submit" value="Send SMS">'; echo '</form>'; ?> Could it be missing a name on select tag so would be <select name="namehere">, sorry just trying to work it out and had that thought pop in my head below is the script from the form action script send-sms.php <?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); function sendSMS($username, $password, $mobnumber, $message, $originator) { $URL = 'http://api.textmarketer.co.uk/gateway/'."?username=$username&password=$password&option=xml"; $URL .= "&to=$mobnumber&message=".urlencode($message).'&orig='.urlencode($originator); $fp = fopen($URL, 'r'); return fread($fp, 1024); } $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'); } $sqlCommand = "SELECT id, customer_name, customer_phone FROM repairs"; $query = mysqli_query($db, $sqlCommand) or die (mysqli_error($db)); //fetch the data from the database while ($row = mysqli_fetch_array($query)) { $mobnumber = $row['customer_phone']; $country_code = '44'; $mobnumber = str_replace(' ', '', $row['customer_phone']); $mobnumber = substr_replace($mobnumber, ''.$country_code, 0, ($mobnumber[0] == '0')); //var_dump($mobnumber); } $message = "Name:".$row['customer_name'] . ' ' . 'Your PC/Laptop is ready for collection'; // Example of use $response = sendSMS('DJkGc7', '97q84F', $mobnumber, "Your PC/Laptop is ready for collection", 'ITDoneRight'); var_dump($response); ?>
  20. Yeah only for the moment cause when I used $_POST it was not adding no data to the db so will take a look tonight and see if I can work it out
  21. Think this is ok, it works as is still adding the data to the database still as I tried other ways but was not adding the data to the db table but this way is, is it suitable enough for sanitizing $item_number = $db->real_escape_string($_GET['item_number']); $txn_id = $db->real_escape_string($_GET['tx']); $payment_gross = $db->real_escape_string($_GET['amt']); $currency_code = $db->real_escape_string($_GET['cc']); $payment_status = $db->real_escape_string($_GET['st']);
  22. Ignore that post it is wrong
  23. Regarding the first statement, is it as simple as changing $_GET to $_POST and changing the form method to post instead of get Regarding statement 2, is the following good enough as sanitization $item_number = filter_var($_GET['item_number'], FILTER_SANITIZE_ITEM_NUMBER); $txn_id = filter_var($_GET['tx'], FILTER_SANITIZE_TX); $payment_gross = filter_var($_GET['amt'], FILTER_SANITIZE_AMT); $currency_code = filter_var($_GET['cc'], FILTER_SANITIZE_CC); $payment_status = filter_var($_GET['st'], FILTER_SANITIZE_ST); I also changed the values to be single quotes instead of the mess it was and does look neater with less opening and closing of php tags as is no need for them to be opening closing many times
  24. Think I sorted it, it seems to be storing the info again I was thinking I wonder if is cause I closed the php tags and opened it again after the session start code, seems to be ok now touch wood, I now have the following and seems to be working, I also changed $id to $memberid just in case it was that was getting confused with another one called id somewhere <?php session_start(); $title = "PayPal Success - Security Site"; include ( 'includes/header.php' ); include 'db-connect.php'; $memberid = $_SESSION["memberID"]; // store the user id into session $name = $_SESSION["name"]; // store the user id into session $email = $_SESSION["email"]; // store the user id into session //Store transaction information from PayPal $item_number = $_GET['item_number']; $txn_id = $_GET['tx']; $payment_gross = $_GET['amt']; $currency_code = $_GET['cc']; $payment_status = $_GET['st']; //Get product price $productResult = $db->query("SELECT price FROM products WHERE id = ".$item_number); $productRow = $productResult->fetch_assoc(); $productPrice = $productRow['price']; if(!empty($txn_id) && $payment_gross == $productPrice){ //Insert tansaction data into the database $insert = $db->query("INSERT INTO payments(memberID,name,email,item_number,txn_id,payment_gross,currency_code,payment_status) VALUES('".$memberid."','".$name."','".$email."','".$item_number."','".$txn_id."','".$payment_gross."','".$currency_code."','".$payment_status."')"); $last_insert_id = $db->insert_id; echo "<h1>Your payment has been successful.</h1>"; echo "<h1>Your Payment ID - <?php echo $last_insert_id; ?>.</h1>"; } // get the records from the database if ($insert = $db->query("SELECT employers.memberID, employers.name, employers.email, payments.payment_id, payments.payment_status FROM employers INNER JOIN payments ON employers.memberID = payments.memberID WHERE employers.memberID='$id'")); if ($payment_status == Completed) { header("Location: http://www.broadwaymediadesigns.co.uk/sites/security-site/payg-job-advert.php"); }else{ header("Location: http://www.broadwaymediadesigns.co.uk/sites/security-site/employer-profile.php"); } ?> <?php include( 'includes/footer.php' ); ?>
  25. They do seem to be storing the correct info in the session or do you mean they could be getting confused with something else and not storing the info in the session so is unable to save the data to the payments db table
×
×
  • 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.