Search code examples
phpsqlapiadminwhatsapp

php whatsapp link with variable


I would like to do the following in my webpage:

  1. users submit a form then write the date into phpmyadmin. It is ok for me.
  2. then the webpage automatically open whatsapp and start the conversation in whatsapp with some text.

Now I can start the whatapp conversation but no text! Please help.

here with my code:

                            $txt = " happy ";
                            $link = "<meta http-equiv=REFRESH CONTENT=1;url='https://wa.me/85265648596?text=$txt'>";

                                    $sql = "insert into Enrol (`Name`, `Tel`, `Year`, `Enquiry`) values ('$Name', '$Tel', '$Year', '$Enquiry')";


                                            if ($conn->query($sql) === TRUE)
                                            {

                                                echo $txt;

                                                echo $link;


                                            }

Solution

  • Notice how it already works, if your text does not contain a space at the beginning …?

    You need to properly URL-encode the value, if it contains “special” characters.

    $link = "<meta http-equiv=REFRESH CONTENT=1;url='https://wa.me/85265648596?text=" .
               urlencode($txt) . "'>";