Jump to content
tunnelboy

Two near identical scripts. One works, one doesn't

Recommended Posts

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>
?>

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 by NotionCommotion

Share this post


Link to post
Share on other sites

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.