0

I built a WhatsApp Chatbot , which takes the value from backend and sends the reply for example in below image.

Chat WhatsappBot

i got a message from bot , and i have to select anyone of them either 1,2 or 3 . When i choose 1 . it gives me a reply .if i chose 3 for the last message in screenshot. it gives me reply of the first message which is General Info . But what i want is reply for Request Status Student.

$sql = "SELECT  `Reply` ,`IsTemplate` FROM `ChatReply` WHERE UPPER(Message) = '".strtoupper($text)."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $replyMessageAfterUpdate = rawurlencode($row['Reply']);
             $curl = curl_init();
             curl_setopt_array($curl, array(
                 CURLOPT_URL => 'ABCD/CallBackURL',
                 CURLOPT_RETURNTRANSFER => true,
                 CURLOPT_ENCODING => '',
                 CURLOPT_MAXREDIRS => 10,
                 CURLOPT_TIMEOUT => 0,
                 CURLOPT_FOLLOWLOCATION => true,
                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                 CURLOPT_CUSTOMREQUEST => 'POST',
                 CURLOPT_POSTFIELDS => 'userid=209932442&password=$$hdys99@&method=SendMessage&auth_scheme=plain&v=1.1&send_to='.$mobile.'&msg='.$replyMessageAfterUpdate,
                 CURLOPT_HTTPHEADER => array(
                     'Content-Type: application/x-www-form-urlencoded'
                 ),
             ));
             $response = curl_exec($curl);
             $err = curl_error($curl);
             curl_close($curl);
             echo $response;
             if (curl_errno($ch)) {
                 $error_msg = curl_error($ch);
             }
    }
}

So May i know how will i achieve that .

So what i want is something like below What needed

but for me , since it is stored in Database , if i select 1 it will retrieve reply of first message creating a loop . Can anyone please help me with this .

  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman May 20 '22 at 11:20

0 Answers0