PHPClueless Posted December 4, 2016 Share Posted December 4, 2016 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) { $ch = curl_init('https://api.smsbroadcast.com.au/api-adv.php'); 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! Quote Link to comment https://forums.phpfreaks.com/topic/302679-extent-of-knowledge-exhausted-any-ideas-on-this-script/ Share on other sites More sharing options...
Jacques1 Posted December 4, 2016 Share Posted December 4, 2016 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'; Quote Link to comment https://forums.phpfreaks.com/topic/302679-extent-of-knowledge-exhausted-any-ideas-on-this-script/#findComment-1540021 Share on other sites More sharing options...
PHPClueless Posted December 4, 2016 Author Share Posted December 4, 2016 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($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 = '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. Quote Link to comment https://forums.phpfreaks.com/topic/302679-extent-of-knowledge-exhausted-any-ideas-on-this-script/#findComment-1540022 Share on other sites More sharing options...
PHPClueless Posted December 4, 2016 Author Share Posted December 4, 2016 It does not give me an error message just a blank screen with the url http://xyz.com/xy2p1.php?date=asd&time=asd&pua=sad&doa=sad&passenger=&pax= If I use the basic PHP script it will work but I obviously need more functionality. Quote Link to comment https://forums.phpfreaks.com/topic/302679-extent-of-knowledge-exhausted-any-ideas-on-this-script/#findComment-1540023 Share on other sites More sharing options...
Jacques1 Posted December 4, 2016 Share Posted December 4, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/302679-extent-of-knowledge-exhausted-any-ideas-on-this-script/#findComment-1540024 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.