I would like to ask for help. I got this homework to create a class in PHP with search method which returns 50 pictures from Flickr, but without use of official PHP Flickr libraries... Anyway with help of google I wrote following code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
class Flickr {
private $apiKey = 'aba429532a6606f2ee35e3f47a300716';
public function search($query = null) {
$search = 'http://flickr.com/services/rest/?method=flickr.photos.search&api_key=' . $this->apiKey . '&text=' . urlencode($query) . '&per_page=50&format=php_serial';
$result = file_get_contents($search);
$result = unserialize($result);
return $result;
}
}
?>
<form action="index.php" method="get">
<input type="text" name="text1" /><br />
<input type="submit" name="submit1" value="Send" /><br />
</form>
<?php
if(isset($_GET["submit1"])) {
$Flickr = new Flickr;
$data = $Flickr->search($_GET["text1"]);
foreach($data['photos']['photo'] as $photo) {
echo '<img src="http://farm' . $photo["farm"] . '.static.flickr.com/' . $photo["server"] . '/' . $photo["id"] . '_' . $photo["secret"] . '.jpg">';
}
}
?>
</body>
</html>
That code does what I need, but I am not sure whether I can use flickr.photos.search, so I was wondering if there is a way to avoid using flickr.photos.search.
You could just request http://www.flickr.com/search/?q={work_by_witch_you_search}&z=m pictures from here with curl and just parse received page. Then you definitely wount use anything even close to Flickr API.
Related
I'm running an Apache server on MAMP on macOSX. The problem I've occurred is that every variable is receiving the filter_input() but the last one, "param". I've tried using $_POST['param']; to no avail. I've restarted the Apache server but nothing has changed. I'm sure it's a syntax error, but all the other questions on here are unrelated and unhelpful. The one "PHP form not receiving inputs" was no help at all. Any help is appreciated :)
EDIT: I've realized using filter_input(INPUT_POST, "param") was not needed since I don't provide a filter, and that $_POST["param"] is a more acceptable method.
My HTML:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Code Writer (JAVA)</title>
</head>
<body>
<center>
<h1>Code Writer (JAVA)</h1>
</center>
<form action="backwards.php" method="post">
<fieldset>
<label>Enter visibility level (public/private/etc)</label>
<input type="text" name="first"><br>
<label>Static Method? Y/N</label>
<input type="text" name="static"><br>
<label>Enter return type (int/double/etc)</label>
<input type="text" name="return"><br>
<label>Enter method name?</label>
<input type="text" name="method"><br>
<label>Paramaters, if any</label>
<input type="text" name="param"><br>
<button type="submit">Submit</button>
</fieldset>
</form>
</body>
</html>
My PHP:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>backwards.php</title>
</head>
<body>
<?php
#Gather inputs
$first = filter_input(INPUT_POST, "first");
$static = filter_input(INPUT_POST, "static");
$return = filter_input(INPUT_POST, "return");
$method = filter_input(INPUT_POST, "method");
$param = filter_input(INPUT_POST, "param");
#Add to $output
$output = $first . " ";
if ($static == "Y") {
$output .= "static" . " ";
}
$output .= $return . " ";
$output .= $method . "(";
$output .= $param;
$output .= ") {} \n";
#Print $output
print($output);
?>
</body>
</html>
Turns out that right after running the website with #John Conde's comment "var_dumb($_POST)", it started working. Removing the var_dump and it still works, although I am confused as to why. The matter is resolved, but I'm still confused as to why it works now, and not before.
This has been asked before but no solution given.
I have created an account with https://datamarket.azure.com/account/keys and I have a primary account key and a customer id.
I got the code below from https://msdn.microsoft.com/en-gb/library/dd440739.aspx
I have tried replacing <yourAppIdHere> with the values of both the primary account key and the customer id, but in each case get Invalid argument supplied for foreach().
What am I missing here? Please help.
<html>
<head>
<link href="styles.css" rel="stylesheet" type="text/css" />
<title>PHP Bing</title>
</head>
<body><form method="post" action="<?php echo $PHP_SELF;?>">
Type in a search:<input type="text" id="searchText" name="searchText" value="<?php
if (isset($_POST['searchText'])){
echo($_POST['searchText']); }
else { echo('sushi');}
?>"/>
<input type="submit" value="Search!" name="submit" id="searchButton" />
<?php
if (isset($_POST['submit'])) {
$request = 'http://api.search.live.net/json.aspx?Appid=<YourAppIDHere>&sources=image&query=' . urlencode( $_POST["searchText"]);
$response = file_get_contents($request);
$jsonobj = json_decode($response);
echo('<ul ID="resultList">');
foreach($jsonobj->SearchResponse->Image->Results as $value)
{
echo('<li class="resultlistitem"><a href="' . $value->Url . '">');
echo('<img src="' . $value->Thumbnail->Url. '"></li>');
}
echo("</ul>");
} ?>
</form>
</body>
</html>
I want to create trello teams automatically via an html form from my website.
I wrote a php script that seems to work. For example I can get list of boards or create a new board. But it does not works to create teams.
HTML CODE
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="api_method.php" method="post">
Project Name:<br>
<input type="text" name="projectName" value="board_test">
<br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called "api_method.php".</p>
</body>
</html>
I then use a php script to create the new board:
<?php
require("trello_api.php");
$key = 'mykey';
$token = 'mytoken';
$trello = new trello_api($key, $token);
$data = $trello->request('GET', ('member/me/boards'));
$obj = array('name' => $_POST['projectName']);
$trello->request('POST', ('/boards'),$obj);
echo "Board name: " . $data[0]->name . "\n \n";
echo "New board: " . $_POST['projectName'];
?>
So that works perfectly but not when I try to do the same thing with "organizations" it doesn't work
$trello->request('POST', ('/organizations'),$obj);
Can you please help me.
I found the solution, I had to use the option "displayName" instead of "name"
<?php
require("trello_api.php");
$key = 'myKey';
$token = 'myToken';
$trello = new trello_api($key, $token);
$data = $trello->request('GET', ('member/me/boards'));
$obj = array('displayName' => $_POST['projectName']);
$trello->request('POST', ('/organizations'),$obj);
echo "Board name: " . $data[0]->name . "\n \n";
echo "New board: " . $_POST['projectName'];
?>
By default on my web service I must make a post request to custom user's url. I can post the array but I would like to post request as a json payload, the code below could be the post data, but I cannot get the data from PHP.
function redirect_to_customer($result = [], $redirect_url = "")
{
$html = '<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body onload="closethisasap();">
<form name="redirectpost" method="POST" action="' . $redirect_url . '">
';
if (!is_null($result)) {
$result = json_encode($result);
$html .= '<input type="hidden" value="' . str_replace('"', "'", $result) . '"> ';
}
$html .= "
</form>
</body>
<script type=\"text/javascript\">
function closethisasap() {
document.forms[\"redirectpost\"].submit();
}
</script>
</html>";
echo $html;
}
result of this code is :
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
</head>
<body onload = "closethisasap();">
<form name = "redirectpost" method = "POST" action = "http://www.sample.com/response.php">
<input type = "hidden" value = "{'code':'-103','message':'order_id must be unique'}">
</form>
</body>
<script type = "text/javascript">
function closethisasap()
{
document . forms["redirectpost"] . submit();
}
</script>
</html>
response.php user's file content :
<?php
print_r($_POST);
?>
after post data i get empty array
All inputs including <input type = "hidden" need a name, so name = "something".
I cannot seem to retrieve the data input into this text area. Also I know this code may not be secure, but I am just beginning with php.
echo '<tr><td align=right>Description:</td><td><textarea name=description form=description cols=100 rows=5></textarea></td></tr>';
$descriptionToSend = $("#description").val()
DBSubmit("INSERT INTO Conference (conferenceid,description,submission_due,review_due) VALUES ('".$_POST['conferenceName']."', '" . $descriptionToSend . "','" .$_POST['submitdeadline'] . "','" .$_POST['reviewdeadline']. "')");
Are you mixing up jquery with php ?
First, the <textarea> should reside in a <form>
After the form is submitted to php, you can access the data sent with $_REQUEST['description'] so you would have
$descriptionToSend = $_REQUEST['description'];
<html>
<head>
<title>Test</title>
</head>
<body>
<?php $name = 'nick';
?>
<form action="Test.php">
Name: <input type="text" name="name" value="<?php echo $name; ?>">
About Me: <textarea name="about" rows="5" cols="10"><?php echo $comment; ?></textarea><br/>
Click Me: <input type="submit" vaule="submit">
</body>
</html>
Use $comment to set text and then just retrieve value using $_GET['about'] in next page
<html>
<body>
<?php
$about = $_GET['about'];
echo $about;
?>
</body>
</html>