I have php checkboxes and wanted to send its values in mysql using submit button if the checkboxes are check.
while($grow = mysqli_fetch_array($gresult)) {
$gsymbol = $grow['symbol'];
$gclose = $grow['value'];
echo "<tr><td style='width: 100px;'>".$gsymbol."</td><td>".$gclose.</td<td><input type = 'checkbox' name = 'markings' value = '".$gsymbol."'></td></tr>"};
my question is do I have to echo a form or is there are more easier way. Thanks
Maybe you would prefer to put PHP code inside your HTML. This is ugly, but I think it's better than echo the HTML.
It could be something like this:
<table>
<?php
while($grow = mysqli_fetch_array($gresult)):
$gsymbol = $grow['symbol'];
$gclose = $grow['value'];
?>
<tr>
<td style='width: 100px;'><?php echo $gsymbol; ?></td>
<td><?php echo $gclose; ?></td>
<td><input type = 'checkbox' name = 'markings' value = "<?php echo $gsymbol; ?>" ></td>
</tr>
<?php endwhile; ?>
Related
i have this table with a button in it, what i want is when i click the button "id=myBtn" get its value to a input text field.
<tbody>
<?php while($row = mysqli_fetch_array($queryTripulacion2)):? >
<tr>
<td><input type="checkbox" name="f[]" value=<?php echo $row[2];?>></td>
<td><?php echo $row['order'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['last'];?></td>
<td ><?php echo $row['cod1']?></td>
<td class="nr"><?php echo $row['cod2'];?></td>
<td><?php echo $row['address'];?></td>
<td><?php echo $row['activity'];?></td>
<td><input type="button" id="myBtn" value="<?php echo $row['wanted_value']; ?>"></td>
</tr>
<?php endwhile;?>
</tbody>
this is what i tried, but is not working!. I want the "wanted_value" inside my "#inputM". THANKS!
$(".tablar tbody").on('click','#myBtn',function() {
$('#modal').show();
var c = $(this).closest('tr').find('td.eq(8)').text();
$("#inputM").val(c);
.eq() is a function, not part of a selector. So it should be:
var c = $(this).closest('tr').find('td').eq(8).text();
But this won't work. That TD doesn't have any text in it, it just has the input button. You need to select the button, not the TD, and use .val() rather than .text().
var c = $(this).closest('tr').find('td').eq(8).children(":button").val();
But this is all really overcomplicating it, since the button you're selecting is the same one you clicked on, so it should just be:
var c = $(this).val();
I cannot find the solution to my issue on this forum. I'm trying to give the submit button a PHP value (unique ID) by extracting data from my database. I would also like to store the value in a SESSION. The submit button doesn't work when I I give it something other than a String as value.
Student View:
<pre>
<?php foreach ($tabinternships as $internship) { ?>
<tr>
<td><span class="html"><?php echo $internship->id_internship() ?></span></td>
<td><?php echo $internship->email_teacher1_internship() ?></span></td>
<td><?php echo $internship->email_teacher2_internship() ?></span></td>
<td><?php echo $internship->email_responsible_internship() ?></span></td>
<td><?php echo $internship->id_promoter_internship() ?></span></td>
<td><?php echo $internship->name_enterprise_internship() ?></span></td>
<td><?php echo $internship->stage_internship() ?></span></td>
<td><input type="radio" name="apply" value="<?php $tabinternship->id_internship() ?>"></td> <!-- Method calls an Object rather than an Array because I'm only displaying the attributes of 1 Object therefore the Array is not required here-->
</tr>
<?php } ?>
</pre>
StudentController:
<pre>
$tabinternships = Db::getInstance()->select_internships();
if(isset($_POST['apply']) && isset($_POST['application'])){
$_SESSION['apply']= $_POST['apply'];
$_SESSION['application']= $_POST['application'];
$_SESSION['redirect']='redirect';
}
if(!empty($_SESSION['application']) && !empty($_SESSION['apply']) && !empty($_SESSION['redirect'])){
$_SESSION['redirect']='';
header("Location: index.php?action=formdeux");
die();
}
</pre>
Thanks for your help.
I have found the error, I wasn't using echo when giving a value to the radio input
echo $tabinternship->id_internship()
I have a form where I'm submitting some values (from checkboxes) to another page and on that page I'm using an explode function to break the string inside the array. But I'm getting an additional (+1) value when I put the count() function on the explode.
HTML
<form name = "view" method = "POST" action ="cart.php">
<table align = 'center' width = '100%' border = '4'>
<tr>
<td colspan = '20' align = 'center'><h2> Viewing all the Products </h2></td>
</tr>
<tr align = 'center'>
<th>Item ID</th>
<th>Name</th>
<th>Price</th>
<th>Select</th>
</tr>
<tr align = 'center' class = "odd">
<?php
while($row = mysql_fetch_array($run))
{
$i_id = $row['item_id'];
$i_name = $row['item_name'];
$i_price = $row['item_price'];
?>
<td><?php echo $i_id; ?></td>
<td><?php echo $i_name; ?></td>
<td><?php echo $i_price; ?></td>
<?php
$item = $i_name ." ". $i_price;
?>
<td><input type="checkbox" name="addcart[]" value="<?php echo $item; ?>" onClick="return KeepCount()" />Tick</td>
</tr>
<?php }?><input type = "hidden" name = "check">
<button type= "submit" onclick = "location.href = 'cart.php';" id = "cart">Add to Cart</button> <?php } ?>
</table>
</form>
PHP (on page 2)
$prd = implode(",",$_POST['addcart']);
$final = explode(",", $prd);
for($i=0; $i<=count($final); $i++)
{
echo count($final); //this is where I'm getting the +1 to original count and hence everything falls apart.
echo $final[$i];
}
Note: I have include all the essential files like config.php and everything in the PHP file already.
Why that much extra code, directly do like below:-
foreach($_POST['addcart'] as $val){
echo $val;
}
Since count() starts counting from 1 and for loop starting from 0.
Replace this line:
for($i=0; $i<=count($final); $i++)
with
for($i=0; $i<=count($final)-1; $i++)
I need to pass a one of these row contents of features-table to an array. But the problem is I used an iframe to display the table. And I need it to happen when after clicking the image of particular row.
In main.php
<iframe id="ifrm" src="reserved_tables/reserved_rooms_table.php"></iframe>
In reserved_rooms_table.php
<?php
include '../core/init.php';
$username = $user_data['username'];
$que = "SELECT * FROM ordered_rooms WHERE `username` LIKE '$username'";
$reslt = mysql_query($que);
echo '<table class="features-table" >';
echo '<thead>
<tr>
<td></td>
<td>Date</td>
<td>Start At</td>
<td>End At</td>
<td>Action</td>
</tr>
</thead>
<tbody>';
while($row = mysql_fetch_array($reslt)){
echo '<tr><td>' . $row['room_name'] .' </td><td> '. $row['date'] . '</td><td>'. $row['s_at'].'hrs</td>
<td>'. $row['e_at'].'hrs</td><td><input type="image" src="../images/cross.png" onclick="delete();" value=""></td></tr>';
}
echo "</tbody></table>";
mysql_close(); //connection closed
?>
It isn't entirely clear what you're trying to do. If you want to take data from an HTML table row and send it to a PHP array after a click then you'll need to use javascript.
Keep it simple. Create a link that sends the data to whatever URL/file does the processing:
while ($row = mysql_fetch_array($reslt)) {
?>
<tr>
<td><?php echo $row['room_name'] ?></td>
<td><?php echo $row['date'] ?></td>
<td><?php echo $row['s_at'] ?>hrs</td>
<td><?php echo $row['e_at'] ?>hrs</td>
<td><a id="my_link" href="some_file.php?room_name=<?php echo $row['room_name'] ?>&date=<?php echo $row['date'] ?>&s_at=<?php echo $row['s_at'] ?>&e_at=<?php echo $row['e_at'] ?>"><input type="image" src="../images/cross.png" value=""><a/></td>
</tr>
<?php
}
The data will then be available to some_file.php in $_GET.
Note that you can still use javascript to process this dynamically. You could add a click function to the link, so that when it is clicked, it does an AJAX call using the href value. For example:
$('#my_link').click(function() {
$.ajax({
url: this.href
});
});
I create a table using PHP from a database, meaning the size of the table and values vary.
The table creation:
<table>
<thead>
<tr>
<th>Ticket</th>
<th>Empresa</th>
<th>Requerente</th>
<th>Motivo</th>
<th>Data</th>
<th>Hora</th>
</tr>
</thead>
<tbody>
<form name="goTicket" action="resolver.php" method="POST" >
<?php
$sql = "QUERY";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo "<tr onmouseover=\"this.style.background='#EFF5FB';this.style.cursor='pointer'\"
onmouseout=\"this.style.background='white';\" onclick=\"javascript: submitform()\">";
echo "<td>$row[Ticket]</td>";
echo "<input type='hidden' name='_ticket' value='$row[Ticket]' />";
echo "<td>$row[Empresa]</td>";
echo "<td>$row[Requerente]</td>";
echo "<td>$row[Motivo]</td>";
echo "<td>$row[Data]</td>";
echo "<td>$row[Hora]</td>";
echo "</tr>";
}
echo "</form>";
echo "<tr><td colspan='6' style='text-align: center;'><form action='adminmenu.php' ><br /><input type='submit' name='woot' value='Main Menu' /></form></td></tr>";
echo "<tbody>";
echo "</table>";
?>
The Javacript function used to submit is this one:
<script type="text/javascript">
function submitform()
{
document.forms["goTicket"].submit();
}
</script>
Now whenever I click on a row it takes to the appropriate page "resolver.php" but always sends the most recent data, from last time the while was executed.
I need the value from the first cell, or the hidden input tag, that contains what I need, from the row I click.
Thank you.
Full suggestion
<script type="text/javascript">
function submitform(ticket) {
document.goTicket.elements["_ticket"].value=ticket;
document.goTicket.submit();
}
</script>
<table>
<thead>
<tr>
<th>Ticket</th>
<th>Empresa</th>
<th>Requerente</th>
<th>Motivo</th>
<th>Data</th>
<th>Hora</th>
</tr>
</thead>
<tbody>
<form name="goTicket" action="resolver.php" method="POST" >
<input type="hidden" name="_ticket" value="" />
<?php
$sql = "QUERY";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
?>
<tr onmouseover="this.style.background='#EFF5FB';this.style.cursor='pointer'"
onmouseout="this.style.background='white';"
onclick="submitform('<?php echo $row[Ticket]; ?>')">
<td><?php echo $row[Ticket]; ?></td>
<td><?php echo $row[Empresa]; ?></td>
<td><?php echo $row[Requerente]; ?></td>
<td><?php echo $row[Motivo]; ?></td>
<td><?php echo $row[Data]; ?></td>
<td><?php echo $row[Hora]; ?></td>
</tr>
<?php } ?>
</form><!-- not really nice -->
<tr><td colspan="6" style="text-align: center;"><form action="adminmenu.php" >
<br /><input type="submit" name="woot" value="Main Menu" /></form></td></tr>
</tbody>
</table>
Your problem is that you're just submitting the form without any reference to what was clicked. All the hidden inputs have the same name so the form just sends the last one.
Try the following:
echo "<tr onmouseover=\"this.style.background='#EFF5FB';this.style.cursor='pointer'\" onmouseout=\"this.style.background='white';\" onclick=\"javascript: submitform('$row[Ticket]')\">";
// delete this from while:
// echo "<input type='hidden' name='_ticket' value='$row[Ticket]'/>";
// and instead add before </form> with value=""
Then change your javascript to change the value before submitting:
function submitform(val) {
document.forms["goTicket"].elements["_ticket"].value = val;
document.forms["goTicket"].submit();
}
Kudos to mplungjan also got this as I was typing!
If I see good ... Yo set form with many of hidden inputs with same name ... what you want with this... of course it return last value ...
you have to changing names in loop and then call exact name of input