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

In summary, the conversation is about a person working on their midterm project and needing help with their PHP script. They need to create a form that allows a user to search for books on Amazon using a keyword, and then have the PHP script append the keyword to a URL that goes to Amazon web services. The person shares their code and asks for tips, and someone helps them by pointing out a missing semicolon and providing a corrected version of the code. The person expresses gratitude and the conversation ends with them realizing they forgot to include a crucial line at the top of their file.
  • #1
Math Is Hard
Staff Emeritus
Science Advisor
Gold Member
4,652
37
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
  • #2
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:
  • #3
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:
  • #4
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:
  • #5
Did you include the following line at the top of the file?
Code:
#!/usr/local/bin/php
 
  • #6
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!
 
  • #7
Glad to help.
 

1. What is the purpose of combining PHP and Amazon Web Services for a midterm project?

The purpose of combining PHP and Amazon Web Services is to create a dynamic and scalable web application. PHP is a popular server-side scripting language that is widely used for web development, while Amazon Web Services (AWS) provides a wide range of cloud-based services, including hosting, storage, and database management. The combination of these two technologies allows for the creation of a powerful and efficient web application that can handle large amounts of traffic and data.

2. What are some benefits of using PHP for a midterm project?

PHP offers several benefits for web development, including its ease of use, extensive documentation, and large community support. It also allows for quick prototyping and has a wide range of built-in functions and libraries that can help with tasks such as database access and file management. Additionally, PHP is a free and open-source language, making it accessible to all developers.

3. How can AWS be useful for a midterm project?

AWS offers a variety of services that can be useful for a midterm project, such as hosting, storage, and database management. These services are highly scalable, allowing the project to handle increased traffic and data as needed. AWS also provides reliable and secure infrastructure, freeing up developers to focus on building the application rather than managing servers.

4. Can any other programming languages be used instead of PHP for this project?

Yes, there are other programming languages that can be used for this project, such as Python, Java, or Node.js. However, PHP is a popular choice for web development due to its simplicity and compatibility with databases. Additionally, the AWS SDK (Software Development Kit) for PHP makes it easy to integrate AWS services into a PHP application.

5. Is prior experience with PHP and AWS necessary for working on this project?

While prior experience with PHP and AWS can be helpful, it is not necessary for working on this project. Both PHP and AWS have extensive documentation and resources available online, making it easy for developers to learn and use these technologies. Additionally, there are many tutorials and guides available that can help beginners get started with using PHP and AWS for web development.

Similar threads

  • Programming and Computer Science
Replies
7
Views
6K
  • Programming and Computer Science
Replies
6
Views
6K
  • Programming and Computer Science
Replies
2
Views
9K
Replies
1
Views
3K
Replies
2
Views
888
Replies
1
Views
1K
  • Quantum Physics
Replies
9
Views
5K
Replies
15
Views
24K
  • General Discussion
Replies
2
Views
2K
Back
Top