dtu72460 2017-10-30 14:10
浏览 57

在PHP中的echo按钮的IF-ELSE上插入SMS

I would like to put my send_sms on an if else of two buttons. If a button 'accept' will be clicked, an sms will be sent on an number in the php table containing a message "Accepted". Such as on 'reject' button the message will also be sent to a number but the message will be "Rejected". Please Help..Thank you in advance.

Here's my php code it names app.php

<?php

//connect to database

$con = mysqli_connect('127.0.0.1','root','');

//select database
mysqli_select_db($con, 'appointment');

//select query
$sql = "SELECT * FROM service";

//Execute the query
$records = mysqli_query($con,$sql)

?>
<html>
<head>
<title>Appointment Schedule</title>
</head>

<body>

<table width = "100%" border = "5px" height = "20%">
<tr align = "left">
    <th>First Name</th>
    <th>Middle Name</th>
    <th>Last Name</th>
    <th>Address</th>
    <th>Date</th>
    <th>Time</th>
    <th>Office</th>
    <th>Service</th>
    <th>Contact No.</th>
    <th>Remarks</th>
</tr>
<?php
while($row = mysqli_fetch_array($records))
{
    echo "<tr><form action = 'display.php' method = post>";
    echo "<input type=hidden name=id value='".$row['ID']."'>";
    echo "<td>".$row['fname']."</td>";
    echo "<td>".$row['mname']."</td>";
    echo "<td>".$row['lname']."</td>";
    echo "<td>".$row['address']."</td>";
    echo "<td>".$row['date']."</td>";
    echo "<td>".$row['time']."</td>";
    echo "<td>".$row['office']."</td>";
    echo "<td>".$row['services']."</td>";
    echo "<td><name = number>".$row['contactno']."</td>";
    echo "<td>".$row['remarks']."</td>";

if($row['remarks'] == 'Accepted' || $row['remarks'] == 'Rejected')
{
echo "<td><input type =submit disabled value='Accepted' name=accept>";
echo "<td><input type =submit disabled value='Rejected' name=reject>";
}

else 
{ 

    if echo "<td><input type =submit value='Accepted' name=accept>"; 
    {
        <form method="POST" action="send_sms.php"></form>
    }
    elseif echo "<td><input type =submit value='Rejected' name=reject>"; 
    {
        <form method="POST" action="send_sms1.php"></form>
    }       
}       
    echo "</form></tr>";    
}
?>

</table>
</body>
</html>

Here's my SMS code it names send_sms.php

<?php

//connect to database

$con = mysqli_connect('127.0.0.1','root','');

//select database
mysqli_select_db($con, 'appointment');

$phone= mysql_query("SELECT contactno FROM service");
$message= "Your Appointment was Accepted";

send_sms($phone,$message);

function send_sms($phone, $message) {

$ch = curl_init();
$parameters = array(
'apikey' => '*****', //Your API KEY
'number' => $phone,
'message' => $message,
'sendername' => 'SEMAPHORE'
);
curl_setopt( $ch, CURLOPT_URL,'http://api.semaphore.co/api/v4/messages' );
curl_setopt( $ch, CURLOPT_POST, 1 );

//Send the parameters set above with the request
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $parameters ) );

// Receive response from server
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close ($ch);

//Show the server response
echo "Message Successfully Delivered";
}

?>

Here's the another one php code. It named send_sms1.php

<?php

//connect to database

$con = mysqli_connect('127.0.0.1','root','');

//select database
mysqli_select_db($con, 'appointment');

$phone= mysql_query("SELECT contactno FROM service");
$message= "Your Appointment was Rejected";

send_sms($phone,$message);

function send_sms($phone, $message) {

$ch = curl_init();
$parameters = array(
'apikey' => '******', //Your API KEY
'number' => $phone,
'message' => $message,
'sendername' => 'SEMAPHORE'
);
curl_setopt( $ch, CURLOPT_URL,'http://api.semaphore.co/api/v4/messages' );
curl_setopt( $ch, CURLOPT_POST, 1 );

//Send the parameters set above with the request
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $parameters ) );

// Receive response from server
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close ($ch);

//Show the server response
echo "Message Successfully Delivered";
}

?>

I'll provide a screenshot so that you can easily understand my problem sir/maam.

My table

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog