0

A user enters two dates periods on a text-box and a SQL select statement picks mobile numbers from a database entered in between the period. I want to pick and display them on a page. On the same display page, I have a text area where a user can type a message and on submit, it should be sent to these selected numbers and displayed mobile numbers. I am having a challenge on passing the $mobilenumber and message to the function sendbulk that is to send the message. Everything else is okay apart from passing the two. Check sample code below and please advice. How do I pass $mobilenumber and $message to the function sendbulk()? Anyone?

<?php

sendbulk();
// conection

$sql =  "SELECT DISTINCT msisdn FROM customer WHERE DATE_FORMAT(time_paid, '%Y-%c-%e') BETWEEN ADDDATE('$time1',INTERVAL 0 HOUR) AND ADDDATE('$time2',INTERVAL '23:59' HOUR_MINUTE)";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
   // display the number of records
  echo " Recipients: ";  echo "$result->num_rows <br> <br>";

 // output data of each row
    while($row = $result->fetch_assoc()) {
 $mobilenumber = $row['msisdn'];
       //display the records
      echo "Mobile : " . "$mobilenumber" . "<br>";

    }
} else {
    echo "No Contacts to Display";
}
$conn->close();

//validates the message on the text area
if ($_SERVER["REQUEST_METHOD"] == "POST") {

  $message = test_input($_POST['message']);
  echo "$message";
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>
<center></center> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  

  <textarea name='message' rows="6" cols="60" placeholder="Please Type Your Message Here"></textarea>
  <br><br>

  <input type="submit" name="submit" value="Send Message">  
</form></center>

<?php
function sendbulk() {
    global $mobilenumber;
    global $message_sent;
echo "$mobilenumber";
echo "$message_sent";



    $serviceArguments = array(
        "mobilenumber" => $mobilenumber,
        "message" => $message_sent
    );

    $client = new SoapClient("http://******");

    $result = $client->process($serviceArguments);

    return $result;


}
?>

1 Answer 1

1
function_name($variable1, $variable2);

in your example

if ($_SERVER["REQUEST_METHOD"] == "POST") {

   $message = test_input($_POST['message']);
   sendbulk($message);
}

As simple as that

Sign up to request clarification or add additional context in comments.

3 Comments

Hello there, so for my case should be function sendbulk($message, $mobilenumber );
Sorry tried that but seems by the time the page loads the second time the $mobilenumber has lost it is value....how can I save it for the second load
to conserve value of your variable on page load in php you have to make use of php sessions w3schools.com/php/php_sessions.asp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.