# Need php advice

Staff Emeritus
Gold Member

## Main Question or Discussion Point

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 lets 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: ## Answers and Replies Related Programming and Computer Science News on Phys.org Staff Emeritus Science Advisor Gold Member 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="[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"[/URL]

$xml=file_get_contents($url);

echo $xml; ?> Last edited by a moderator: -Job- Science Advisor 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="[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="[/URL] .$kwords;

$xml=file_get_contents($url);

echo $xml; ?> Last edited by a moderator: Staff Emeritus Science Advisor Gold Member 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="[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="[/URL] . $kwords;$xml=file_get_contents($url); echo$xml;
?>

Last edited by a moderator:
-Job-
Did you include the following line at the top of the file?
Code:
#!/usr/local/bin/php

Staff Emeritus