tunnelboy Posted May 20, 2020 Share Posted May 20, 2020 Trying to create a very simple API script sending XML data. When I send the "hard coded" XML, it works perfectly. When I add a form to supply the data for the XML, I get a 500 Internal Server error. Have tried it on two different servers. No error in the logs. Stumped. Examples below are VERY simplified (and obviously won't do anything as-is) to show what I'm dealing with. This one works fine: <?php $xml = "<Order><UserId>foo</UserId><Password>foo</Password><Mode>Test</Mode><Name>Charles R. Hodges</Name>"; $xml .= "</Order>"; $url = 'http://sitename.com'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($response); print_r($xml); ?> And then I use this one and all heck breaks loose with the 500 Internal Error: <?php if (isset($_POST['submit'])) { $xml = "<Order><UserId>foo</UserId><Password>foo</Password><Mode>Test</Mode><Name>{$_POST['name']}</Name>"; $xml .= "</Order>"; $url = 'http://sitename.com'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($response); print_r($xml); exit; } ?> <html>... etc <form method="post" action=""> Name: <input type="text" name="name" /> <p><input type="submit" name="submit" "Add to XML string and send" /> </form> ?> Quote Link to comment https://forums.phpfreaks.com/topic/310818-two-near-identical-scripts-one-works-one-doesnt/ Share on other sites More sharing options...
requinix Posted May 20, 2020 Share Posted May 20, 2020 A 500 means there's something wrong with your script. Could be a syntax error. But it's really hard to spot syntax errors when you only post "very simplified" code. Do you know how to configure php.ini settings on your server(s)? Change display_errors to "on" and error_reporting to -1. Then restart your web server and/or PHP and try running your script again. There should be error messages this time. Quote Link to comment https://forums.phpfreaks.com/topic/310818-two-near-identical-scripts-one-works-one-doesnt/#findComment-1578215 Share on other sites More sharing options...
NotionCommotion Posted May 21, 2020 Share Posted May 21, 2020 (edited) I assume the errors being generated the API's server, and not yours. True? Have you tried adding lines like syslog(LOG_INFO, $xml); to make sure they reflect what you expected? Edited May 21, 2020 by NotionCommotion Quote Link to comment https://forums.phpfreaks.com/topic/310818-two-near-identical-scripts-one-works-one-doesnt/#findComment-1578237 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.