Getting radio input from selection in table - php

I'm trying to get my code to open a page that displays a picture of the model and displays information. the code uses a csv file that populates the table. I cant seem to figure out how to get my radio button to pass data based on selection. I'm trying to find the selected row and display the data on another page basically. any help would be appreciated. Thank you!
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<h1>Choose One</h1>
<form action="index.php" method="post">
<label for="Type">Package Type</label>
<select name="Type">
<option value="">Choose...</option>
<option value="a">apple</option>
<option value="b">google</option>
<option value="c">oneplus</option>
<option value="d">Samsung</option>
</select>
<input type="Submit" >
</form>
<?php
echo "<html><body><table border = '1'>\n\n";
echo "<form action='stock.php' method='post' name='stock'>";
echo "<th>Item</th><th>Manufacturer</th><th>Model</th><th>Price</th>";
$myfile = fopen("phones.csv", "r");
$ind=0;
$ind++;
while (($dataarray = fgetcsv($myfile)) !== false)
{
echo "<tr><td>"."<input type = 'radio' name='manufacturer' id=manufacturer
value=$dataarray[$ind]>"."</td>";
foreach ($dataarray as $cell)
{
echo "<td>" . htmlspecialchars($cell) . "</td>";
}
echo "</tr>\n";
$ind = 0;
}
fclose($myfile);
echo "\n</table>
<input type='submit'>
</form></body></html>";
$ind = 0;
?>
</body>
</html>
Start of stock.php
<!DOCTYPE html>
<html lang="en">
<head>
<form action="index.php" method="get" name="stock">
</form>
<php?
if(isset($_get[manufacturer]))
{
$value=$_get[manufacturer];
}
?>
</head>
<body>
</body>
</html>
This is a snip of the csv file:

Related

Why can't I unselect the last option in multiselect after I save it to a session variable?

I have a multi-select which saves the currently selected options using a session variable. However when I un-select all options, the last selected option stays. How do I fix this? Here is my code:
<!DOCTYPE html>
<?php
session_start();
if(isset($_POST['occupation']))
$_SESSION['occupation'] = $_POST['occupation'];
?>
<html>
<head>
</head>
<body>
<form method="post" action="">
<h2>Industy</h2>
<select name="occupation[]" multiple >
<?php
$occ = array("Accounting", "Education", "Healthcare", "Information Technology", "Retail", "Sales");
$len = count($occ);
for($i = 0; $i<$len; $i++ )
{
if(in_array($occ[$i], $_SESSION['occupation']))
echo '<option value="' . $occ[$i] . '" selected>' . $occ[$i] .'</option>';
else
echo '<option value="' . $occ[$i] . '" >' . $occ[$i] .'</option>';
}
?>
</select>
<br/><br/>
<button type="submit" value="Search" class="my-button" name="search_button" >Search</button>
</form>
</body>
</html>
Just add to your code that if you submitted without any value, just overwrite the session array empty.
Here's the idea:
<?php
session_start();
$occ = array("Accounting", "Education", "Healthcare", "Information Technology", "Retail", "Sales");
if (empty($_SESSION['occupation'])) { // initialize
$_SESSION['occupation'] = array();
}
if(isset($_POST['search_button'])) { // if submitted
// set session occupation else just set empty
$_SESSION['occupation'] = !empty($_POST['occupation']) ? $_POST['occupation'] : array();
}
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form method="post" action="">
<h2>Industy</h2>
<select name="occupation[]" multiple>
<?php foreach ($occ as $o) { ?>
<option value="<?php echo $o; ?>" <?php echo in_array($o, $_SESSION['occupation']) ? 'selected' : ''; ?>>
<?php echo $o; ?>
</option>
<?php } ?>
</select>
<br/><br/>
<button type="submit" value="Search" class="my-button" name="search_button" >Search</button>
</form>
</body>
</html>

PHP: How to popualate list from sqlite table

I want to populate my Php form list from sqlite table. Following is the code:
<?php
$db = new PDO("sqlite:c:/sqlite/test.db");
$smt = $db->prepare('select person_name From persons');
$smt->execute();
$data = $smt->fetchAll(); ?>
<!DOCTYPE HTML>
<html lang = "en">
<head>
<title>formDemo.html</title>
<meta charset = "UTF-8" />
</head>
<body>
<h1>Form Demo</h1>
<form>
<fieldset>
<legend>choose Profile Collection Id and Call Type </legend>
<p>
<label>Profile_Collection_Id 1</label>
<select id = "myList">
<?php
foreach ($data as $row)?>
< option><?php $row["person_name"]?></option>
endforeach ?>
</select>
</form>
</body>
</html>
I am not getting where i am going wrong as list is empty when I run this code. Can someone help.
Assuming your query is returning results:
<select id="myList">
<?php
foreach ($data as $row){
echo '<option value="' . $row['Person_Name'] . '">' . $row['Person_Name'] . '</option>';
}
?>
</select>
echo is missing
<?php
foreach ($data as $row)?>
< option><?php echo $row["person_name"]?></option>
endforeach
?>

Change JSON value with PHP script

I have a JSON http://pastebin.com/index/LwAhi59r
And I have a PHP script in which I want to change my JSON value of each domain and template from each site. I would like to know what would be a good PHP code to change the values with an input and a selector in which you can choose which site you want to change it from. I got this php code I think it a good start but I don't know how to proceed.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h2>Domain of Template veranderen met PHP script</h2>
<form action="process.php" id="form" method="post">
<select name="selector">
<option value="cms18.test.silverbee.nl">cms18.test.silverbee.nl</option>
<option value="cms18.test.silverbee.nl">dmmd.test.silverbee.nl</option>
<option value="cms18.test.silverbee.nl">opmaat.test.silverbee.nl</option>
<option value="cms18.test.silverbee.nl">opmaatdebiteurenadvies.nl</option>
<option value="cms18.test.silverbee.nl">navbar.test.silverbee.nl</option>
<option value="cms18.test.silverbee.nl">test18.test.silverbee.nl</option>
<option value="cms18.test.silverbee.nl">huisartsplus.test.silverbee.nl</option>
<option value="cms18.test.silverbee.nl">robertenrademaker.test.silverbee.nl</option>
<option value="cms18.test.silverbee.nl">tilburg.test.silverbee.nl</option>
<option value="cms18.test.silverbee.nl">cbk-groningen.test.silverbee.nl</option>
<option value="cms18.test.silverbee.nl">getbusyinc.test.silverbee.nl</option>
</select>
Value:<input type="text" name="value">
<input type="submit" value="Send">
</form>
<br>
<?php
$select = $_POST['selector'];
//neem de json bestand array in php
$lijst= file_get_contents('list.json');
/*echo $lijst;*/
//neem de lijst json en decodeerd het json string. als true maakt hij er een array van.
$decoderen= json_decode($lijst, true);
/*echo $decoderen;*/
echo "<ul>";
foreach ($decoderen as $key => $value)
{
echo "<li>".$key."<ul>";
foreach ($value as $key1 => $value1)
{
echo "<li>".$key1.": ".$value1."</li>";
}
echo "</ul>"."</li>";
}
echo "</ul>";
/*------------------------------------------------------------------------------------------------------*/
/*foreach ($decoderen as $key => $value) {
if((string)$key-> == $this->put('')) {
$value->name="--";(string)$value->description="--";
}*/ This is the last code i was trying to use i found this in another site someone had same problem but i couldnt come out with this. BTW i am new in PHP.
?>
</body>
</html>
Try something like this:
<?php
$list = file_get_contents('list.json');
$list = json_decode($list, true);
$selector = $_POST['selector'];
if (isset($selector))
{
// overwrite the selected domain of the list with the new value if they are not empty
if (isset($_POST['domain']))
{
$list[$selector]['domain'] = $_POST['domain'];
}
if (isset($_POST['template']))
{
$list[$selector]['template'] = $_POST['template'];
}
// store the new json
file_put_contents('list.json', json_encode($list));
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h2>Domain of Template veranderen met PHP script</h2>
<form action="process.php" id="form" method="post">
<select name="selector">
<?php foreach ($list AS $key => $value) : ?>
<option value="<?php echo $key; ?>"><?php echo $value['domain']; ?></option>
<?php endforeach; ?>
</select>
<input type="text" name="domain" placeholder="Domain">
<input type="text" name="template" placeholder="Template">
<input type="submit" value="Send">
</form>
</body>
</html>

How to make the php strings selectable for the html query?

I'm looking to make the the suggestions given by the Dictionary API to become links that can be queried or that are inserted directly in to the text are field before they are searched. I'm looking to achieve some kind of query expansion in any case.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Search Attempt</title>
</head>
<body>
<form method="POST" action='AllinOneMonstaaa.php'>
<label for="query">Query</label><br/>
<input name="query" type="text" size="60" maxlength="60" value="" /><br /><br />
<select name ="agg">
<option value="Aggregated">Aggregated</option>
<option value="Non-Aggregated">Non-Aggregated</option>
<option value="Bing">Bing</option>
<option value="Blekko">Blekko</option>
<option value="Faroo">Faroo</option>
</select>
<input name="bt_search" type="submit" value="Search" /> </form>
<h2> Results </h2>
</body>
</html>
<?php
if ($_POST['query'])
{
$query = urlencode($_POST['query']);
$s_count = 0;
$ss_count = 0;
$query = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/'.$query.'?
$xml = new SimpleXMLIterator(file_get_contents($query));
foreach ($xml -> suggestion as $suggestion[$s_count])
{
$s_count++;
}
if ($s_count > 1)
{
echo ('<h4>Did you mean?</h4>');
while ($ss_count <=$s_count)
{
echo ($suggestion[$ss_count].'<br>');
$ss_count++;
}
}
}
'Quick bug, there's a missing ' on the $query line.
echo '<a href="whatever">'. $suggestion[$ss_count].'<br>';
Edit: This will send them to Dictionary.com with the word to look up there. Outside that I have no idea how else you would formulate the url.
echo '<a href="http://dictionary.reference.com/browse/"' . $suggestion[$ss_count] . '" target="_new">' . $suggestion[$ss_count] . '<br>';

retrieve data and display in droplist (php/mysql)

can anyone tell me what is the error in this dam code i went crazy searching about the error but without any success
the error is that i do not get any data from the table why is that happening?? plz help me
index.php
<html>
<head>
</head>
<body>
<form action="index.php" method="post">
<label for="searchByCountry">By Country</label>
<select name="searchByCountry" id="searchByCountry">
<option id="0">--select your country--</option>
<?php
require_once('connfor_lamelchameltest.php');
$getallCountries = mysql_query("SELECT country_name FROM country") or die("could not search for countries");
if(mysql_num_rows($getallCountries) > 0) {
while($viewallCountries = mysql_fetch_array($getallCountries)){
?>
<option id="<?php echo $viewallCountries['country_name']; ?> "></option>
<?php } ?>
<?php } ?>
</select>
</form>
</body>
</html>
<html>
<head>
</head>
<body>
<form action="index.php" method="post">
<label for="searchByCountry">By Country</label>
<select name="searchByCountry" id="searchByCountry">
<option id="0">--select your country--</option>
<?php
require_once('connfor_lamelchameltest.php');
$getallCountries = mysql_query("SELECT country_name FROM country") or die("could not search for countries");
if(mysql_num_rows($getallCountries) > 0) {
while($viewallCountries = mysql_fetch_array($getallCountries)){
?>
<option value="<?php echo $viewallCountries['country_name']; ?> ">
<?php echo $viewallCountries['country_name']; ?>
</option>
<?php } ?>
<?php } ?>
</select>
</form>
</body>
</html>

Categories