radio modification with php - php

I have this script =>
while ($data = mysqli_fetch_assoc($result)){
echo "<tr>";
echo "<td><span class='getinfo'>" . $data['username'] . "</span></td>";
echo "<td></td>";
echo "<td><span class='getinfo'>" . $data['email'] . "</span></td>";
echo "<td></td>";
echo "<td><span class='getinfo'>" . $data['rights'] . "</span></td>";
echo "<td></td>";
echo "<td><span class='getinfo'>" . $data['last_seen'] . "</span></td>";
echo "<td></td>";
echo "<td><span class='getinfo'>" . $data['since'] . "</span></td>";
echo "<td></td>";
echo "<td><span class='radio_place'><input type='radio' name='choose' onclick='showModification()' id='get_" . $data['username'] . "' value='" . $data['rights'] . "'></span></td>";
echo "</tr>";
}
And like you see guys, I have radio buttons and after onclick them I have made to show up next form =>
and with showModification() function (javascript) I appear next html form for data modification
and here is the face of this form =>
<div id="mod_div">
<select name="option" id="option">
<option value="sel">* * * *</option>
<option value="null">0</option>
<option value="one">1</option>
<option value="del">Delete</option>
</select>
<input type="submit" name="action" id="action" value="Action">
</div>
I want to know after pressing action submit which radio is clicked to manipulate it with php, please help me how to do that ? Thanks ...

If it is a new page, you can use $_GET or if it is in same page you can use JavaScript itself to push which radio button is clicked. Example as follows.
<div id="mod_div">
<select name="option" id="option">
<option value="sel">* * * *</option>
<option value="null">0</option>
<option value="one">1</option>
<option value="del">Delete</option>
</select>
<input type="submit" name="action" id="action" value="Action">
<input type='hidden' name='cameFrom' />
</div>

In PHP:
$_POST["choose"] or $_GET["choose"]
will give you an access to the clicked radio button. (the usage of _POST or _GET depends on your "action" attribute of your "form" tag.

Related

How to show a selected value in a dynamic drop down in PHP

I am trying to retain the value selected in a drop down menu. Everything is working, but I don't know how to show and retain the selected value. How can I do this?
I've got this working using another way:
<?php if($_POST['selClass'] == $row1['class']) echo 'selected="selected"' ?>
but this leads to other problems, i.e. a blank option in my drop down menu.
<form action="" method="POST" name="form1" id="form1">
<select name="selClass" size="1" id="selClass" onchange="form1.submit()">
<option value="">Select a class</option>
<?php
echo "<option value='". "All records". "' . >" . "all records". "</option>";
while ($row1 = mysqli_fetch_array($rs5)) {
echo "<option value='".$row1["class"] ."'>" . $row1["class"]. "</option>";
}
?>
</select>
</form>
You can approach this as
<?php
$selectedOption = '';
if($_POST){
$selectedOption = $_POST['selClass'];
}
?>
<form action="" method="POST" name="form1" id="form1">
<select name="selClass" size="1" id="selClass" onchange="form1.submit()">
<option value="">Select a class</option>
<?php
echo "<option value='". "All records". "' . >" . "all records". "</option>";
while ($row1 = mysqli_fetch_array($rs5)) {
if($row1["class"] == $selectedOption)
echo "<option value='".$row1["class"] ."' selected='selected'>" . $row1["class"]. "</option>";
else
echo "<option value='".$row1["class"] ."'>" . $row1["class"]. "</option>";
}
?>
</select>
</form>
There is two option you can choose whichever you feel ease.
<?php
echo "<option value='". "All records". "' . >" . "all records". "</option>";
while ($row1 = mysqli_fetch_array($rs5)) {
if($_POST['selClass'] == $row1['class']){
echo "<option value='".$row1["class"] ."' selected='selected'>" . $row1["class"]. "</option>";
}else{
echo "<option value='".$row1["class"] ."'>" . $row1["class"]. "</option>";
}
}
?>
OR
<?php
$selectedClass = $_POST['selClass'];
while ($row1 = mysqli_fetch_array($rs5)) { ?>
<option value="<?php echo $row1['çlass']?>" <?php if(selectedClass == $row1['class']) { echo "selected='selected'"; }?> ><?php echo $row1['class']?></option>
<?php } ?>

Unable to fetch data from the selected checkbox

Here is the html code and php script, I am unable query data for the selected checkbox:
<code>
Search the Database using multiple options:<br /><br />
<form id="Advanced_form" action="checkbox.php" enctype="multipart/form-data" method="POST">
<input type="checkbox" name="checkbox1[]" value="1" /> Location: projectid
<input type="text" name="projectid" size="10" /> basesq30 from
<input type="text" name="start" size="10" /> To
<input type="text" name="end" size="10" />
<br /><br />
<input type="checkbox" name="checkbox1[]" value="2" /> platform:
<select name="key4" onchange="SetText(key4,word4)">
<option selected="selected" value="All">Select</option>
<option value="miseq">miseq</option>
<option value="hiseq">hiseq</option>
</select>.<br /><br />
<input type="checkbox" name="Genotype" value="3" /> run no:
<select multiple="multiple" name="checkbox1[]" size="5">
<option selected="selected" value= "2">2</option>
<option value= "3">3</option>
<option value= "4">4</option>
<option value= "5">5</option>
<option value= "6">6</option>
</select>
<center>
<INPUT TYPE="Reset" VALUE="Reset">
<input style="align: center;" type="Submit" name="submit" value="Search" /></center>
</form>
<?php
/*
Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password)
*/
$link = mysqli_connect("localhost", "root", "root123", "newdb");
// Check connection
if($link === false)
{
die("ERROR: Could not connect. " . mysqli_connect_error());
}
//code
if(isset($_POST['submit']))
{
foreach($_POST['checkbox1'] as $checkbox1)
//printf("%S<br>",$checkbox1);
if($checkbox1==1)
$text=$_POST['projectid'];
$a=$_POST['start'];
$b=$_POST['end'];
{
$sql="select * from qcdata where project_id='$text' and bases_q30>='$a' and bases_q30<='$b'";
}
if($checkbox1==2)
{
$value=$_POST['key4'];
$sql1="select * from qcdata where platform='$value'";
}
}
echo "$sql";
if($result = mysqli_query($link, $sql))
{
if(mysqli_num_rows($result) > 0)
{
echo "<table align='left'>";
echo "<tr>";
echo "<th>sno</th>";
echo "<th>project_id</th>";
echo "<th>file_name</th>";
echo "<th>read_pair</th>";
echo "<th>total_bases</th>";
echo "<th>total_reads</th>";
echo "<th>bases_q20</th>";
echo "<th>bases_q30</th>";
echo "<th>average_read_length</th>";
echo "<th>readlength_range_min</th>";
echo "<th>readlength_range_max</th>";
echo "<th>quality_range_min</th>";
echo "<th>quality_range_max</th>";
echo "<th>phread_range_min</th>";
echo "<th>phread_range_max</th>";
echo "<th>gc_percentage</th>";
echo "<th>a</th>";
echo "<th>t</th>";
echo "<th>g</th>";
echo "<th>c</th>";
echo "<th>n</th>";
echo "<th>platform</th>";
echo "<th>run_no</th>";
echo "<th>creation_by</th>";
echo "<th>creation_date</th>";
echo "<th>last_modified</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" .$row['sno']. "</td>";
echo "<td>" .$row['project_id'] . "</td>";
echo "<td>" .$row['file_name']. "</td>";
echo "<td>" .$row['read_pair'] . "</td>";
echo "<td>" .$row['total_bases'] . "</td>";
echo "<td>" .$row['total_reads'] . "</td>";
echo "<td>" .$row['bases_q20'] . "</td>";
echo "<td>" .$row['bases_q30'] . "</td>";
echo "<td>" .$row['average_read_length'] . "</td>";
echo "<td>" .$row['readlength_range_min'] . "</td>";
echo "<td>" .$row['readlength_range_max'] . "</td>";
echo "<td>" .$row['quality_range_min'] . "</td>";
echo "<td>" .$row['quality_range_max'] . "</td>";
echo "<td>" .$row['phread_range_min'] . "</td>";
echo "<td>" .$row['phread_range_max'] . "</td>";
echo "<td>" .$row['gc_percentage'] . "</td>";
echo "<td>" .$row['a'] . "</td>";
echo "<td>" .$row['t'] . "</td>";
echo "<td>" .$row['g'] . "</td>";
echo "<td>" .$row['c'] . "</td>";
echo "<td>" .$row['n'] . "</td>";
echo "<td>" .$row['platform'] . "</td>";
echo "<td>" .$row['run_no'] . "</td>";
echo "<td>" .$row['creation_by'] . "</td>";
echo "<td>" .$row['creation_date'] . "</td>";
echo "<td>" .$row['last_modified'] . "</td>";
echo "</tr>";
}
echo "</table>";
// Close result set
mysqli_free_result($result);
}
else{
echo "No records matching your query were found.";
}
}
else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
</code>
MySQL DB screenshot images are here part 1 part 2
I would remove the []'s from the name of your checkbox.

Fetch db data depending on selected drop down value

Is it possible to fetch data from db upon changing value of my drop down, I want to pull up the data that corresponds to the value of the drop down and show it to a text area, I got the codes that I've tried to create just don't know how to make it work to what I want.
I want my page to just initially show the drop down then after selecting a value it will show the data in a text area without refreshing the page, here is the code:
<div id="mainContent">
<table width="619" border="0" align="center">
<td align="center"><form id="form1" name="form1" method="post" action="" >
<fieldset>
<legend><strong>EA</strong></legend>
<p>
<select name="ea_name" id="ea_name">
<option value="" selected="selected">Please select...</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</p>
</fieldset>
</form></td>
</table>
<div id="results"></div>
</div>
I am thinking an "onchange" could do it but just dont know how to implement it, also want to echo the resulting data to a text area within a fieldset.
Here is the code that I've tried that will pull up data and show to a text area:
<?php
require 'include/DB_Open.php';
$ea_name = $_POST['ea_name'];
$sql="SELECT * FROM ea_error WHERE ea_name = '" . $ea_name . "'";
$myData = mysql_query($sql);
//to count if there are any results
$numrow = mysql_num_rows($myData);
if($numrow == 0)
{
echo "No results found.";
}
else
{
echo "<fieldset><legend><strong>Information</strong></legend><p>
<table width="auto" height="172" border="0">
<tr><th scope="row">Error</th></tr>
<tr><th scope="row">Resolution</th></tr>
<tr><th scope="row">Contact/s</th></tr>;"
while($info = mysql_fetch_array($myData))
{
echo "<form action='retrieve.php' method='post'>";
echo"<tr>";
echo "<td align='center'>" . $info['error'] . "<input type=hidden name=error value=" . $info['error'] . " </td>";
echo "<td align='center'>" . $info['resolution'] . "<input type=hidden name=resolution value=" . $info['resolution'] . " size='11' maxlength='11' /> </td>";
echo "<td align='center'>" . $info['contacts'] . "<input type=hidden name=contacts value=" . $info['contacts'] . "' /> </td>";
echo "</tr>";
echo "</form>";
}
}
echo "</fieldset>";
include 'include/DB_Close.php';
?>
UPDATED CODE:
<?php
require 'include/DB_Open.php';
$ea_name = $_POST['ea_name'];
$sql="SELECT * FROM ea_error WHERE ea_name = '" . $ea_name . "'";
$myData = mysql_query($sql);
//to count if there are any results
$numrow = mysql_num_rows($myData);
if($numrow == 0)
{
echo "No results found.";
}
else
{
echo '<fieldset><legend><strong>Information</strong></legend><p>
<table width="auto" height="172" border="0">
<tr><th>Error</th></tr>
<tr><th>Resolution</th></tr>
<tr><th>Contact/s</th></tr>';
while($info = mysql_fetch_array($myData))
{
echo "<form action='retrieve.php' method='post'>";
echo"<tr>";
echo "<td align='center'>" . $info['error'] . "<input type=hidden name=error value=" . $info['error'] . " </td>";
echo "<td align='center'>" . $info['resolution'] . "<input type=hidden name=resolution value=" . $info['resolution'] . " size='11' maxlength='11' /> </td>";
echo "<td align='center'>" . $info['contacts'] . "<input type=hidden name=contacts value=" . $info['contacts'] . "' /> </td>";
echo "</tr>";
echo "</form>";
}
}
echo "</fieldset>";
include 'include/DB_Close.php';
?>
This should do the trick. Just put this javascript either in script tags in the head of your page, after the jQuery include, or in another js file and include that after jQuery...
$(function() { // document.ready
$("#ea_name").on("change", function() {
$.ajax({
url: "phpfile.php",
type: "POST",
data: {
ea_name: $(this).val()
},
success: function(data) {
$("#results").html(data);
}
});
});
});
It assigns an event handler to the change event of the drop down. When this is triggered it sends an ajax request to your php file (don't forget to put the correct filename for the url!) which then returns the html. This is then pushed into the results div.
Note: I fixed a typo that may or may not be in your php file. At the end of the line where you create the query, you'd missed a closing ". Just in case that was a copy and paste from the real file.
You have to implement ajax call to php file with ea_name as post parameter file. and place response to specific div.

Refreshing a php page after submit button - PHP - MySQL

I have a page that needs to be constantly refreshed multiple times a minute. The page has is a echo'd php table.
The page loads perfectly fine, all is good, I have used the META tag HTML, I have used the header tag with the refresh function in PHP... and yet a problem arises :
When I hit Start Session button the refresh stops. And the table bellow does does not get updated. So then I have to manually refresh the page. This is not the desired affect. Can some one explain to me how to refresh a page continually.
Edit 1:
Code that makes the include of the session start
foreach($result as $row)
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td> <a href=student.php?anum=" . $row['anum'] . " target='_blank'>" .$row['anum'] . " </a></td>";
echo "<td>" . $row['first'] . "</td>";
echo "<td>" . $row['last'] . "</td>";
echo "<td>" . $row['why'] . "</td>";
echo "<td>" . $row['comments'] . "</td>";
echo "<td>" . $row['additional_req'] . "</td>";
echo "<td>" . $row['signintime'] . "</td>";
echo "
<td> <form action='counselor.php?id=" . $row['id'] . "' method='post' target='_new'>
<select name='namedrop'>
<option value=''>Counselor Name</option>
<option value='Admin-John'>Admin - John</option>
<option value='Admin-Christine'>Admin - Christine</option>
<option value='Admin-Dawne'>Admin - Dawne</option>
<option value='Counselor-Cherie'>Counselor - Cherie</option>
<option value='Counselor-Tootie'>Counselor - Tootie</option>
<option value='Counselor-Debbie'>Counselor - Debbi</option>
<option value='FrontDesk-Delores'>Front Desk - Delores</option>
<option value='FrontDesk-Kiana'>Front Desk - Kiana</option>
</select>
</td>
<td> <input type='submit' name='submit' value='Start Session'></td>
</form> </td>";
}
If you are looking to refresh the page when you click "Start Session", then you can edit your submit button to have this onClick listener. It should refresh the page.
<input type='submit' name='submit' value='Start Session' onClick="window.location.reload()" />
Is it possible for you to use Javascript to achieve the desired effect? I don't know enough about what you're doing to determine whether that would clear your changes or not (my assumption here is: no).
If you are able to use Javascript, you could write a simple function which refreshes the page on an interval.
<form action="<?php echo $PHP_SELF; ?>" method="post">
or
<form action="thispage.php" method="post">

Handling data modification

I have such a situation. Here is my code =>
while ($data = mysqli_fetch_assoc($result)){
echo "<tr>";
echo "<td><span class='getinfo'>" . $data['username'] . "</span></td>";
echo "<td></td>";
echo "<td><span class='getinfo'>" . $data['email'] . "</span></td>";
echo "<td></td>";
echo "<td><span class='getinfo'>" . $data['rights'] . "</span></td>";
echo "<td></td>";
echo "<td><span class='getinfo'>" . $data['last_seen'] . "</span></td>";
echo "<td></td>";
echo "<td><span class='getinfo'>" . $data['since'] . "</span></td>";
echo "<td></td>";
echo "<td><span class='getinfo'><select name='change_rights'><option value='sel'>* * *</option><option value='null'>0</option><option value='one'>1</option></select></span></td>";
echo "<td></td>";
echo "<td><span class='getinfo'><input type='submit' name='del_user' id='del_user' value='Delete'></span></td>";
echo "</tr>";
}
Like you see , I've made preposition along of data <select> and delete Submit
this is all in one
<form name="" action="" method="post"></form>
Is it possible to make modification with <select> and also delete data from script like this and if it possible how? Or not can advice me how to that?
If I have html form like this =>
<form name="mod" action="default.php" method="post">
<input type="checkbox" name="mod[]" id="mod1">
<input type="checkbox" name="mod[]" id="mod2">
<input type="submit" name="ok" value="ok">
</form>
and php =>
if (isset($_POST['ok'])){
if ($_POST['mod']=="mod1"){
echo "one";
} else {
echo "two";
}
}
(I've never user checkbox with php and I have not know it well)
something is not going well, what is wrong here?
This does not look that good. Try using seperate forms for each entry and add a hidden field to it which holds the identifier. Another solution: add checkboxes to each entry and use a single form with only one submit button

Categories