Help Needed: Combining PHP & Amazon Web Services for Midterm Project

Click For Summary

Discussion Overview

The discussion revolves around integrating PHP with Amazon Web Services (AWS) for a midterm project that involves creating a search form for Amazon books. Participants are exploring how to properly append user input to a URL for querying AWS and returning results to a webpage.

Discussion Character

  • Technical explanation
  • Homework-related
  • Exploratory

Main Points Raised

  • One participant describes their initial PHP script that captures a search keyword from a form but struggles to append it to a URL for AWS.
  • Another participant points out a syntax error in the PHP script, specifically a missing semicolon, and suggests using the concatenation operator to append the search keyword to the URL.
  • A later reply confirms the changes made to the PHP script and asks if anything else might be missing, indicating ongoing uncertainty.
  • One participant inquires whether the shebang line is included at the top of the PHP file, which is a common requirement for executing PHP scripts on certain servers.
  • A participant expresses relief after receiving help, indicating a personal struggle with the task due to a headache.

Areas of Agreement / Disagreement

Participants generally agree on the need to correctly format the PHP script and append the search keyword to the URL, but there remains uncertainty about whether additional issues exist in the implementation.

Contextual Notes

Participants have not fully resolved the functionality of the script, and there may be additional dependencies or requirements for the AWS query that are not discussed.

Math Is Hard
Staff Emeritus
Science Advisor
Gold Member
Messages
4,663
Reaction score
36
I am working on my midterm project and I have two pieces I can't put together with php.
I am supposed to create a form that let's a user enter a keyword to search Amazon books, so I have the form that catches the data and gives it to the php file:
http://www.pic.ucla.edu/~jctaylor/midterm.htm
the php is just this:
Code:
#!/usr/local/bin/php
<?php 
echo $_GET["hello"]; 
?>
"hello" is the variable that hold the entered search keyword.

I need the php script to append that keyword to a long URL that goes to Amazon web services and gets the books, and then returns the content to the div in my HTML.
I have a page with a link that will go get the books. I hard coded the search word "Oprah" in the query. (note: this only works correctly in firefox, as far as I know).
http://www.pic.ucla.edu/~jctaylor/getbooks.htm

Anyway..
I'm not sure how to make php append the keyword, get the data, and send it back.

Any tips? I am pretty lost. Thanks.
 
Last edited by a moderator:
Technology news on Phys.org
Here is something I tried in the php, just to try to get some content from Amazon back, but it didn't work:
Code:
#!/usr/local/bin/php
<?php 
$url="http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=06XN0NB7DG5T94WYZCR2&Operation=ItemSearch&ResponseGroup=Medium,Request&SearchIndex=Books&BrowseNode=1000&Sort=salesrank&Style=http://www.pic.ucla.edu/~jctaylor/midterm.xsl&Keywords=Oprah"

$xml=file_get_contents($url);

echo $xml; 
?>
 
Last edited by a moderator:
You're missing a ";" on your php script in the following line:
Code:
$url="[URL]http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=06XN0NB7DG5T94WYZCR2&Operation=ItemSearch&ResponseGroup=Medium,Request&SearchIndex=Books&BrowseNode=1000&Sort=salesrank&Style=http://www.pic.ucla.edu/~jctaylor/midterm.xsl&Keywords=Oprah"[B];[/B][/URL]

You want your PHP script to retrieve the "hello" variable from the querystring and append it to the URL. You use isset($_GET["hello"]) to check if the "hello" variable has a value.
To append the value to your amazon URL you concatenate the value to the $url variable using the "." (the concatenation operator):
Code:
<?php 
$kwords = "";
if(isset($_GET["hello"])) $kwords = $_GET["hello"];
$url="http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=06XN0NB7DG5T94WYZCR2&Operation=ItemSearch&ResponseGroup=Medium,Request&SearchIndex=Books&BrowseNode=1000&Sort=salesrank&Style=http://www.pic.ucla.edu/~jctaylor/midterm.xsl&Keywords=" . $kwords;

$xml=file_get_contents($url);

echo $xml; 
?>
 
Last edited by a moderator:
Thanks so much, Job!
Is there anything else I am missing? I am still having some trouble with it.

I made a new version here:
http://www.pic.ucla.edu/~jctaylor/midterm1.htm

and made changes to midterm1.php:
Code:
<?php 
$kwords = "";
if(isset($_GET["hello"])) $kwords = $_GET["hello"];
$url="http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=06XN0NB7DG5T94WYZCR2&Operation=ItemSearch&ResponseGroup=Medium,Request&SearchIndex=Books&BrowseNode=1000&Sort=salesrank&Style=http://www.pic.ucla.edu/~jctaylor/midterm.xsl&Keywords=" . $kwords;

$xml=file_get_contents($url);

echo $xml; 
?>
 
Last edited by a moderator:
Did you include the following line at the top of the file?
Code:
#!/usr/local/bin/php
 
Oh God! I'm an idiot! I had not put it in there. I am about blind from a severe headache today.

Job, I love you. You've saved me! I owe you big time!
 
Glad to help.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
7K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 2 ·
Replies
2
Views
9K
Replies
1
Views
4K
Replies
2
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 15 ·
Replies
15
Views
26K
  • · Replies 2 ·
Replies
2
Views
5K