Search code examples
phpubuntu-12.04gammu

error run php script in ubuntu server terminal


I'm really confuse right now..i make this php script to send sms with gammu and put it in my home directory

<?php
mysql_connect("localhost","username","password") or die("failed");
mysql_select_db("database1") or die("Database Failed");
$not_send = mysql_query("SELECT * FROM outbox WHERE status=0");
while($sending = mysql_fetch_array($not_send)){
    $msg_id = $sending['id'];
    $text = "gammu --sendsms TEXT ".$sending['phoneNum']." -text ".$sending['content'];
    $sms = shell_exec($text);
    if(preg_match("/ok/im", $sms)){
        mysql_query("DELETE FROM outbox WHERE id = '$msg_id'");
    }
}
?>

I already confirm the $text output with echo $text, but when i run it in terminal with php send_sms.php it always say unexpected '('

can anyone tell me whats wrong here??Or i cant put run php script outside /var/www/?? please help me..


Solution

  • I solved this problem thankx to @zerkms..I just dont quote the $sending['content'] part in the earlier code...

    so this is the new code:

    <?php
    mysql_connect("localhost","username","password") or die("failed");
    mysql_select_db("database1") or die("Database Failed");
    $not_send = mysql_query("SELECT * FROM outbox WHERE status=0");
    while($sending = mysql_fetch_array($not_send)){
        $msg_id = $sending['id'];
        $text = "gammu --sendsms TEXT ".$sending['phoneNum']." -text '".$sending['content'."'"];
        $sms = shell_exec($text);
        if(preg_match("/ok/im", $sms)){
            mysql_query("DELETE FROM outbox WHERE id = '$msg_id'");
        }
    }
    ?>
    

    if you have same problem hope search engine find this...once again thank you zerkms