I have coding like this, it should when clicked Dekripsi button, it will appear download.php file, but this coding does not work
<?php
$nik = $_SESSION['nik'];
$no = 1;
$sql = "SELECT enkrip.Id,
(SELECT user.nama
FROM user
WHERE user.nik=enkrip.filefrom) as nama,
enkrip.filefrom,
enkrip.filename,
enkrip.kunci,
enkrip.dateupload,
enkrip.folder
FROM enkrip
WHERE enkrip.fileto = '$nik'
ORDER BY enkrip.Id ASC";
$data = mysql_query($sql);
while ($master = mysql_fetch_array($data)) {
?>
<form action="download.php?Id=<?php echo $master['Id']; ?>&file=<?php echo $master['folder']; ?>" method="post" target="_blank" >
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $master['nama'] ?></td>
<td><?php echo $master['filename'] ?></td>
<td><?php echo $master['kunci'] ?></td>
<td><?php echo $master['dateupload'] ?></td>
<td><input type="text" class="form-control" name="kunci" placeholder="Masukan Kunci Dekrip"></td>
<td><button type="submit" class="btn btn-success">Dekripsi</button></td>
<tr>
</form>
<?php } ?>
You are using method post for your form so:
<form action="download.php" method="post" target="_blank" >
<tr>
<td><?php echo $no++; ?></td>
<td><?php echo $master['nama'] ?></td>
<td><?php echo $master['filename'] ?></td>
<td><?php echo $master['kunci'] ?></td>
<td><?php echo $master['dateupload'] ?></td>
<td><input type="text" class="form-control" name="kunci" placeholder="Masukan Kunci Dekrip"></td>
<td><button type="submit" class="btn btn-success">Dekripsi</button></td>
<tr>
<input type="hidden" name="Id" value="<?php echo $master['Id']; ?>">
<input type="hidden" name="file" value="<?php echo $master['folder']; ?>">
</form>
All the parameters must be passed in post mode (using hidden input fields)
Related
<form method="post">
<?php
$sql_u="SELECT * from cubaan";
$query_u = mysqli_query($conn,$sql_u);
while($row=mysqli_fetch_assoc($query_u)){
?>
<table border="2">
<tr>
<td><input type="checkbox" name="bio[]" value="<?php $row['name'];?>" data-valuetwo="<?php $row['age'];?>" data-valuethree="<?php $row['job'];?>"></td>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['age'];?></td>
<td><?php echo $row['job'];?></td>
</tr>
</table>
<?php
}
?>
<input type="submit" name="post">
</form>
this is my code where I want to select data from the database and the selected data will insert to the new database
Use input type hidden as following
<form method="post">
<?php
$sql_u="SELECT * from cubaan";
$query_u = mysqli_query($conn,$sql_u);
while($row=mysqli_fetch_assoc($query_u)){
?>
<table border="2">
<tr>
<td>
<input type="checkbox" name="bio[<?php echo $row['id'];?>]" value="<?php echo $row['name'];?>">
<input type="hidden" name="age[<?php echo $row['id'];?>]" value="<?php echo $row['age'];?>">
<input type="hidden" name="job[<?php echo $row['id'];?>]" value="<?php echo $row['job'];?>">
</td>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['age'];?></td>
<td><?php echo $row['job'];?></td>
</tr>
</table>
<?php
}
?>
<input type="submit" name="post">
</form>
And while your form submit action use
<?php foreach($_POST['bio'] as $id=>$name) {
echo $name;
echo $_POST['age'][$id];
echo $_POST['job'][$id];
}
?>
1.fetch user data and display in tabular fashion
<?php
while($row=mysqli_fetch_assoc($rResultSet))
{
?>
<td><?php echo $row['id']?></td>
<td><?php echo $row['name']?></td>
<td><?php echo $row['user_role']?></td>
<td><?php echo $row['start_date']?></td>
<td>
<form id='euser' action='edituser.php' method='post'>
<input type="hidden" name="id" value="<?php echo $row['id']?>">
<input type="hidden" name="type" value="edituser">
Edit</i>|
</form>
<?php
}
?>
result of this code
2.when click on Edit link every time first id which 16 throw by form
i need , when press link edit at id 17 then id 17 thrown by form
Try below if it help :
<?php
while($row=mysqli_fetch_assoc($rResultSet))
{
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['user_role'];?></td>
<td><?php echo $row['start_date'];?></td>
<td>
<form id='<?php echo $row['id'];?>' action='edituser.php' method='post'>
<input type="hidden" name="id" value="<?php echo $row['id'];?>">
<input type="hidden" name="type" value="edituser">
Edit|
</form>
</td>
</tr>
<?php
}
?>
The problem is because of form's id attribute, it has to be unique for each row. Right now you're assigning the same id value euser for each row. For maintaining the uniqueness of id value, what you can do is, append the $row['id'] with euser for each table row. Also, you forgot to encapsulate each table row in <tr>...</tr>. So your code should be like this:
<?php
while($row=mysqli_fetch_assoc($rResultSet)){
?>
<tr>
<td><?php echo $row['id']?></td>
<td><?php echo $row['name']?></td>
<td><?php echo $row['user_role']?></td>
<td><?php echo $row['start_date']?></td>
<td>
<form id='euser<?php echo $row['id']?>' action='edituser.php' method='post'>
<input type="hidden" name="id" value="<?php echo $row['id']?>">
<input type="hidden" name="type" value="edituser">
Edit</i>|
</form>
<tr>
<?php
}
?>
I want to repopulate a page that contains checkboxes from values in the database. Currently, they are being stored as a string that gets split into an array when processing e.g 3,4,5.
I am able to check the boxes with the data from my database but another empty checkbox is created by its side. How do I only check the boxes with data from the database without having a duplicate empty box by its side?
<tbody>
<?php
if(!empty($datatable)){
foreach ($datatable as $data){
?>
<tr>
<td>
<?php foreach ($event_contacts as $checked){?>
<?php if($checked==$data->id){?>
<input type="checkbox" name="id[]" id="id" checked value="<?php echo $data->id; ?>"/>
<?php }else{ ?>
<input type="checkbox" name="id[]" id="id" value="<?php echo $data->id; ?>"/>
<?php }}?>
</td>
<td><?php echo $data->first_name." ".$data->last_name; ?></td>
<td><?php echo $data->email; ?></td>
<td><?php echo $data->phone_number; ?></td>
<td><?php echo $data->address;?></td>
</tr>
<?php
}
}
?>
</tbody>
Hope someone can help. Thanks
EDIT: Added photo for clarity
just change your code like this
<tbody>
<?php
if(!empty($datatable)){
foreach ($datatable as $data){
?>
<tr>
<td>
<?php
if (in_array($data->id, $event_contacts)) {
?>
<input type="checkbox" name="id[]" id="id" checked value="<?php echo $data->id; ?>"/>
<?php
}else{
?>
<input type="checkbox" name="id[]" id="id" value="<?php echo $data->id; ?>"/>
<?php
}
?>
</td>
<td><?php echo $data->first_name." ".$data->last_name; ?></td>
<td><?php echo $data->email; ?></td>
<td><?php echo $data->phone_number; ?></td>
<td><?php echo $data->address;?></td>
</tr>
<?php
}
}
?>
</tbody>
I was informed that I can send data without a POST function. What I am trying to figure out is how I can get rid of the form around my table and send the data to my page called "edit-product".
In addition to the data, I want the user to be sent there as well, just like the form's action attribute would do.
As of now, I have it structured like this:
<?php
$stmt = $dbc->query("SELECT `id`,`first`,`last`,`product` FROM users");
$stmt->setFetchMode(PDO::FETCH_ASSOC);
while($row = $stmt->fetch()) {
?>
<form method="POST" action="edit-product">
<tr>
<td><?php echo $row['id'];?>"</td>
<td><?php echo $row['first'];?></td>
<td><?php echo $row['last'];?></td>
<td><?php echo $row['product'];?></td>
<input name="id" type="hidden" value="<?php echo $row['id'];?>" readonly>
<input name="first" type="hidden" value="<?php echo $row['first'];?>">
<input name="last" type="hidden" value="<?php echo $row['last'];?>">
<input name="product" type="hidden" value="<?php echo $row['product'];?>">
<td><input name="save" type="submit" value="Save"></td>
<td><div class="delete-class" name="delete" id="<?php echo $row['id']; ?>">Delete</div></td>
<td><input name="edit" type="submit" value="Edit"></td>
</tr>
</form>
<?php } ?>
</tbody>
</table>
In my edit-product page, I receive the data like this:
$id = $_POST['id'];
$first = $_POST['first'];
$last = $_POST['last'];
$product = $_POST['product'];
How could I do this?
You can use an edit button with anchor.
<table>
<tbody>
<?php
$stmt = $dbc->query("SELECT `id`,`first`,`last`,`product` FROM users");
$stmt->setFetchMode(PDO::FETCH_ASSOC);
while($row = $stmt->fetch()) {
?>
<tr>
<td><?php echo $row['id'];?>"</td>
<td><?php echo $row['first'];?></td>
<td><?php echo $row['last'];?></td>
<td><?php echo $row['product'];?></td>
<td><input name="save" type="submit" value="Save"></td>
<td><div class="delete-class" name="delete" id="<?php echo $row['id']; ?>">Delete</div></td>
<td>Edit</td>
</tr>
<?php } ?>
</tbody>
</table>
And u can catch the url value from edit-prpduct page.
like
$id = $_GET['id'];
$first = $_GET['first'];
$last = $_GET['last'];
$product = $_GET['product'];
Just try this without any form post.
So the below code grabs the server_id from the row that the user selects. However, I am wondering if it is possible to grab both the server_id and server_name from the row without the user having to do anymore than he already does (select a radio button and push submit). Thanks for any help.
<form method="post" name="server_information" id="server_information" action="test.php">
<label>Server Information</label><br><br>
<table border='1'>
<tr>
<th>Selection</th>
<th>User Name</th>
<th>Date Created</th>
<th>Server Name</th>
<th>Server Id</th>
<th>Public DNS</th>
<th>Server Status</th>
</tr>
<?php while($row = mysql_fetch_assoc($result)): ?>
<tr>
<td><input type="radio" name="server" value="<?php echo $row['serverId']; ?>" /></td>
<td><?php echo $row['userName']; ?></td>
<td><?php echo $row['dateCreated']; ?></td>
<td><?php echo $row['serverName']; ?>"</td>
<td><?php echo $row['serverId']; ?></td>
<td><?php echo $row['publicDNS'] ?></td>
<td><?php echo $row['serverStatus']; ?></td>
</tr>
<?php endwhile; ?>
</table>
<br>
<?php endif; ?>
<input type="submit" name="server_stop" value="Stop Server"/>
<input type="submit" name="server_terminate" value="Terminate Server"/>
</form>
You can put a pipe | or any other character to concatenate both in the radio value, then explode your $_POST['server'] on pipe, you'll get id in index 0 and name in index 1.
<td><input type="radio" name="server" value="<?php echo $row['serverId'].'|'.$row['serverName']; ?>" /></td>
Another solution would be to add a hidden input and name it with the server id like this:
<td>
<input type="radio" name="server" value="<?php echo $row['serverId']; ?>" />
<input type="hidden" name="name_<?php echo $row['serverId'];?>" value="<?php echo $row['serverName'];?>" />
</td>
then in PHP
$server_id=(int)$_POST['server'];
$server_name=$_POST['name_'.$server_id];
You can use an array:
name="server[$row['serverId']]" value="$row['serverName']"
Then get it with:
list($id, $name) = $_POST['server'];
Sure, just concatenate the two values with a comma (or other delimiter that won't appear in the values):
<tr>
<td><input type="radio" name="server"
value="<?php echo $row['serverId'] . ',' . $row['serverName']; ?>" /></td>
<td><?php echo $row['userName']; ?></td>
<td><?php echo $row['dateCreated']; ?></td>
<td><?php echo $row['serverName']; ?>"</td>
<td><?php echo $row['serverId']; ?></td>
<td><?php echo $row['publicDNS'] ?></td>
<td><?php echo $row['serverStatus']; ?></td>
</tr>
Then when you process the form use explode() to separate the results:
$server_info = explode(",", $_POST["server"]); // server_info is an array
$server_selection = $server_info[0];
$server_name = $server_info[1];