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 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大