Need Some help in simple PHP - php

Hello people i just wanted to ask this that how to do make the below code in PHP
<input type="text" name="SteamID64">
when the person enters and clicks the button then it should fill that value in the below
<?php
$xml=simplexml_load_file("http://steamcommunity.com/profiles/<STEAMID64 HERE>?xml=1");
echo $xml->steamID . "<br>";
echo $xml->onlineState . "<br>";
echo $xml->privacyState . "<br>";
echo $xml->avatarFull . "<br>";
echo $xml->body;
?>
I am sorry if i have done this question wrong i am new here

Use $_POST to get the id:
$format = "http://steamcommunity.com/profiles/%s?xml=1";
$url = sprintf($format, $_POST["SteamID64"]);
$xml=simplexml_load_file($url);
I'm assuming you've got the form set up correctly, something like:
<form action="TheTarget.php" method="post">
<input type="text" name="SteamID64" />
<input type='submit' value='submit' />
</form>

if (isset($_POST['SteamID64'])) {
$id = $_POST['SteamID64'];
$xml = simplexml_load_file("http://steamcommunity.com/profiles/{$id}?xml=1");
}

Related

how to use two form's post value together

I have a form on a page like:
<form action='search.php' method='POST'>
<input type='text' name='specialist' />
<input type='submit' name='submit' />
</form>
on search page there is another form like
<form action='' method='POST'>
<input type='submit' name='anygender' />
</form>
then i am using
if(isset($_POST['anygender'])){
$speciality = $_POST['speciality'];
echo $speciality;
$a = mysql_query("SELECT * FROM find_doctor WHERE doctor_type LIKE '%$speciality%'");
while ($b = mysql_fetch_array($a)){
echo "<img src='$b[image]' height='150px' width='300px'>"."</br>";
echo $b['name']."</br>";
echo $b['doctor_type']."</br>";
echo $b['location']."</br>";
echo $b['insurance']."</br>";
echo $b['comments']."</br>";
echo $b['address']."</br>";
}
}
then $specialist is showing blank and sql query not working..I want to use both form's post value together.Please tell me how to use first form post value in this. Thanks in advance
Why you need two forms?
<form action='index.php' method='POST'>
<input type='text' name='specialist' />
<input type='submit' name='anygender' />
<input type='submit' name='submit' />
</form>
Maybe you can use one form and check buttom?
Use this code. Check $_POST['submit'] in if condition.
if(isset($_POST['submit'])){
$speciality = $_POST['speciality'];
echo $speciality;
$a = mysql_query("SELECT * FROM find_doctor WHERE doctor_type LIKE '%$speciality%'");
while ($b = mysql_fetch_array($a)){
echo "<img src='$b[image]' height='150px' width='300px'>"."</br>";
echo $b['name']."</br>";
echo $b['doctor_type']."</br>";
echo $b['location']."</br>";
echo $b['insurance']."</br>";
echo $b['comments']."</br>";
echo $b['address']."</br>";
}
}

echo with attribute name for query purposes php pdo

<form method="POST" action="include/crud.php" enctype="multipart/form-data" >
<?php
foreach (LoadAnouncements() as $value){
/*echo "<div id='bb'></div>";*/
echo "<hr/>";
echo $value['searchresultwhat'];
echo "<br/>\n";
echo $value['searchresultwhen'];
echo "<br/>\n";
echo $value['searchresultwhere'];
echo "<hr/>";
/*echo "<div id='bb'></div>";*/
}
?>
</form>
I have this form that show an echo is there a way that I can add the attribute name in this echo so I can use it to query the database? I search for ideas if putting attribute to echo is possible but I haven't found anything yet any suggestion is appreciated
You are looking it?
<input type="text" name="searchresultwhat[]" value="<?php echo $value['searchresultwhat']; ?>" />
<input type="text" name="searchresultwhen[]" value="<?php echo $value['searchresultwhen']; ?>" />
<input type="text" name="searchresultwhere[]" value="<?php echo $value['searchresultwhere']; ?>" />
Edited
<?php
echo '<table>';
echo '<tr><th>What </th><th> When</th><th> Where</th><tr>';
foreach (LoadAnouncements() as $value){
echo "<tr><td>".$value['searchresultwhat']."</td>
<td>"$value['searchresultwhen']."</td>
<td>".$value['searchresultwhere']."</td>
</tr>";
}
echo '</table>';
?>
Do you want to add attribute to certain value in PHP? But you can't do it because $value['searchresultwhat'] and others of the kind are simple strings - as is! They can't send separated data (or attributes) with themself.
EDIT:
You can send seprated data about certain value using array:
$value['searchresultwhat'] = array("name", "value");
$value['searchresultwhen'] = array("name2", "2014-09-01");
$value['searchresultwhere'] = array("name3", "kittens");
echo $value['searchresultwhat'][0] . " is " . $value['searchresultwhat'][1];
echo $value['searchresultwhen'][0] . " = " . $value['searchresultwhen'][1];
echo $value['searchresultwhere'][0] . " has " . $value['searchresultwhere'][1];

Getting a value by type="hidden"

In my application I'm printing out searchresults. I want to use those searchresults to send an invite to become a member in that group. I'm printing out those userdata but I'm wondering how I can use those data into another function (sendInvite or something). I have to get the user_id of that people ($row['user_id'] but I don't know how I can get it. I'm thinking about type="hidden" but I never used it before.)
PRINT OUT
<div id="InviteGroupMembers">
<form action="<?php echo $_SERVER['PHP_SELF'] . "?group_id=" .$group_id; ?>" method="post">
<div >
<input type="text" name="btnSearch" placeholder="Add people to group"/>
</div>
<div>
<button type="submit" name="">Add</button>
</div>
</form>
<form action="<?php echo $_SERVER['PHP_SELF'] . "?group_id=" .$group_id; ?>" method="post">
<?php
if (is_object($searchresult))
while ($row = $searchresult -> fetch_array()) {
echo "<div><p class='searchresults'><img src='uploads/" . $row['avatar'] . " " . "' alt='' />" . $row['surname'] . " " . $row['name'] . " " . "<input type='submit' name='btnAddMember'class='addFriendToGroup' value='' /><input type='hidden' name='user_id' value='" . $row['user_id'] . "'/></p></div>"; }
?>
</form>
</div>
PHP
if (isset($_POST["btnSearch"])) {
try {
$searchinput = mysql_real_escape_string($_POST['btnSearch']);
$searchresult = $user -> Search($searchinput);
} catch(exception $e) {
$feedback = $e -> getMessage("no results");
}
}
if (isset($_POST["btnAddMember"])) {
try{
$group_receiver_id = mysql_real_escape_string($_POST['user_id']);
var_dump($group_receiver_id);
}
catch(exception $e) {
$feedback = $e -> getMessage("no results");
}
}
input type hidden would work for you in this instance. The output below is based on it being within php code. Other wise you will need to use php tags within the value attribute.
<input type="hidden" name="user_id" value="$row['user_id']"/>
Then you can just get the post variable on form submission

How to display results from search below the form

i would like to ask if someone could help me with a search query and displaying of the results.
Here is the code...
<?php
// Change the fields below as per the requirements
$db_host="localhost";
$db_username="dasi";
$db_password="**************";
$db_name="dasi";
$db_tb_name="test";
$db_tb_atr_price="price_vat";
$db_tb_atr_cur="currency";
//Now we are going to write a script that will do search task
// leave the below fields as it is except while loop, which will display results on screen
mysql_connect("$db_host","$db_username","$db_password");
mysql_select_db("$db_name");
$query=mysql_real_escape_string($_GET['query']);
$query_for_result=mysql_query("SELECT * FROM $db_tb_name WHERE code like '%".$query."%'");
echo "<h2>Search Results</h2><ol>";
while($data_fetch=mysql_fetch_array($query_for_result))
{
echo "<table border=1>";
echo "<tr><td>" . $data_fetch['code'] . "</td><td>" . $data_fetch['price_vat'] . "</td><td>" . $data_fetch['currency'] . "</td></tr>";
echo "</table>";
}
echo "</ol>";
mysql_close();
?>
In content i added the form ...
<form action="search.php" method="post">
<label>Search For: </label><input name="query" type="text" /><input name="submit" type="submit" value="Start Search" />
</form>
So ... all is working normaly.. i am getting the results, everything is fine. Problem is:
i want to have results displayed below the form itself, not in a new page.
If anyone could help me that would be great. Thank you in advance
P.S.
Well i have no idea how it works actualy but was thinking, isnt there a way where the result can be added into empty div below the form or something like this? I tryed the options above but it dosnt helped.
Save your table in to a variable:
$table = "<h2>Search Results</h2><ol>";
while($data_fetch=mysql_fetch_array($query_for_result))
{
$table .= "<table border=1>";
$table .= "<tr><td>" . $data_fetch['code'] . "</td><td>" . $data_fetch['price_vat'] . "</td><td>" . $data_fetch['currency'] . "</td></tr>";
$table .= "</table>";
}
$table .= "</ol>";
And print it in your template:
<form action="search.php" method="post">
<label>Search For: </label><input name="query" type="text" /><input name="submit" type="submit" value="Start Search" />
</form>
<?php echo $table ?>
Just embed your form code in your search.php and then check for isset($submit) and you are good to go.
<?php
?>
<form action="" method="post">
<label>Search For: </label><input name="query" type="text" /><input name="submit" type="submit" value="Start Search" />
</form>
<?php
if(isset($submit))
{
// Change the fields below as per the requirements
$db_host="localhost";
$db_username="dasi";
$db_password="**************";
$db_name="dasi";
$db_tb_name="test";
$db_tb_atr_price="price_vat";
$db_tb_atr_cur="currency";
//Now we are going to write a script that will do search task
// leave the below fields as it is except while loop, which will display results on screen
mysql_connect("$db_host","$db_username","$db_password");
mysql_select_db("$db_name");
$query=mysql_real_escape_string($_POST['query']);
$query_for_result=mysql_query("SELECT * FROM $db_tb_name WHERE code like '%".$query."%'");
echo "<h2>Search Results</h2><ol>";
while($data_fetch=mysql_fetch_array($query_for_result))
{
echo "<table border=1>";
echo "<tr><td>" . $data_fetch['code'] . "</td><td>" . $data_fetch['price_vat'] . "</td><td>" . $data_fetch['currency'] . "</td></tr>";
echo "</table>";
}
echo "</ol>";
mysql_close();
}
?>
You've got two choices,
Use AJAX to actually get the results to 'collect' the PHP Generated Content and use JavaScript to append it to somewhere on the page.
Place the Search Algorithm and PHP Code at the top of the same page of the form, then use an isset() $_GET or $_POST to check if it's been submitted successfully, save the results & content to be later printed elsewhere.

How to display the selected data from this form?

So this is part of my code :
echo "<form name='whatever' action='next.php' method='get'>";
while($row = mysql_fetch_assoc($qsq))
{
echo"<input type='checkbox' name='choice[]' value='" . $row['question_id'] . "' /> ". `$row['question_text'] . '<br />';`
}
echo"<br>";
echo "<input type='submit' value='submit' /></form>";
What should i do in the next.php ? I'm thinking to put the selected info in an array and display it. Then store the selected results in a table.But i am not sure with the codes.I am beginner in php can someone help me with the coding ?Thanks in advance!
First of all I cleaned up your code a little bit. (Using single quoutes around HTML trributes is uncanny).
echo ('<form name="whatever" action="next.php" method="get">');
while ($row = mysql_fetch_assoc ($qsq)) {
echo ('<input type="checkbox" name="choice[' . $row["question_id"] . ']" value="1" /> ' . $row["question_text"] . '<br />';
}
echo '<br />';
echo '<input type="submit" value="submit" /></form>';
Then you can iterate thru the values with a foreach loop in next.php.
echo ('<ul>');
foreach ($_GET["choice"] as $key => $value){
echo ('<li>' . $key . ' is ticked</li>');
}
echo ('</ul>');
Note that the array's keys hold the real information here,values wil only contain the number 1.
Take a look ath the source of resulting HTML. This is not theonly possible solution but good for learning purposes.

Categories