I'm trying to figure out how to make this code snippet display the value or the button but not both. As you'll see there is a button for "Call_Attempt_One". I'm trying to have it only display when there is no value in the field but have the field value displayed when there is a value and have the button disappear.
Suggestions?? Thanks!
<td style='font-size:12px;width:500px;'><div style=\"overflow-x:auto; max-height:100px\">{$row['Project_Description']}</div></td>
<td style='font-size:12px;'><center>{$row['Restoration_Decision_Matrix']}</center></td>
<td style='font-size:12px;'><center>
<form action='".$_SERVER['PHP_SELF']."' method='post'>
<input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
<input type='submit' name='formCalledOne' id='formCalledOne' value='Called' />
</form>
{$row['Call_Attempt_One']}
</center></td>
<td style='font-size:12px;'><center><button type=\"submit\" form=\"form1\" value=\"Submit\">Called</button></center></td>
<td style='font-size:12px;'><center><button type=\"submit\" form=\"form1\" value=\"Submit\">Called</button></center></td>
<td style='font-size:12px;'><center><button type=\"submit\" form=\"form1\" value=\"Submit\">Emailed</button></center></td>
<td style='font-size:12px;'><center>Text Area</center></td>
<td style='font-size:12px;'><center>{$row['Received_Date']}</center></td>
<td style='font-size:12px;'><center>
<form action='".$_SERVER['PHP_SELF']."' method='post'>
<input type='hidden' id='ID' name='ID' value='{$row['ID']}' />
<input type='submit' name='formDelete' id='formDelete' value='Delete' />
</form>
</center></td>
</tr>";
}
//Check to see if delete button is pressed
if(isset($_POST['formDelete']))
{
if(isset($_POST['ID']) && !empty($_POST['ID']))
{
$ID = $_POST['ID'];
$result = mysql_query("DELETE FROM Project_Submissions WHERE ID ='".$ID."'");
}
}
here is the code that I found to work in my question above. I fixed it myself and replaced these lines
if(isset($_POST['formDelete']))
{
if(isset($_POST['ID']) && !empty($_POST['ID']))
{
$deleteID = $_POST['ID'];
$result = mysql_query("DELETE FROM Project_Submissions WHERE ID ='".$deleteID."'");
}
}
Related
I am stuck with this code, trying to post 2 different radio group my problem is I want to make the user to check 1 radio button for ervery 4 results , I mean how can I know when user has choose other, with this code I always can choose more than one radio , any help?
$sql = "SELECT * FROM tbl1 WHERE object = '".$obj."' LIMIT 5 ";
$result2 = mysqli_query($conn,$sql);
echo "<form action='' method='post'>";
while ($row2 = mysqli_fetch_array($result2,MYSQLI_ASSOC)) {
echo "<div align='center'>
<table class='demo' dir='rtl'>
<tbody>
<tr>
<td>".$row2['ojs']."</td>
<td> </td>
</tr>
<tr>
<td>".$row2['txt1']."</td>
<td><input type='radio' name='chk1' value='1' >
</tr>
<tr>
<td>".$row2['txt2']."</td>
<td><input type='radio' name='chk2' value='2' >
</tr>
<tr>
<td>".$row2['txt3']."</td>
<td><input type='radio' name='chk3' value='3' >
</tr>
<tr>
<td>".$row2['txt4']."</td>
<td><input type='radio' name='chk4' value='4' >
</tr>
</tbody>
</table><br>
</div>
";
}
echo "<input type='submit' name='submit'>
</form>";
if (isset($_POST['submit'])) {
$chk1 = $_POST['chk1'];
$chk2 = $_POST['chk2'];
$chk3 = $_POST['chk3'];
$chk4 = $_POST['chk4'];
echo $chk4."|".$chk3."|".$chk2."|".$chk1;
//insert into mysql , just the Selected radio button for each different question
$insQry = "insert into tbl2 (id,sel1,sel2,sel3,sel4) VALUES('$chk1','$chk2','$chk3','$chk4')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
You need to set the name of the entire adio input group to one name. Since you have them set to four different names, it treats them as as four different entities.
You need to give them the same name then get it in PHP like
$sql = "SELECT * FROM tbl1 WHERE object = '".$obj."' LIMIT 5 ";
$result2 = mysqli_query($conn,$sql);
echo "<form action='' method='post'>";
while ($row2 = mysqli_fetch_array($result2,MYSQLI_ASSOC)) {
echo "<div align='center'>
<table class='demo' dir='rtl'>
<tbody>
<tr>
<td>".$row2['ojs']."</td>
<td> </td>
</tr>
<tr>
<td>".$row2['txt1']."</td>
<td><input type='radio' name='chk' value='1' >
</tr>
<tr>
<td>".$row2['txt2']."</td>
<td><input type='radio' name='chk' value='2' >
</tr>
<tr>
<td>".$row2['txt3']."</td>
<td><input type='radio' name='chk' value='3' >
</tr>
<tr>
<td>".$row2['txt4']."</td>
<td><input type='radio' name='chk' value='4' >
</tr>
</tbody>
</table><br>
</div>
";
}
echo "<input type='submit' name='submit'>
</form>";
if (isset($_POST['submit'])) {
$chk = $_POST['chk'];
echo $chk;
Then simply set the adjacent one in the database to selected number and others to 0
I have a form in PHP with two submit buttons of type 'image'.
How do I know which button is clicked?
Code:
<?php
echo ("
<form action='WijzigSession.php' method='POST'>
<td><input class= 'nummers' type='number' name='aantal' value=".$_SESSION['producten'][$i]['aantal']." min='1' max='20'>
<input name='refresh' class='buttons' type='image' src='img/refresh.png'</a>
<input name='delete' class='buttons' type='image' src='img/delete.png'</a>
<input type='hidden' name='id' value='$i'>
</form></td>
<td>€ ".$_SESSION['producten'][$i]['prijs']."</td>
");
?>
Just try:
if(isset($_POST['refresh_x'])) { //you can potentially even check for '$_POST['refresh_y']'
// refresh is clicked
}
if(isset($_POST['delete_x'])) {
// delete is clicked
}
I need my system to show only the set of 'minutes' a user clicks on and not every set of minutes that the current user is involved in.
At the minute when I click the 'image' to view a set of minutes it prints out each set of minutes that user is involved in, I need it to only print out and be able to edit that one specific set of minutes... the edit function works but I just need it to print out what the user clicks on and not every set..PLEASE Can ANYONE help with this I have spent all day and don't understand how to get this to work.
Below is the code that shows the php and query in the minutes.php page, when you click the image for 'view' it takes you to the 'viewstudentminutes.php' page, I only want it to print out the minutes you click on not every set.
<?php
session_start();
if (!(isset($_SESSION["sess_username"]))) header ("Location: index.php");
$currentUser=$_SESSION["sess_username"];
$dbQuery = $db->prepare("select * from minute where '$currentUser'=B_number ");
$dbQuery->execute();
$numMinutes = $dbQuery->rowCount();
echo "<p>There are $numMinutes sets of minutes in the system</p>";
$oddRow=true;
while ($dbRow = $dbQuery->fetch(PDO::FETCH_ASSOC)) {
$ID = $dbRow['ID'];
$B_number = $dbRow['B_number'];
$Date = $dbRow['Date'];
$Time = $dbRow['Time'];
$Discussion = $dbRow['Discussion'];
$Actions = $dbRow['Actions'];
$Dateofnextmeeting = $dbRow['Dateofnextmeeting'];
$Status = $dbRow['Status'];
$E_number = $dbRow['E_number'];
$Supervisor_comments = $dbRow['Supervisor_comments'];
if ($oddRow) $rowClass="odd"; else $rowClass="even";
$oddRow=!$oddRow;
if (isset($_POST['editMinuteID']) && $_POST['editMinuteID']==$ID) {
echo "<tr class='$rowClass '>
<form style='display:inline' method='post' action='minutes.php'>
<input type='hidden' name='editCommitID' value='$ID'>
<td><input type='varchar' name='editB_number' value='$B_number'></td>
<td><input type='date' name='editDate' value='$Date'></td>
<td><input type='time' name='editTime' value='$Time'></td>
<td><input type='text' name='editDiscussion' value='$Discussion'></td>
<td><input type='text' name='editActions' value='$Actions'> </td>
<td><input type='date' name='editDateofnextmeeting' value='$Dateofnextmeeting'></td>
<td><input type='enum' name='editStatus' value='$Status'> </td>
<td><input type='varchar' name='editE_number' value='$E_number'></td>
<td><input type='text' name='editSupervisor_comments' value='$Supervisor_comments'></td>
<td colspan='2'><input type='image' src='edit.png'>
</form>
</tr>";
} else {
echo "<tr class='$rowClass'><td>$B_number</td><td>$Date</td> <td>$Time</td><td>$Discussion</td><td>$Actions</td><td>$Dateofnextmeeting</td> <td>$Status</td><td>$E_number</td><td>$Supervisor_comments</td>
echo "<tr class='$rowClass'><td>$B_number</td><td>$Date</td><td>$Time</td><td>$Discussion</td><td>$Actions</td><td>$Dateofnextmeeting</td><td>$Status</td><td>$E_number</td><td>$Supervisor_comments</td>
<td class='operation'>
<form class='display:inline' method='post' action='viewstudentminutes.php'>
<input type='hidden' name='editMinute_ID' value='$ID'>
<input type='image' src='edit.png' style='padding-top:7px'>
</form></td>
<td class='operation'>
<form class='display:inline' method='post' action='minutes.php'
onsubmit='return confirm(\"Are you sure?\")'>
<input type='hidden' name='deleteMinuteID' value='$ID'>
<input type='image' src='delete.png' style='padding-top:7px'>
</form></td>
<td class='operation'>
<form class='display:inline' method='post' action='viewstudentminutes.php'
onsubmit='viewstudentminutes.php'>
<input type='image' src='view.png' style='padding-top:7px'>
</form></td>
</tr>";
}
}
?>
Below is the code for the 'viewstudentminutes.php' when trying to edit the set of minutes
<h2>Minutes</h2>
<table class="table table-condensed">
<?php
$dbQuery= $db->prepare("SELECT * FROM `Minute` WHERE `B_number` = '" . $currentUser . "' AND `id` = " . $_POST['Minute_ID']);
$dbQuery->execute();
$oddRow=true;
while ($dbRow = $dbQuery->fetch(PDO::FETCH_ASSOC)) {
$ID = $dbRow['ID'];
$B_number = $dbRow['B_number'];
$Date = $dbRow['Date'];
$Time = $dbRow['Time'];
$Discussion = $dbRow['Discussion'];
$Actions = $dbRow['Actions'];
$Dateofnextmeeting = $dbRow['Dateofnextmeeting'];
$Status = $dbRow['Status'];
$E_number = $dbRow['E_number'];
$Supervisor_comments = $dbRow['Supervisor_comments'];
if ($oddRow) $rowClass="odd"; else $rowClass="even";
$oddRow=!$oddRow;
if (isset($_POST['editMinuteID']) && $_POST['editMinuteID']==$id) {
echo "<tr class='$rowClass'>
<form style='display:inline' method='post' action='viewstudentminutes.php'>
<input type='hidden' name='editCommitID' value='$ID'>
<tr><td colspan='2'><input type='image' src='edit.png'> </tr>
<tr><th>BNumber</th><td><input type='varchar' name='editB_number' value='$B_number'></td></tr>
<tr><th>Date</th><td><input type='date' name='editDate' value='$Date'></td></tr>
<tr><th>Time</th><td><input type='time' name='editTime' value='$Time'></td></tr>
<tr><th>Discussion</th><td><input type='text' name='editDiscussion' value='$Discussion'></td></tr>
<tr><th>Actions</th><td><input type='text' name='editActions' value='$Actions'></td></tr>
<tr><th>Date of Next Meeting</th><td><input type='date' name='editDateofnextmeeting' value='$Dateofnextmeeting'></td></tr>
<tr><th>Status</th><td><input type='enum' name='editStatus' value='$Status'></td></tr>
<tr><th>E Number</th><td><input type='varchar' name='editE_number' value='$E_number'></td></tr>
<tr><th>Supervisor Comments</th><td><input type='text' name='editSupervisor_comments' value='$Supervisor_comments'></td></tr>
</form>
</tr>";
} else {
echo "<tr class='$rowClass'>
<td class='operation'>
<form class='display:inline' method='post' action='viewstudentminutes.php'>
<input type='hidden' name='editMinute_ID' value='$ID'>
<input type='image' src='edit.png' style='padding-top:7px'>
</form></td>
<tr><th>BNumber</th><td>$B_number</td></tr>
<tr><th>Date</th><td>$Date</td></tr>
<tr><th>Time</th><td>$Time</td></tr>
<tr><th>Discussion</th><td>$Discussion</td></tr>
<tr><th>Actions</th><td>$Actions</td></tr>
<tr><th>Date of Next Meeting</th><td>$Dateofnextmeeting</td></tr>
<tr><th>Status</th><td>$Status</td></tr>
<tr><th>E Number</th><td>$E_number</td></tr>
<tr><th>Supervisor Comments</th><td>$Supervisor_comments</td></tr>
</tr>";
}
}
?>
</table>
The Minute table within the database holds the following fields...
1 ID Primary int(10) AUTO_INCREMENT
2 B_number varchar(15) latin1_swedish_ci
3 Date date
4 Time time
5 Discussion text latin1_swedish_ci
6 Actions text latin1_swedish_ci
7 Dateofnextmeeting date
8 Status enum('Submitted', 'Approved', 'Rejected', '') latin1_swedish_ci
9 Supervisor_comments text latin1_swedish_ci
10 E_number varchar(15) latin1_swedish_ci
Please help :(
There are a few variables that I'm unsure of what they are - updating your question to include what $currentUser is would help.
That said, the issue may be in your SQL statement:
$db->prepare("select * from minute where '$currentUser'=B_number ");
You are selecting where $currentUser is equal to B_number. But in your database schema, you show that B_number is a column.
I'd try this SQL statement instead:
$db->prepare("SELECT * FROM `Minute` WHERE `B_number` = '" . $currentUser . "' AND `id` = " . $yourIDVariable );
Edit
Your viewstudentminutes.php will iterate over every record returned in your SQL query. You need to uniquely identify your Minute record to show just one on your viewstudentminutes.php page. You access this page via clicking on an <img> tag. But you never send data for which Minute object you want with this form. You could add this via:
<form class='display:inline' method='post' action='viewstudentminutes.php' onsubmit='viewstudentminutes.php'>
<input type='image' src='view.png' style='padding-top:7px'>
<input type='hidden' name='minute_id' value='" . $ID . "'>
</form>
Then access this on your viewstudentminutes.php as
$db->prepare("SELECT * FROM `Minute` WHERE `B_number` = '" . $currentUser . "' AND `id` = " . $_POST['minute_id']);
this code not asceding id. we have id 1, 2, 3, 15. when adding next record is read id 16. so how to solve this problem ? id must 1,2,3,4,5,etc
<?php
include"class_koneksi.php";
$db=new database();
$db->konek();
if(empty($_GET['aksi'])){
$daftar=$db->tampilData();
echo"<table border=1>
<tr>
<td>Id</td>
<td>Nama</td>
<td>Email</td>
<td>Pesan</td>
<td>Edit</td>
<td>Hapus</td>
</tr>";
foreach($daftar as $data){
echo" <tr>
<td>".$data['id']."</td>
<td>".$data['nama']."</td>
<td>".$data['email']."</td>
<td>".$data['pesan']."</td>
<td><a href='?aksi=edit&id=$data[id]'>edit</a></td>
<td><a href='?aksi=hapus_data&id=$data[id]'>Hapus</a></td>
</tr>";
}
echo"</table> <br> <a href='?aksi=tambah'>TAMBAH</a>";
}elseif(isset($_GET['aksi']) && $_GET['aksi']=='tambah'){
echo"<br>
<form method=POST action='?aksi=tambah_data'>
<table>
<tr><td>Nama</td><td><input type=text name='nama'></td></tr>
<tr><td>Email</td><td><input type=text name='email'></td></tr>
<tr><td>Pesan</td><td><input type=text name='pesan'></td></tr>
<tr><td></td><td><input type=submit value='simpan'></td></tr>
</table>
</form>
";
}elseif(isset($_GET['aksi']) && $_GET['aksi']=='tambah_data'){
$id= isset($_POST['id']);
$nama=$_POST['nama'];
$email=$_POST['email'];
$pesan=$_POST['pesan'];
$db->tambahData($id,$nama,$email,$pesan);
}elseif(isset($_GET['aksi']) && $_GET['aksi']=='edit'){
$id=$_GET['id'];
echo"<br>
<form method=POST action='?aksi=update_data'>
<table>
<tr><td>Id</td><td><input type=text name='id' value='".$db->bacaData('id',$id)."'></td></tr>
<tr><td>Nama</td><td><input type=text name='nama' value='".$db->bacaData('nama',$id)."'></td></tr>
<tr><td>Email</td><td><input type=text name='email' value='".$db->bacaData('email',$id)."'></td></tr>
<tr><td>Pesan</td><td><input type=text name='pesan' value='".$db->bacaData('pesan',$id)."'></td></tr>
<tr><td></td><td><input type=submit value='simpan'></td></tr>
</table>
<input type='hidden' name='id' value='".$db->bacaData('id',$id)."'>
</form>
";
}elseif(isset($_GET['aksi']) && $_GET['aksi']=='update_data'){
$id=$_POST['id'];
$nama=$_POST['nama'];
$email=$_POST['email'];
$pesan=$_POST['pesan'];
$db->updateData($id,$nama,$email,$pesan);
}elseif(isset($_GET['aksi']) && $_GET['aksi']=='hapus_data'){
$id=$_GET['id'];
$db->hapusData($id);
}
?>
can you tell me where this code wrong?
can you help me solve this problem? thanks
Remove the auto increment property of the table which is showing 16.
Before inserting a new row in that table write a select query.
$sql = "select * from `table_name`";
$result = mysql_query($sql);
$id=count($result)+1;
if(count($result)>0){
$temp = 1;
while($row = mysql_fetch_assoc($result)){
if($row['id']!=$temp++){
$id=$temp; break;
}
}
}
$sql = "insert into `table_name` (`id`,`..`,`..`) values('"$id.."','..','..')";
mysql_query($sql);
I hope this will solve your query...
It is showing id as 16 becouse in table properties Id is set as auto increment
First remove auto increment from id in the respective database table you are having this issue. Then Replace this code section with your code.
.
.
.
elseif(isset($_GET['aksi']) && $_GET['aksi']=='tambah'){
$daftar=$db->tampilData();
$id=count($daftar)+1;
if(count($daftar)>0){
$temp = 1;
forech($daftar as $row){
if($row['id']!=$temp++){
$id=$temp; break;
}
}
}
echo"<br>
<form method=POST action='?aksi=tambah_data'>
<table>
<tr><td>Nama</td><td><input type=text name='nama'><input type="hidden" name='id' value="<?php echo $id ?>"></td></tr>
<tr><td>Email</td><td><input type=text name='email'></td></tr>
<tr><td>Pesan</td><td><input type=text name='pesan'></td></tr>
<tr><td></td><td><input type=submit value='simpan'></td></tr>
</table>
</form>
";
}elseif(isset($_GET['aksi']) && $_GET['aksi']=='tambah_data'){
$id= $_POST['id'];
$nama=$_POST['nama'];
$email=$_POST['email'];
$pesan=$_POST['pesan'];
$db->tambahData($id,$nama,$email,$pesan);
}
.
.
.
I hope this solves your requirement..
im new in php! i currently display data from MySQL every time i search for name or idnumber and display all in to the html table but when i click the button on the table row i get the last value of the data.
here is the code i made:
$searchdata=mysql_query("select * from tblstudent where Last_name
='".$search."'")or die("Error Query");
if(isset($_POST['Search'])){
if(empty($search)){
$error_2="Search Box is empty";
}
elseif(strlen($search)<1){
$error_2="ERROR SEARCH";
}
else{
//display data to the table
echo "<div id='res'><form id='form1' method='POST' action=".basename(__FILE__).">
Reservation Fees:<input id='descriptive' name='reserv' type='text' /> ";
echo "<table id='example' border='1'>
<tr>
<th>ID NUMBER</th>
<th>LAST NAME</th>
<th>FIRST NAME</th>
<th>MIDDLE NAME</th>
<th>COURSE</th>
<th>GENDER</th>
</tr>";
while($row=mysql_fetch_array($searchdata)){
$studentid=$row['student_id'];
$coursee=$row['Course'];
$lnamee=$row['Last_name'];
$fnamee=$row['First_name'];
$mnamee=$row['M_name'];
$gnder=$row['Gender'];
echo "
<tr>
<td>".$studentid." <input type='hidden' name='dummyID' value='$studentid'></td>
<td>".$lnamee." <input type='hidden' name='dummylname' value='$lnamee'></td>
<td>".$fnamee."<input type='hidden' name='dummyfname' value='$fnamee'></td>
<td>".$mnamee."<input type='hidden' name='dummymname' value='$mnamee'></td>
<td>".$coursee."<input type='hidden' name='dummycourse' value='$coursee'></td>
<td>".$gnder."<input type='hidden' name='dummygnder' value='$gnder'></td>
<td><input id='send' name='add' type='submit' value='Reserve' /></td>
</tr>";
}
echo "</table>
</form></div>";
}}}
you have a form with multiple elements named dummyID, dummylname, etc. So the value that gets submitted is just the last one you output.
Add in an index {$i} to determine which row is being submitted.
$i = 0;
while($row=mysql_fetch_array($searchdata)){
$studentid=$row['student_id'];
$coursee=$row['Course'];
$lnamee=$row['Last_name'];
$fnamee=$row['First_name'];
$mnamee=$row['M_name'];
$gnder=$row['Gender'];
echo "
<tr>
<td>".$studentid." <input type='hidden' name='dummyID[$i]' value='$studentid'></td>
<td>".$lnamee." <input type='hidden' name='dummylname[$i]' value='$lnamee'></td>
<td>".$fnamee."<input type='hidden' name='dummyfname[$i]' value='$fnamee'></td>
<td>".$mnamee."<input type='hidden' name='dummymname[$i]' value='$mnamee'></td>
<td>".$coursee."<input type='hidden' name='dummycourse[$i]' value='$coursee'></td>
<td>".$gnder."<input type='hidden' name='dummygnder[$i]' value='$gnder'></td>
<td><input id='send' name='add[$i]' type='submit' value='Reserve' /></td>
</tr>";
$i++
}
Then process the data like:
if(!empty($_POST['add'])) {
$i = current(array_keys($_POST['add']));
$studentid=$_POST['dummyID'][$i]
$coursee=$_POST['dummycourse'][$i];
$lnamee=$_POST['dummylname'][$i];
$fnamee=$_POST['dummyfname'][$i];
$mnamee=$_POST['dummymname'][$i];
$gnder=$_POST['dummygnder'][$i];
}