PHP select option values when use with echo - php

I am trying to show details in a table and show list of values in drop down list. the values are shown in table but drop down list is not showing the values although the values exists and when i save it in session and print it, it appears at the top . Also I have problem in using name of select. when i click on button and wants to read the post value of the option, it gives me error as shown in figure
here is the code:
for($i=0;$i<count($dr_ide);$i=$i+5)
{
echo "<tr>";
echo "<td> Dr. " . $dr_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i+1] . "</td>";
echo "<td>" . $sub_namee[$i+2] . "</td>";
echo "<td>" . $sub_namee[$i+3] . "</td>";
echo "<td>" . $sub_namee[$i+4] . "</td>";
echo "<td> <select name='perr' >
<option name='perr' selected=selected>Choose one</option>";
foreach($Names as $name) {
echo"<option name='perr' value=";
$name ;
echo "> ";
$_SESSION["tt"]=$name;
$name;
echo"</option>";
}
echo "</select></td>";
//echo "<td>" . $dayse[$i] . "</td>";
//echo "<td>" . $timing[$i] . "</td>";
echo "</tr>";
}
}
echo $_SESSION["tt"];
if(isset($_POST['confirm'])){
echo $_POST['perr'];
}
Here is my full page code.
<html>
<head>
<title> Expert System </title>
<link rel="stylesheet" type="text/css" href="style.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:700,600' rel='stylesheet' type='text/css'>
</head>
<body>
<div >
<table id="cells2" border="0" cellpadding="15" cellspacing="5" font size="6">
<tr>
<th><img id="header2" src="images/Kuwait_University_Logo.jpg" > </th>
<th>KUWAIT UNIVERSITY</th>
</tr>
</table>
<div class='back1'>
<table border='1' align='center' id='customers' >
<?php
require "init.php";
session_start();
global $con,$users,$dr_id,$sub_id,$dr_name,$sub_name,$days,$fav,$timing;
global $dr_ide,$dr_namee,$sub_namee,$dayse,$fave,$timinge;
$query= "SELECT * FROM subjects_current where subjects_current.sub_ID NOT IN (SELECT test.subject_id from test)";
$result=mysqli_query($con,$query);
if ( $result->num_rows == 0 ) // User doesn't exist
echo "Subjects doesn't exist!";
else {
while($row = mysqli_fetch_array($result))
{
$IDs[]=$row['sub_ID'];
$Names[]=$row['Name'];
//echo $row['Name'];
}
}
$query= "SELECT * FROM test order by dr_id";
$result=mysqli_query($con,$query);
if ( $result->num_rows == 0 ) // User doesn't exist
echo "Subjects doesn't exist!";
else { echo "
<tr>
<th>Professor Name</th>
<th>First Choice</th>
<th>Second Choice</th>
<th>Third Choice</th>
<th>Fourth Choice</th>
<th>Fifth Choice</th>
<th>Update Subject</th>
</tr>";
$r=0;
$f=0;
while($row = mysqli_fetch_array($result))
{
$dr_ide[$f]=$row['dr_id'];
$dr_namee[$f]=$row['dr_name'];
$sub_namee[$f]=$row['sub_name'];
$dayse[$f]=$row['days'];
$timinge[$f]=$row['timing'];
$fave[$f]=$row['fav'];
//echo "<tr>";
//echo "<td> Dr. " . $dr_namee[$f] . "</td>";
//echo "<td>" . $sub_namee[$f] . "</td>";
//echo "<td>" . $fave[$f] . "</td>";
//echo "<td>" . $dayse[$f] . "</td>";
//echo "</tr>";
//$r++;
$f++;
}
//for($i=0;$i<count($Names);$i=$i+5)
//{
for($i=0;$i<count($dr_ide);$i=$i+5)
{
echo "<tr>";
echo "<td> Dr. " . $dr_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i+1] . "</td>";
echo "<td>" . $sub_namee[$i+2] . "</td>";
echo "<td>" . $sub_namee[$i+3] . "</td>";
echo "<td>" . $sub_namee[$i+4] . "</td>";
echo "<td> <select name='perr' >
<option name='perr' selected=selected>Choose one</option>";
foreach($Names as $name) {
echo"<option name='perr' value='$name'>$name</option>";
}
echo "</select></td>";
//echo "<td>" . $dayse[$i] . "</td>";
//echo "<td>" . $timing[$i] . "</td>";
echo "</tr>";
}
}
echo $_SESSION["tt"];
if(isset($_POST['confirm'])){
echo $_POST['perr'];
}
?>
</table>
<form method='post' action='edit_subjects.php'>
<input ID="btn2" name="confirm" type="submit" value="Home">
</form>
</div>
</body>
</html>

Remove name='perr' from <options> and change foreach() like below:-
foreach($Names as $name) {
echo"<option value='$name'>$name</option>";
}
Do change in your code like this:-
echo "<form method='post' action='edit_subjects.php'>"; //add before while
while($row = mysqli_fetch_array($result))
{
$dr_ide[$f]=$row['dr_id'];
$dr_namee[$f]=$row['dr_name'];
$sub_namee[$f]=$row['sub_name'];
$dayse[$f]=$row['days'];
$timinge[$f]=$row['timing'];
$fave[$f]=$row['fav'];
$f++;
}
for($i=0;$i<count($dr_ide);$i=$i+5)
{
$dr_nam = $dr_namee[$i];
echo "<tr>";
echo "<td> Dr. " . $dr_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i+1] . "</td>";
echo "<td>" . $sub_namee[$i+2] . "</td>";
echo "<td>" . $sub_namee[$i+3] . "</td>";
echo "<td>" . $sub_namee[$i+4] . "</td>";
echo "<td><select name='perr[$dr_nam]' >
<option name='perr' selected=selected>Choose one</option>";
foreach($Names as $name) {
echo"<option name='perr' value='$name'>$name</option>";
}
echo "</select></td>";
echo "</tr>";
}
echo"<input ID='btn2' name='confirm' type='submit' value='Home'></form>"; //add just after while code ended

echo "<td> <select name='perr' >
<option name='perr' selected='selected'> Choose one </option>";
foreach($Names as $name) {
echo"<option name='perr' value='". $name ."'> ". $name ." </option>";
}
echo "</select></td>";

You have to echo the names like this:
foreach($Names as $name) {
echo "<option value=";
echo $name ;
echo "> ";
$_SESSION["tt"]=$name;
echo $name;
echo"</option>";
}
And put the table inside the form:
<html>
<head>
<title> Expert System </title>
<link rel="stylesheet" type="text/css" href="style.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:700,600' rel='stylesheet' type='text/css'>
</head>
<body>
<div >
<table id="cells2" border="0" cellpadding="15" cellspacing="5" font size="6">
<tr>
<th><img id="header2" src="images/Kuwait_University_Logo.jpg" > </th>
<th>KUWAIT UNIVERSITY</th>
</tr>
</table>
<div class='back1'>
<form method='post' action='edit_subjects.php'>
<table border='1' align='center' id='customers' >
<?php
require "init.php";
session_start();
global $con,$users,$dr_id,$sub_id,$dr_name,$sub_name,$days,$fav,$timing;
global $dr_ide,$dr_namee,$sub_namee,$dayse,$fave,$timinge;
$query= "SELECT * FROM subjects_current where subjects_current.sub_ID NOT IN (SELECT test.subject_id from test)";
$result=mysqli_query($con,$query);
if ( $result->num_rows == 0 ) // User doesn't exist
echo "Subjects doesn't exist!";
else {
while($row = mysqli_fetch_array($result))
{
$IDs[]=$row['sub_ID'];
$Names[]=$row['Name'];
//echo $row['Name'];
}
}
$query= "SELECT * FROM test order by dr_id";
$result=mysqli_query($con,$query);
if ( $result->num_rows == 0 ) // User doesn't exist
echo "Subjects doesn't exist!";
else { echo "
<tr>
<th>Professor Name</th>
<th>First Choice</th>
<th>Second Choice</th>
<th>Third Choice</th>
<th>Fourth Choice</th>
<th>Fifth Choice</th>
<th>Update Subject</th>
</tr>";
$r=0;
$f=0;
while($row = mysqli_fetch_array($result))
{
$dr_ide[$f]=$row['dr_id'];
$dr_namee[$f]=$row['dr_name'];
$sub_namee[$f]=$row['sub_name'];
$dayse[$f]=$row['days'];
$timinge[$f]=$row['timing'];
$fave[$f]=$row['fav'];
//echo "<tr>";
//echo "<td> Dr. " . $dr_namee[$f] . "</td>";
//echo "<td>" . $sub_namee[$f] . "</td>";
//echo "<td>" . $fave[$f] . "</td>";
//echo "<td>" . $dayse[$f] . "</td>";
//echo "</tr>";
//$r++;
$f++;
}
//for($i=0;$i<count($Names);$i=$i+5)
//{
for($i=0;$i<count($dr_ide);$i=$i+5)
{
echo "<tr>";
echo "<td> Dr. " . $dr_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i] . "</td>";
echo "<td>" . $sub_namee[$i+1] . "</td>";
echo "<td>" . $sub_namee[$i+2] . "</td>";
echo "<td>" . $sub_namee[$i+3] . "</td>";
echo "<td>" . $sub_namee[$i+4] . "</td>";
echo "<td> <select name='perr' >
<option selected=selected>Choose one</option>";
foreach($Names as $name) {
echo"<option value='$name'>$name</option>";
}
echo "</select></td>";
//echo "<td>" . $dayse[$i] . "</td>";
//echo "<td>" . $timing[$i] . "</td>";
echo "</tr>";
}
}
echo $_SESSION["tt"];
if(isset($_POST['confirm'])){
echo $_POST['perr'];
}
?>
</table>
<input ID="btn2" name="confirm" type="submit" value="Home">
</form>
</div>
</body>
</html>

Related

Adding up array elements in php table

i wanted to ask I would I add up the points of all the drivers in the table produced below by the following code as this only displays points of all the drivers in each row ... There is a table Points which has points, position and a table Drivers having forename, surname.
<?php
session_start();
if ( !isset($_SESSION['loggedin']) ) {
header("Location: login.php");
}
$con=mysqli_connect("xxxxx","xxxxx","xxxxx","xxxx");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT Drivers.forename, Drivers.surname, Teams.name, Teams.engine, Points.points
From Drivers, Teams, Points");
echo "<table border='1'>
<tr>
<th>First name</th>
<th>Last name</th>
<th>Team Name</th>
<th>Engine</th>
<th>Points</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['forename'] . "</td>";
echo "<td>" . $row['surname'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['engine'] . "</td>";
echo "<td>" . $row['points'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
in your code, before the $while
$counter=0
while($row = mysqli_fetch_array($result))
{
$counter += $row['points'];
echo "<tr>";
echo "<td>" . $row['forename'] . "</td>";
echo "<td>" . $row['surname'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['engine'] . "</td>";
echo "<td>" . $row['points'] . "</td>";
echo "</tr>";
}
echo $counter; //echoes sum of points

Multiple delete through checkout

I am stuck in one of my application module. I have to set multiple delete options in my application.
I have used the below code. The designing is perfectly fine. All what I want to add multiple delete options in it.
Below is the code which I have tried out:
<html>
<head>
<title>Strad Hosting Limited -Web Hosting</title>
<script language="javascript">
function validate()
{
var chks = document.getElementsByName('checkbox[]');
var hasChecked = false;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
hasChecked = true;
break;
}
}
if (hasChecked == false)
{
alert("Please select at least one.");
return false;
}
return true;
}
</script>
</head>
<body >
<?php
$con=mysqli_connect("localhost","stradsol","D#v,b5TnQ!D!","stradsol_sales");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons");
echo "<form name='form1' method='post' action='' onSubmit='return validate();'>";
echo "<table border='1' style='
background-color: white;'>
<tr>
<th></th>
<th>id</th>
<th style='padding-left: 11px;'>Lead Generated Date </th>
<th>name</th>
<th>email</th>
<th>contacts</th>
<th>requirement</th>
<th style='display:none;'>Company name</th>
<th style='display:none;'>Address</th>
<th>Next Follow-Up date</th>
<th>Final_Details</th>
<th style='display:none;'>Status</th>
<th style='padding-left: 12px; display:none;'>Lead Closed Date</th>
<th>EDIT</th>
<th>Follow-up History</th>
<th>Add Follow-up</th>
<th>Delete Record</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td><input name='checkbox[]' type='checkbox' id='checkbox[]' value='".$rows['id']."'></td>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td><a href='config_info.php?id=" . $row['id'] . "'>".$row['name']."</a></td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['contacts'] . "</td>";
echo "<td>" . $row['requirement'] . "</td>";
echo "<td style='display:none;'>" . $row['company_name'] . "</td>";
echo "<td style='display:none;'>" . $row['address'] . "</td>";
echo "<td>" . $row['startdate'] . "</td>";
echo "<td>" . $row['final_details'] . "</td>";
echo "<td style='display:none;'>" . $row['status'] . "</td>";
echo "<td style='display:none;'>" . $row['lead_close'] . "</td>";
echo "<td><a href='edit_eg1.php?id=" . $row['id'] . "'>Edit</a></td>";
echo "<td><a href='Follow_history.php?id=" . $row['id'] . "'>Follow_history</a></td>";
echo "<td><a href='add_follow.php?id=" . $row['id'] . "'>Followup</a></td>";
echo "<td><a href='delete.php?id=" . $row['id'] . "'>Delete</a></td>";
echo "</tr>";
}
echo "<tr><td><input name='delete' type='submit' id='delete' value='Delete'></td></tr>";
$count=mysqli_num_rows($result);
if(isset($_POST['delete'])){
for($i=0;$i<count($_POST['checkbox']);$i++){
$del_id=$_POST['checkbox'][$i];
$sql = "DELETE FROM Persons WHERE id='$del_id'";
echo $sql;
$result2 = mysqli_query($con,$sql);
}
// if successful redirect to delete_multiple.php
if($result2)
{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=edit_table_del.php\">";
}
}
mysqli_close($con);
echo "</table>";
echo "</form>";
?>
<br><br>
[ Back To Home ]
</body>
</html>
I am stuck, the query is not working I think. I don't know what I am missing.
Try replacing
$sql = "DELETE FROM Persons WHERE id='$del_id'";
With
$sql = "DELETE FROM Persons WHERE id=$del_id";
I'm assuming the ID is a number so the single quotes aren't needed.

If functions per $row in a table

I have a table that shows me data from a call flow.
I need the Data from this table to be manipulated per row in such a way that all the values of my table, which are being looked up from my DB, (which are now in code) will be translated into a text value. Let me show U and explain:
My Table:
<?php
include_once "Connect2Martijn1.php";
?>
<link rel="stylesheet" href="CSSMartijn1.css">
</link>
<head>
<meta charset="iso-8859-1">
<meta name="description"content="VoizXL ">
<meta name="keywords"content="VoizXL ">
<meta name="author"content="Kenn Lo-A-Tjong">
</meta>
<title>Call Flow</title>
</head>
<fieldset>
<article class="rondehoeken">
<header>
<div class="streep1"></div>
<div class="streep2"></div>
<div class="streep3"></div>
<div class="streep4"></div>
<div class="streep5"></div>
<h1 id="artikel-titel" >Call Flow</h1>
</header>
<div id="artikel-container">
<table class="table 1">
<thead>
<title>Call Flow</title>
<meta charset = "UTF-8" />
<style type = "text/css">
table, td, th {
border: 1px solid black;
}
</style>
</thead>
<tbody>
<?php
$con=mysqli_connect("localhost","root","","voizxl_wachtrij");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Callflow");
echo "<table border='0'>
<tr>
<th>Nummer</th>
<th>Naam</th>
<th>Status</th>
<th>Time</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . $row['statusAnswered'] . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Example of (how I want to be) Translating the Data:
<?php
if ($row['statusAnswered'] ="NULL")
{
echo "Not Answered!";
}
else
{
echo "Answered!";
}
?>
What I want to Achieve is for eg. that the value in this table from $row['statusAnswered'] will be displayed in text as "Answered or Not Answered" if the Value of this row in the DB is NULL or Not...
How do I do this?
Right now I can only achieve to have 1 echo under the table saying Answered :S
No Idea how to put it per $row.
while($row = mysqli_fetch_array($result))
{
if (!isset($row['statusAnswered']))
{
$answered = "Not Answered!";
}
else
{
$answered = "Answered!";
}
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . $answered . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
if ($row['statusAnswered'] =="NULL"||$row['statusAnswered'] =="Null" || $row['statusAnswered'] =="null" || $row['statusAnswered'] =="")
{
echo "<td>Not Answered!</td>";
}
else
{
echo "<td>Answered!</td>";
}
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<table border='0'>
<tr>
<th>Nummer</th>
<th>Naam</th>
<th>Status</th>
<th>Time</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . ($row['statusAnswered']=='NULL'?'Not Answered!':'Answered!') . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";
You could use;
$checkstatus = if($row['statusAnswered'] = NULL) { echo "Not Answered!"; } else {echo "Answered!";};
then call that by replacing;
echo "<td>" . $row['statusAnswered'] . "</td>";
with;
echo "<td>{$checkstatus}</td>"

make checkbox automatically checked within table PHP

I am new to PHP and I have problem. I have a table with check boxes. I need to add if statement inside the check box.
echo "<div class='table1'>
<table>
<tr>
<td></td>
<td>Module code</td>
<td>Module Title</td>
<td>Option</td>
</tr>";
echo "<form action='confirmsubmission.php' method='post'>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . "<input type='checkbox' name='check[]'
value='".$row['module_id']."' />" . "</td>";
echo "<td>" . $row['module_id'] . "</td>";
echo "<td>" . $row['module_title'] . "<a href=# content='".$row['description']."'
class='tooltip'><span title='Module Description'><img src='images/i.png'/></span>
</a>". "</td>";
echo "<td>" . $row['module_choice'] . "</td>";
echo "</tr>";
}
echo "</table></div>";
Below is a If statement I need to add after value='".$row['module_id']."'
if($row['module_choice']=='Mandatory'){ echo "checked=\"true\""; }
A bit of a mouthful, but try:
...
echo "<td>" . "<input type='checkbox' name='check[]' value='".$row['module_id']."'".($row['module_choice']=='Mandatory' ? 'checked="true"' : "")." />" . "</td>";
...
Even though I'll advise you to use a templating system (Smarty, etc.), you can do the following code:
echo "<div class='table1'>
<form action='confirmsubmission.php' method='post'>
<table>
<tr>
<td></td>
<td>Module code</td>
<td>Module Title</td>
<td>Option</td>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . "<input type='checkbox' name='check[]'
value='".$row['module_id']."'";
if($row['module_choice']=='Mandatory'){
echo " checked='checked' ";
}
echo "/>" . "</td>";
echo "<td>" . $row['module_id'] . "</td>";
echo "<td>" . $row['module_title'] . "<a href=# content='".$row['description']."'
class='tooltip'><span title='Module Description'><img src='images/i.png'/></span>
</a>". "</td>";
echo "<td>" . $row['module_choice'] . "</td>";
echo "</tr>";
}
echo "</table></form></div>";

Approve Form submit

I have trouble with creating an approval form as am still php beginner,
the idea is
user submit a form am setting a default value"0" in the approved row at the table..
so behind the scenes the admin shows all members from this table where approved="0"
and this is the code
<code>
<?php
$con = mysql_connect("localhost","ebarea_epic","...");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ebarea_epic", $con);
$query = "select * from medicalrep where approved='0'";
$result=mysql_query($query);
echo "<table border='1'>
<tr>
<th>User Name</th>
<th>Password</th>
<th>Mobile </th>
<th>Address</th>
<th>Faculty</th>
<th>Graduation Year</th>
<th>Region</th>
<th>Area</th>
<th>Line</th>
<th>Appointment Date</th>
<th>Resign Data</th>
<th>Job Title</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "<td>" . $row['Mobile'] . "</td>";
echo "<td>" . $row['Address'] . "</td>";
echo "<td>" . $row['Faculty'] . "</td>";
echo "<td>" . $row['Graduation Year'] . "</td>";
echo "<td>" . $row['Region'] . "</td>";
echo "<td>" . $row['Line'] . "</td>";
echo "<td>" . $row['Area'] . "</td>";
echo "<td>" . $row['Appointment'] . "</td>";
echo "<td>" . $row['Resign'] . "</td>";
echo "<td>" . $row['job_title'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</code>
I just want to add checkbox for every table user and when checked thier status changed to 1 in approved column
thanks all
$con = mysql_connect("localhost","ebarea_epic","...");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ebarea_epic", $con);
$query = "select * from medicalrep where approved='0'";
$result=mysql_query($query);
$i = 1; //counter for the checkboxes so that each has a unique name
echo "<form action='process.php' method='post'>"; //form started here
echo "<table border='1'>
<tr>
<th>User Name</th>
<th>Password</th>
<th>Mobile </th>
<th>Address</th>
<th>Faculty</th>
<th>Graduation Year</th>
<th>Region</th>
<th>Area</th>
<th>Line</th>
<th>Appointment Date</th>
<th>Resign Data</th>
<th>Job Title</th>
<th>Update</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['password'] . "</td>";
echo "<td>" . $row['Mobile'] . "</td>";
echo "<td>" . $row['Address'] . "</td>";
echo "<td>" . $row['Faculty'] . "</td>";
echo "<td>" . $row['Graduation Year'] . "</td>";
echo "<td>" . $row['Region'] . "</td>";
echo "<td>" . $row['Line'] . "</td>";
echo "<td>" . $row['Area'] . "</td>";
echo "<td>" . $row['Appointment'] . "</td>";
echo "<td>" . $row['Resign'] . "</td>";
echo "<td>" . $row['job_title'] . "</td>";
echo "<td><input type='checkbox' name='check[$i]' value='".$row['ID']."'/>";
echo "</tr>";
$i++;
}
echo "</table>";
echo "<input type='submit' name='approve' value='approve'/>";
echo "</form>";
mysql_close($con);
Now comes process.php
if(isset($_POST['approve'])){
if(isset($_POST['check'])){
foreach ($_POST['check'] as $value){
$sql = "UPDATE post SET post_approved = 1 WHERE ID = $value"; //write this query according to your table schema
mysql_query($sql) or die (mysql_error());
}
}
}
though you are using mysql_* functions here, i recommend you to use PDO
EDIT:
As per your request, this is the update.
Change this code in your admin panel script:
echo "<input type='submit' name='approve' value='approve'/>";
Delete the above line and add this instead:
echo "<input class='action' type='button' name='approve' value='approve' />";
echo "<input class='action' type='button' name='edit' value='edit' />";
echo "<input class='action' type='button' name='delete' value='delete' />";
echo "<input type='hidden' name='action' value='' id='action' />"; //Action (edit, approve or delete) will be set here which will be passed as POST variable on form submission
Now you will need some javascript to do some tricks.
Add the following code preferably head section in your admin panel script
<script type="text/javascript" src="jquery-1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.action').click(function(){
var action = $(this).attr('name');
$('#action').val(action);
$(this).closest('form').submit();
})
})
</script>
Now comes the modification in process.php file
if (isset($_POST['approve'])) {
if (isset($_POST['check'])) {
foreach ($_POST['check'] as $value) {
$sql = "UPDATE post SET post_approved = 1 WHERE ID = $value"; //write this query according to your table schema
mysql_query($sql) or die(mysql_error());
}
}
} elseif(isset($_POST['edit'])){
//do the edit things here
} elseif(isset($_POST['delete'])){
foreach ($_POST['check'] as $value){
$sql = "DELETE FROM post WHERE ID=$value";//modify it
mysql_query($sql) or die(mysql_error());
}
}
NOTE
You may not want to mutiple checkbox for edit. You just need to tweak the javascript code above a little and it'l send the ID as a post variable on form submission from which you can retreive the details for one entry and then edit functions will come. I'l leave it to you. try it, post your trial code here and i'l give you a solution if it doesn't work.

Categories