Am getting an error on my php code to send sms

Am a newbie and i am getting an error on line 26 of my code i cant understand what causes the error as it is making me not to be able to send sms anyhelp will be appreciated

     $con = mysql_connect("localhost","db_host","xxxxxx");

         if (!$con)
         die('Could not connect: ' . mysql_error());

         mysql_select_db("aic_sms", $con);

     $result = mysql_query("SELECT phn_number FROM users WHERE message=$value");
     while($row = mysql_fetch_array($result)) {
         function sendSmsMessage($phn_number, $message)
            $ch= curl_init();
        curl_setopt($ch, "$phn_number&msg=" . urlencode($message));

    else {
       echo mysql_error();

   echo 'Message sent successfully';    



Ok, first off you have a function within a loop this will cause the function tobe defined twice then kill your script, with functions you define them once then use the function name to execute the code within the function, also the actual curl function you are using wont work as your not setting the correct options.

Plus you should use prepared query's to execute SQL statements, as in your current script you are vulnerable to sql injection, someone malicious could post someval OR 1=1 this would cause mysql to return everything as 1=1 which is true.

Heres how you should perhaps do it and build appon it. Hope it helps

if($_SERVER['REQUEST_METHOD']=='POST' && !empty($_POST['value']) && !empty($_POST['message'])){

    $value  = $_POST['value'];
    $message= $_POST['message'];

    try {
        $dbh = new PDO("mysql:host=localhost;dbname=aic_sms", 'username', 'password');

        $stmt = $dbh->prepare("SELECT phn_number FROM users WHERE message=:message");

        /*** bind the paramaters ***/
        $stmt->bindParam(':message', $value, PDO::PARAM_STR);

        /*** execute the prepared statement ***/

        /*** fetch the results ***/
        while($row = $stmt->fetch())
            $result[$row['phn_number']] = sendSmsMessage($row['phn_number'], $message);
        //perhaps do somthing with the $result array
        echo 'Messages sent successfully';   
    catch(PDOException $e)
    //Show form or whatever

function sendSmsMessage($phn_number, $message){
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "$phn_number&msg=" . urlencode($message));
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_TIMEOUT, 30);

    $html = curl_exec($curl);

    return $html;

Need Your Help

Reading Text File Data and writing to TextArea

java swing applet awt scrollpane

So I have a few basic questions that are probably going to be very simple for you guys. Keep in mind, I am not a programmer. I'm just a low-level IT support person who took a few programming course...

jQuery insertbefore


I have the following: