Jump to content

Extent of knowledge exhausted. Any ideas on this script?


PHPClueless

Recommended Posts

Firstly thank you for looking at this issue. I have very basic understanding on HTML and even less of PHP. I have set up two files on a test server with an API send to a SMS broadcast however the test messages are not displaying the data entered in the HTML form. 

 

I am sure the issue is probably incorrect formatting but I have sat here for two hours trying combinations without success.  

 

Basically I need a HTML form that an operator enters data and it sends this in a SMS via API using a PHP script. There is more I need to do to this script but If i get the basics issue here answered I might be able to navigate my way through :)

 

Please see below:

 

HTML FORM:

 

<html>
<body>
 
<form action="xy2p1.php" method="get">
 
Pick Up Date: <input type="text" name='date'><br>
Pick Up Time: <input type="text" name='time'><br><br>
Pickup Address: <input type="text" name='pua'><br>
Drop Of Address: <input type="text" name='doa'><br>
Passenger: <input type="text" name='passenger'><br>
No of Pax : <input type="text" name='pax'><br>
 
<input type="submit">
</body>
</form>
</html>
 
now this should send the data to the PHP file which is named as per the form action above.
 
PHP FILE
 
<?php
    function sendSMS($content) {
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec ($ch);
        curl_close ($ch);
        return $output;    
    }
 
    $username = 'xxxxx';
    $password = 'xxxx';
    $destination = 'xxxx'; 
    $source    = 'SampleCompany';
    $text = 'date','time','pua','doa','passenger','pax';
    $ref = 'abc123';
        
    $content =  'username='.rawurlencode($username).
                '&password='.rawurlencode($password).
                '&to='.rawurlencode($destination).
                '&from='.rawurlencode($source).
                '&message='.rawurlencode($text).
                '&ref='.rawurlencode($ref);
  
    $smsbroadcast_response = sendSMS($content);
    $response_lines = explode("\n", $smsbroadcast_response);
    
     foreach( $response_lines as $data_line){
        $message_data = "";
        $message_data = explode(':',$data_line);
        if($message_data[0] == "OK"){
            echo "The message to ".$message_data[1]." was successful, with reference ".$message_data[2]."\n";
        }elseif( $message_data[0] == "BAD" ){
            echo "The message to ".$message_data[1]." was NOT successful. Reason: ".$message_data[2]."\n";
        }elseif( $message_data[0] == "ERROR" ){
            echo "There was an error with this request. Reason: ".$message_data[1]."\n";
        }
    }
?>

 

 

Any ideas where i am going wrong?

 

Thanks!

 

 

Link to comment
Share on other sites

 

You should be more specific. What exactly does the script do? Crash? Show an error message? Send a wrong SMS? The var_dump() function is very helpful for analyzing variables and figuring out what's going on.

 

What is this line supposed to do:

$text = 'date','time','pua','doa','passenger','pax';

 

Thanks for your reply!

 

The script sends the data to an API for SMSbroadcast.com.au to send out to my drivers. 

 

The stock PHP from SMS Broadcast is:

 

<?php

    function sendSMS($content) {

        $ch curl_init('https://api.smsbroadcast.com.au/api-adv.php');

        curl_setopt($chCURLOPT_POSTtrue);

        curl_setopt($chCURLOPT_POSTFIELDS$content);

        curl_setopt($chCURLOPT_RETURNTRANSFERtrue);

        $output curl_exec ($ch);

        curl_close ($ch);

        return $output;    

    }

 

    $username 'USERNAME';

    $password 'PASSWORD';

    $destination '0400000000'//Multiple numbers can be entered, separated by a comma

    $source    'MyCompany';

    $text 'This is our test message.';

    $ref 'abc123';

        

    $content =  'username='.rawurlencode($username).

                '&password='.rawurlencode($password).

                '&to='.rawurlencode($destination).

                '&from='.rawurlencode($source).

                '&message='.rawurlencode($text).

                '&ref='.rawurlencode($ref);

  

    $smsbroadcast_response sendSMS($content);

    $response_lines explode("\n"$smsbroadcast_response);

    

     foreach( $response_lines as $data_line){

        $message_data "";

        $message_data explode(':',$data_line);

        if($message_data[0] == "OK"){

            echo "The message to ".$message_data[1]." was successful, with reference ".$message_data[2]."\n";

        }elseif( $message_data[0] == "BAD" ){

            echo "The message to ".$message_data[1]." was NOT successful. Reason: ".$message_data[2]."\n";

        }elseif( $message_data[0] == "ERROR" ){

            echo "There was an error with this request. Reason: ".$message_data[1]."\n";

        }

    }

?>

 

What I need is the various fields entered in the HTML to be combined on in the $text field as sent out as a message. I hope this makes sense. 

Link to comment
Share on other sites

So the only line of code you've written yourself is the one I've already asked you about:

$text = 'date','time','pua','doa','passenger','pax';

Long story short: This is not valid code. Like every language, PHP has a specific syntax, and if you want your code to run, you need to learn and apply those syntax rules. Codeacademy has a crash course for PHP which can help you with that.

 

I'm guessing you want string concatenation:

$text = $_GET['date'].' '.$_GET['time'].' '.$_GET['pua'];    // ... and so on

But again, you have to learn the syntax.

 

Blank pages also mean you haven't set up a proper test environment. Install XAMPP (or similar software) on your PC, then make PHP display all errors directly on the screen.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.