Unable to filter data from mysql - php

I tried to read data of my MySQL database, I created the fullcalendar and show up the event on calendar. However, it is unable to retrieve the data from my MySQL database.
The First php code :
<?php require_once('conn.php'); ?>
<?php $maxRows_RsCourse = 1000000;
$pageNum_RsCourse = 0;
if (isset($_GET['pageNum_RsCourse'])) {
$pageNum_RsCourse = $_GET['pageNum_RsCourse'];
}
$startRow_RsCourse = $pageNum_RsCourse * $maxRows_RsCourse;
mysql_select_db($database_conn, $conn);
$query_RsCourse = "SELECT * FROM tbl_course ORDER BY tcid ASC";
$query_limit_RsCourse = sprintf("%s LIMIT %d, %d", $query_RsCourse, $startRow_RsCourse, $maxRows_RsCourse);
$RsCourse = mysql_query($query_limit_RsCourse, $conn) or die(mysql_error());
$row_RsCourse = mysql_fetch_assoc($RsCourse);
if (isset($_GET['totalRows_RsCourse'])) {
$totalRows_RsCourse = $_GET['totalRows_RsCourse'];
} else {
$all_RsCourse = mysql_query($query_RsCourse);
$totalRows_RsCourse = mysql_num_rows($all_RsCourse);
}
$totalPages_RsCourse = ceil($totalRows_RsCourse/$maxRows_RsCourse)-1;
?>
<?php
$tbl_name="tbl_course"; // Table name
$totalcount = 0;
// Connect to server and select database.
mysql_connect("$hostname_conn", "$username_conn", "$password_conn")or die("cannot connect server ");
mysql_select_db("$database_conn")or die("unable to connect");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
// echo "<table><tr>";
// echo "<td>" . $rows['id'] . "</td><td>" . $rows['title'] . "</td><td>" . $rows['start'] . "</td><td>" . $rows['end'] . "</td><td>" . $rows['url'] . "</td><td>" . $rows['allDay'];
// echo "</td></tr></table>";
$event[$totalcount]['tcid']=$rows['tcid'];
$event[$totalcount]['courseid']=$rows['courseid'];
$event[$totalcount]['coursename']=$rows['coursename'];
$event[$totalcount]['startdate']=$rows['startdate'];
$event[$totalcount]['starttime']=$rows['starttime'];
$event[$totalcount]['enddate']=$rows['enddate'];
$event[$totalcount]['endtime']=$rows['endtime'];
$event[$totalcount]['allday']=$rows['allday'];
$totalcount++;
}
for ($i=0; $i < $totalcount; $i++)
{
$tmp1 = explode("-",$event[$i]['startdate']);
$tmp2 = explode(":",$event[$i]['starttime']);
// 0 = hour, 1 = minutes, 2 = seconds,
$x = 0;
foreach ($tmp1 as $date_values_1)
{
$event_start_date[$i][$x] = $date_values_1;
$x++;
}
$y = 0;
foreach ($tmp2 as $time_values_1)
{
$event_start_time[$i][$y] = $time_values_1;
$y++;
}
$tmp3 = explode("-",$event[$i]['enddate']);
$tmp4 = explode(":",$event[$i]['endtime']);
$a = 0;
foreach ($tmp3 as $date_values_2)
{
$event_end_date[$i][$a] = $date_values_2;
$a++;
}
$b = 0;
foreach ($tmp4 as $time_values_2)
{
$event_end_time[$i][$b] = $time_values_2;
$b++;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0046)http://localhost/calendar/demos/db_display.php -->
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<link href='css/fullcalendar.css' rel='stylesheet' />
<script src='js/jquery-1.9.1.min.js'></script>
<script src='js/jquery-ui-1.10.2.custom.min.js'></script>
<script src='js/fullcalendar.min.js'></script>
<SCRIPT>
$(document).ready(function() {
var start_year = new Array(<?php $totalcount?>);
var start_month = new Array(<?php $totalcount?>);
var start_day = new Array(<?php $totalcount?>);
var end_year =new Array(<?php $totalcount?>);
var end_month =new Array(<?php $totalcount?>);
var end_day =new Array(<?php $totalcount?>);
var start_hour =new Array(<?php $totalcount?>);
var start_mins =new Array(<?php $totalcount?>);
var end_hour =new Array(<?php $totalcount?>);
var end_mins =new Array(<?php $totalcount?>);
<?php
$k = 0;
for ($k=0; $k < $totalcount; $k++) {?>
start_year[<?php echo $k?>] =<?php echo $event_start_date[$k][0] ?>;
start_month[<?php echo $k?>] =<?php echo $event_start_date[$k][1] ?>;
start_day[<?php echo $k?>] =<?php echo $event_start_date[$k][2]?>;
end_year[<?php echo $k?>] =<?php echo $event_end_date[$k][0]?>;
end_month[<?php echo $k?>] =<?php echo $event_end_date[$k][1]?>;
end_day[<?php echo $k?>] =<?php echo $event_end_date[$k][2]?>;
start_hour[<?php echo $k?>] =<?php echo $event_start_time[$k][0] ?>;
start_mins[<?php echo $k?>] =<?php echo $event_start_time[$k][1] ?>;
end_hour[<?php echo $k?>] =<?php echo $event_end_time[$k][0]?>;
end_mins[<?php echo $k?>] =<?php echo $event_end_time[$k][1]?>;
<?php } ?>
var calendar = $('#calendar').fullCalendar({
editable: false,
events: [
<?php $j = 0;
for ($j=0; $j < $totalcount; $j++)
{
?>
<?php
if ($event[$j]['allday'] == 0){?>
{ title: '<?php echo $event[$j]['courseid'];?> <?php echo $event[$j]['coursename'];?>',
start: new Date(start_year[<?php echo $j?>],start_month[<?php echo $j?>]-1,start_day[<?php echo $j?>],start_hour[<?php echo $j?>],start_mins[<?php echo $j?>]),
end: new Date(end_year[<?php echo $j?>],end_month[<?php echo $j?>]-1,end_day[<?php echo $j?>],end_hour[<?php echo $j?>],end_mins[<?php echo $j?>]) , url: 'mg_course.php?courseid=<?php echo $event[$j]['courseid']; ?>'
/*
end: new Date(end_year[<?php echo $j?>],end_month[<?php echo $j?>]-1,end_day[<?php echo $j?>],end_hour[<?php echo $j?>],end_mins[<?php echo $j?>]) , url: 'mg_course.php?courseid=<?php echo $_GET['courseid']; ?>'
*/
},
<?php } ?>
<?php if ($event[$j]['allday'] == 1) {?>
{ title: '<?php echo $event[$j]['courseid'];?> <?php echo $event[$j]['coursename'];?>',
start: new Date(start_year[<?php echo $j?>],start_month[<?php echo $j?>]-1,start_day[<?php echo $j?>],start_hour[<?php echo $j?>],start_mins[<?php echo $j?>]),
end: new Date(end_year[<?php echo $j?>],end_month[<?php echo $j?>]-1,end_day[<?php echo $j?>],end_hour[<?php echo $j?>],end_mins[<?php echo $j?>]), url: 'mg_course.php?courseid=<?php echo $event[$j]['courseid']; ?>',
/*
end: new Date(end_year[<?php echo $j?>],end_month[<?php echo $j?>]-1,end_day[<?php echo $j?>],end_hour[<?php echo $j?>],end_mins[<?php echo $j?>]), url: 'mg_course.php?courseid=<?php echo $_GET['courseid']; ?>',
*/
allDay: 'false'
},
<?php } ?>
<?php }?>
{}
]
});
});
</SCRIPT>
<STYLE>BODY {
TEXT-ALIGN: center; MARGIN-TOP: 40px; FONT-FAMILY: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif; FONT-SIZE: 14px
}
#calendar {
MARGIN: 0px auto; WIDTH: 900px
}
</STYLE>
<META name=GENERATOR content="MSHTML 8.00.6001.19412"></HEAD>
<BODY>
<DIV id=calendar></DIV></BODY></HTML>
Here is display event details php:
<?php require_once('conn.php'); ?>
<?php
session_start();
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
?>
<?php
$totalRows_RsEnrol = 0;
if ( isset($_POST['courseid']) ) {
$_GET['courseid'] = $_POST['courseid'];
$_GET['courseid'] = $_GET['courseid'] * 1;
if (is_integer($_GET['courseid']) ) {
$maxRows_RsEnrol = 10000;
$pageNum_RsEnrol = 0;
if (isset($_GET['pageNum_RsEnrol'])) {
$pageNum_RsEnrol = $_GET['pageNum_RsEnrol'];
}
$startRow_RsEnrol = $pageNum_RsEnrol * $maxRows_RsEnrol;
mysql_select_db($database_conn, $conn);
$query_RsEnrol = "SELECT * FROM 'tbl_enroll' WHERE 'tbl_enroll'.'courseid' = '".$_GET['courseid']."'";
//$query_RsEnrol = sprintf("SELECT erid, courseid, staffid FROM tbl_enroll WHERE courseid = %s ORDER BY staffid ASC", $_GET['courseid']);
$query_limit_RsEnrol = sprintf("%s LIMIT %d, %d", $query_RsEnrol, $startRow_RsEnrol, $maxRows_RsEnrol);
$RsEnrol = mysql_query($query_limit_RsEnrol, $conn) or die(mysql_error());
$row_RsEnrol = mysql_fetch_assoc($RsEnrol);
if (isset($_GET['totalRows_RsEnrol'])) {
$totalRows_RsEnrol = $_GET['totalRows_RsEnrol'];
} else {
$all_RsEnrol = mysql_query($query_RsEnrol);
$totalRows_RsEnrol = mysql_num_rows($all_RsEnrol);
}
$totalPages_RsEnrol = ceil($totalRows_RsEnrol/$maxRows_RsEnrol)-1;
} else { $totalRows_RsEnrol = 0;}
}
/******************************************************************************************************/
elseif (isset($_GET['courseid']) && !empty($_GET['courseid']) ) {
$_GET['courseid'] = $_GET['courseid']*1;
if (is_integer($_GET['courseid'])){
$maxRows_RsEnrol = 1000000;
$pageNum_RsEnrol = 0;
if (isset($_GET['pageNum_RsEnrol'])) {
$pageNum_RsEnrol = $_GET['pageNum_RsEnrol'];
}
$startRow_RsEnrol = $pageNum_RsEnrol * $maxRows_RsEnrol;
mysql_select_db($database_conn, $conn);
$query_RsEnrol = sprintf("SELECT * FROM tbl_enroll WHERE courseid IN ( SELECT courseid FROM tbl_course WHERE courseid = %s) ORDER BY erid ASC", $_GET['courseid']);
//$query_RsEnrol = sprintf("SELECT erid, courseid, staffid FROM tbl_enroll WHERE courseid=%s ORDER BY staffid ASC", $_GET['courseid']);
$query_limit_RsEnrol = sprintf("%s LIMIT %d, %d", $query_RsEnrol, $startRow_RsEnrol, $maxRows_RsEnrol);
$RsEnrol = mysql_query($query_limit_RsEnrol, $conn) or die(mysql_error());
$row_RsEnrol = mysql_fetch_assoc($RsEnrol);
if (isset($_GET['totalRows_RsEnrol'])) {
$totalRows_RsEnrol = $_GET['totalRows_RsEnrol'];
} else {
$all_RsEnrol = mysql_query($query_RsEnrol);
$totalRows_RsEnrol = mysql_num_rows($all_RsEnrol);
}
$totalPages_RsEnrol = ceil($totalRows_RsEnrol/$maxRows_RsEnrol)-1;
} else {$totalRows_RsEnrol=0;}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<link href="../../css/style_new.css" rel="stylesheet" type="text/css" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<br />
<table width="322" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="171"><img src="../../Images/logo.gif" width="144" height="34"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center" ><h2>Training Program</h2></td>
</tr>
</table>
<div class="containers" align=">
<div class="header">
<p align="center" class="style2">Enrolment</p>
<h5 class="../css/new_style.css" align="left">
<table align="center" width="116%" border="0" cellpadding="0" cellspacing="2" >
<tr align="center" bgcolor="#CCCCCC" >
<td width="16%">Enrolment ID</td>
<td width="50%">Course ID</td>
<td width="14%">Staff ID</td>
<td width="10%"> </td>
<td width="10%"> </td>
</tr>
<tr align="center" bgcolor="#dfdfdf" >
<td><?php echo $row_RsEnrol['erid']; ?></td>
<td align="left"> <?php echo $row_RsEnrol['courseid']; ?></td>
<td><?php echo $row_RsEnrol['staffid']; ?></td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
It is unable to filter data on Calendar.
I am really appreciated for your help.

Related

applying search or filter to table with pagination

hello kind sirs can you help me with this code. What i try to do is when i type something in the search box, ex. pending it will show the 5 pending reservation per page(5 rows of pending reservation). but when i try it, it shows all the pending reservation which is more than 10.
here is the image
i try something like this.. but it shows nothing
$query = "SELECT * FROM reservations WHERE CONCAT(firstname, lastname, reservationstatus)LIKE '%".$valueToSearch."%' LIMIT " . $this_page_first_result . ',' . $results_per_page";
Here is the whole code
<?php
error_reporting(E_ALL & ~E_NOTICE);
error_reporting(E_ERROR | E_PARSE);
session_start();
?>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "srdatabase";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$results_per_page = 5;
$select= "SELECT * FROM reservations";
$result = mysqli_query($conn, $select);
$number_of_results = mysqli_num_rows($result);
if(!isset($_GET['page']))
{
$page = 1;
}
else
{
$page = $_GET['page'];
}
$this_page_first_result = ($page-1)*$results_per_page;
$sql = "SELECT * FROM reservations LIMIT " . $this_page_first_result . ',' . $results_per_page;
$result = mysqli_query($conn, $sql);
$number_of_pages = ceil($number_of_results/$results_per_page);
?>
<div id="paging-div">
<?php
for($page=1;$page<=$number_of_pages;$page++)
{
echo '<a id="pagingLink" href="adminControl.php?page=' . $page . '">' . $page . '</a>';
}
?>
<?php
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
$query = "SELECT * FROM reservations WHERE CONCAT(firstname, lastname, reservationstatus)LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else
{
$query = "SELECT * FROM reservations";
$search_result = filterTable($query);
}
function filterTable($query)
{
$conn = mysqli_connect("localhost", "root", "", "srdatabase");
$filter_Result = mysqli_query($conn, $query);
return $filter_Result;
}
?>
</div>
<!DOCTYPE html>
<html>
<head>
<title>Admin Control</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="topnav" id="myTopnav">
Home
Speakers
About
Contact
Reservation
Sign Out
<?php echo $_SESSION['firstname']; ?>
Sign Up
Sign In
Admin control
☰
</div>
<br>
<br>
<br>
<br>
<h4 style="padding-left:10px; text-align:center;">Reservation List</h4>
<hr>
<form action="adminControl.php" method="POST">
<input type="text" name="valueToSearch" placeholder="type a value">
<input type="submit" name="search" value="Filter">
</form>
<br>
<br>
<div style="overflow-x:auto;">
<table class="reservations-table">
<tr>
<th class="thFirstName">First Name</th>
<th class="thLastName">Last Name</th>
<th class="thEmailAddress">Email Address</th>
<th class="thContactNumber">Contact Number</th>
<th class="thSpeaker">Speaker</th>
<th class="thTopic">Topic</th>
<th class="thLocation">Location</th>
<th class="thAudience">Audience</th>
<th class="thCount">Count</th>
<th class="thTime">Time</th>
<th class="thDate">Date</th>
<th class="thAction">Reservation Date</th>
<th class="thAction">Status</th>
<th class="thAction">Action</th>
<th class="thAction">Action</th>
</tr>
<?php while($row = mysqli_fetch_array($search_result)):?>
<tr>
<td><?php echo $row['firstname'];?></td>
<td><?php echo $row['lastname'];?></td>
<td><?php echo $row['emailaddress'];?></td>
<td><?php echo $row['contactnumber'];?></td>
<td><?php echo $row['speaker'];?></td>
<td><?php echo $row['topic'];?></td>
<td><?php echo $row['location'];?></td>
<td><?php echo $row['audience'];?></td>
<td><?php echo $row['count'];?></td>
<td><?php echo $row['time'];?></td>
<td><?php echo $row['date'];?></td>
<td><?php echo $row['reservationdate'];?></td>
<td><?php echo $row['reservationstatus'];?></td>
</tr>
<?php endwhile;?>
</table>
</form>
</div>
<?php
$epr='';
$msg='';
if(isset($_GET['epr']))
$epr=$_GET['epr'];
if($epr=='delete')
{
$id=$_GET['id'];
$delete=mysqli_query($conn, "DELETE FROM reservations WHERE id=$id");
if($delete)
header('location:adminControl.php');
else
$msg='Error :'.mysqli_error();
}
?>
<?php
$epr='';
$msg='';
if(isset($_GET['epr']))
$epr=$_GET['epr'];
if($epr=='approve')
{
$id=$_GET['id'];
$approve=mysqli_query($conn, "UPDATE reservations SET reservationstatus='approved' WHERE id=$id");
header('location:adminControl.php');
}
?>
<script>
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
</script>
<script>
function ifAdmin()
{
document.getElementById("signIn").style.display = "none";
document.getElementById("signUp").style.display = "none";
document.getElementById("signOut").style.display = "block";
document.getElementById("adminControl").style.display = "block";
}
</script>
<script>
function ifNotAdmin()
{
document.getElementById("signIn").style.display = "none";
document.getElementById("signUp").style.display = "none";
document.getElementById("signOut").style.display = "block";
document.getElementById("adminControl").style.display = "none";
}
</script>
<script>
function ifNotLogin()
{
document.getElementById("user").style.display = "none";
document.getElementById("signOut").style.display = "none";
document.getElementById("adminControl").style.display = "none";
}
</script>
<?php
if (isset($_SESSION['signedIn']) && $_SESSION['signedIn'] == true)
//if login
{
if($_SESSION['type'] == 1)
{
echo "<script type='text/javascript'>ifAdmin();</script>";
}
elseif($_SESSION['type'] == 0)
{
echo "<script type='text/javascript'>ifNotAdmin();</script>";
}
}
//if not login
else
{
echo "<script type='text/javascript'>ifNotLogin();</script>";
}
?>
<div id="footer" class="push">Copyright 2017</div>
</body>
</html>
... when i try it, it shows all the pending reservation which is more than 10.
That's because when you hit 2nd, 3rd, ... pages(after navigating from the 1st page), the $_POST array would be empty i.e. $_POST['search'] won't be set, and that's why else{...} part of the code will get executed every time you navigate to 2nd, 3rd, ... pages. Since you're not sending any sensitive data with the form, use GET instead of POST in the method attribute of the form, like this:
<form action="..." method="get">
and get the user inputted data like this:
if (isset($_GET['search'])) {
$valueToSearch = $_GET['valueToSearch'];
...
Subsequently, you need to attach that search query in each of your pagination links, so that the search query would be available when you hop from page to page.
// your code
<?php
for($page=1;$page<=$number_of_pages;$page++)
{
echo "<a id='pagingLink' href='adminControl.php?page=" . $page . "&valueToSearch=". urlencode($_GET['valueToSearch']) ."&search'>" . $page . "</a>";
}
?>
// your code

How to delete a row of table on click of a button and respective data from database?

I have a table which contains chapters and a button in front of each chapter.
Now I want to delete a row when the delete button is clicked and also I want to fire a delete query to delete the row from database.
I tried 2 3 ways to delete a row from table, but its not getting delete.
<!doctype html>
<html>
<head>
<title>Chapters</title>
</head>
<body>
<style>
td {
text-align: left;
}
</style>
<script>
var par = $(this).parent().parent(); //tr
par.remove();
</script>
<table id="example" style="width:50%">
<tr>
<th><font size="5">Chapters</font></th>
</tr>
<?php
$dbh = new PDO('mysql:host=174.13.54;dbname=handbook', 'airman', 'airman');
$stmt = $dbh->prepare("SELECT * FROM chapters");
$stmt->execute();
$results = $stmt->fetchall(PDO::FETCH_ASSOC);
if(count($results) > 0)
{
foreach($results as $chapter)
{
if($chapter['type'] == 1)
{
$type = "SSgt";
}
elseif($chapter['type'] == 2)
{
$type = "TSgt";
}
elseif($chapter['type'] == 3)
{
$type = "MSgt";
}
?>
<tr>
<td><?php $chapter['id']; echo $chapter['title'];echo " " . "(" .$type.")";?></td>
<td><input type="button" value="Delete"></td>
</tr>
<?Php
}
?>
</table>
</body>
</html>
<?php
}
?>
How can I do this? Can anyone help please?
EDIT :
chapterDelete.php
<!doctype html>
<html>
<head>
<title>Chapters</title>
</head>
<form method="post" action="deleteChapter.php" enctype="multipart/form-data">
<body>
<style>
td {
text-align: left;
}
</style>
<table id="example" style="width:50%">
<tr>
<th><font size="5">Chapters</font></th>
</tr>
<?php
$dbh = new PDO('mysql:host="138.75.54;dbname=handbook', 'airman', 'airman12345');
$stmt = $dbh->prepare("SELECT * FROM chapters");
$stmt->execute();
$results = $stmt->fetchall(PDO::FETCH_ASSOC);
if(count($results) > 0)
{
foreach($results as $chapter)
{
if($chapter['type'] == 1)
{
$type = "SSgt";
}
elseif($chapter['type'] == 2)
{
$type = "TSgt";
}
elseif($chapter['type'] == 3)
{
$type = "MSgt";
}
?>
<tr>
<td><?php echo $chapter['title'];echo " " . "(" .$type.")";?></td>
<td><input type="button" class="removeRowButton" id = "<?php $chapter['id']?>" value="Delete"></td>
</tr>
<?Php
}
?>
</table>
</body>
</form>
</html>
<script
$('.removeRowButton').click(function(){
var rowID= $(this).attr('id');
$.get( "deleteChapter.php?rowID=" + rowID, function( error ) {
if(error == 0){
$('tr#' + rowID).remove();
}
else{
alert('MySQL error!');
}
});
});
</script>
<?php
}
?>
deleteChapter.php
<?php
ini_set('display_errors', 1);
error_reporting(1);
ini_set('error_reporting', E_ALL);
$dbh = new PDO('mysql:host=138.75.54;dbname=handbook', 'airman', 'airman12345');
$stmt = $dbh->prepare("DELETE FROM `chapters` WHERE `rowID`= '" . $_GET["rowID"]);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if(count($result) > 0)
{
echo 'row deleted';
}
else{
echo 'row could not delete';
}
?>
Nothing is happening on click of delete button.
EDIT 2 :
<!doctype html>
<html>
<head>
<title>Chapters</title>
</head>
<form method="post" action="chapterDelete.php" enctype="multipart/form-data">
<body>
<style>
td {
text-align: left;
}
</style>
<table id="example" style="width:50%">
<tr>
<th><font size="5">Chapters</font></th>
</tr>
<?php
ini_set('display_errors', 1);
error_reporting(1);
ini_set('error_reporting', E_ALL);
$dbh = new PDO('mysql:host=1775.54;dbname=handbook', 'airman', 'airman');
$stmt = $dbh->prepare("SELECT * FROM chapters");
$stmt->execute();
$results = $stmt->fetchall(PDO::FETCH_ASSOC);
if(count($results) > 0)
{
foreach($results as $chapter)
{
if($chapter['type'] == 1)
{
$type = "SSgt";
}
elseif($chapter['type'] == 2)
{
$type = "TSgt";
}
elseif($chapter['type'] == 3)
{
$type = "MSgt";
}
?>
<tr>
<td><?php echo $chapter['title'];echo " " . "(" .$type.")";?></td>
<td><input type="button" onClick= "this.form.submit()" value="Delete<?php $chapter['id']?>"</input></td>
</tr>
<?Php
}
?>
</table>
</body>
</form>
</html>
<?php
}
function delete($id)
{
$dbh = new PDO('mysql:host=174.138.75.54;dbname=airman_handbook', 'airman', 'airman12345');
$stmt = $dbh->prepare("DELETE FROM `chapters` WHERE `id`= " . $id);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if(count($result) > 0)
{
echo 'row deleted';
}
else{
echo 'row could not delete';
}
}
?>
Can I do like this without using ajax? But it is not working .
You'll need to make an asynchronous (AJAX) call to a .php script that deletes the row from your MySQL table.
First, your table rows should have an ID set with a unique row number, and this number should also be an attribute of the button that is supposed to remove the row (so that we know which row to remove when we press the remove button):
<table>
<tr id="number">
<td>Data</td>
<td><button class="removeRowButton" id="number" value="Delete this row"></td>
</tr>
</table>
That way, you can interact with each row separately.
Your PHP file (e.g. "removerow.php") should look something like this:
// Connect to MySQL database
$error= 0;
$deleteRow= mysql_query("DELETE FROM `tablename` WHERE `rowID`= '" . $_GET["rowID"] . "';") or $error= 1;
echo($error);
And when you get a SUCCESS back, you'll remove the row from the visible HTML table using jQuery:
$('.removeRowButton').click(function(){
var rowID= $(this).attr('id');
$.get( "removerow.php?rowID=" + rowID, function( error ) {
if(error == 0){
$('tr#' + rowID).remove();
}
else{
alert('MySQL error!');
}
});
});

Unable to insert data into MySQL event database

I am trying to create a PHP/MySQL event calendar. However it doesn't go quite right. Below is my code:
// calender.php
$servername = "localhost";
$username = "username";
$password = "";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
#mysqli_select_db("calen");
if (!#mysqli_select_db) {
die("database connection failed".mysqli_connect_error());
}
/*
mysqli_connect($hostname,$username,$password) or die ($error);
mysqli_select_db($dbname) or die ($error);
*/
?>
<html>
<head>
<script>
function lastmonth(month,year) {
if (month == 1) {
--year;
month = 13;
}
--month
var monthstring= ""+month+"";
var monthlength = monthstring.length;
if (monthlength <=1) {
monthstring = "0" + monthstring;
}
document.location.href = "<?= $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
}
function nextmonth(month,year) {
if(month == 12) {
++year;
month = 0;
}
++month
var monthstring= ""+month+"";
var monthlength = monthstring.length;
if (monthlength <=1) {
monthstring = "0" + monthstring;
}
document.location.href = "<?=$_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
}
</script>
</head>
<body>
<?php
if (isset($_GET['day'])) { //to pass variable
$day = $_GET['day'];
} else {
$day = date("j");
}
if (isset($_GET['month'])) {
$month=$_GET['month'];
} else {
$month = date("n");
}
if (isset($_GET['year'])) {
$year=$_GET['year'];
} else {
$year = date("y");
}
$currentTimeStamp = strtotime("$year-$month-$day");
$monthname = date("F", $currentTimeStamp);
$numofdays = date("t", $currentTimeStamp);
$counter = 0;
?>
<?php
if (isset($_GET['add'])) {
$title =$_POST['txttitle'];
$detail =$_POST['txtdetail'];
$eventdate = $month."/".$day."/".$year;
$insert = "INSERT into calendar(Title,Detail,EventDate,DateAdded) values ('".$title."','".$detail."','".$eventdate."',now())";
$check = mysqli_query($conn,$insert);
if ($check ) {
echo "Event Added...";
} else {
echo "Failed....";
}
}
?>
<table border='1'>
<tr>
<td><input style='width:50px;' type='button' value='<' name='previous' onclick="lastmonth(<?php echo $month.",".$year ?>)"> </td>
<td colspan='5' align='center'> <?php echo $monthname.",".$year ?> </td>
<td><input style='width:50px;' type='button' value='>' name='next' onclick="nextmonth(<?php echo $month.",".$year ?>)"></td>
</tr>
<tr>
<td width='50px' align='center'>Sun</td>
<td width='50px'align='center'>Mon</td>
<td width='50px'align='center'>Tue</td>
<td width='50px'align='center'>Wed</td>
<td width='50px'align='center'>Thu</td>
<td width='50px'align='center'>Fri</td>
<td width='50px'align='center'>Sat</td>
</tr>
<?php
echo "<tr>";
for ($i=1;$i<$numofdays+1;$i++,$counter++) {
$TimeStamp = strtotime("$year-$month-$i");
if ($i == 1) {
$firstday = date("w", $TimeStamp); //which day 1 falls on
for ($j = 0; $j < $firstday; $j++, $counter++) {
echo "<td> </td>";
}
}
if ($counter % 7 == 0) {
echo "</tr><tr>";
}
$monthstring=$month;
$monthlength=strlen($monthstring);
$daystring=$i;
$daylength=strlen($daystring);
if ($monthlength<=1) {
$monthstring = "0".$monthstring;
}
if ($daylength<=1) {
$daystring="0".$daystring;
}
echo "<td align='center'> <a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$daystring."&year=".$year."&v=true'>".$i."</a> </td>";
}
echo "</tr>";
?>
</table>
<?php
if (isset($_GET['v'])) {
echo "<a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$daystring."&year=".$year."&v=true&f=true'>Add Event </a>";
if (isset($_GET['f'])) {
include("event.php");
}
}
?>
</body>
</html>
event.php
<form name='event' method='POST' action="<?php $_SERVER['PHP_SELF']; ?>?month=<?php echo $month;?>&day=<?php echo $day;?>&year=<?php echo $year; ?>&v=true&add=true">
<table width='400px' border='0'>
<tr>
<td width='150px'>Title</td>
<td width='250px'><input type='text' name='txttitle'</td>
</tr>
<tr>
<td width='150px'>Detail</td>
<td width='250px'><textarea name='txtdetail'></textarea></td>
</tr>
<tr>
<td colspan='2' align='center'><input type='submit' name='btnadd' value='Add Event'></td>
</tr>
</table>
</form>
SQL:
CREATE TABLE `calendar` (
`ID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`Title` VARCHAR( 65 ) NOT NULL ,
`Detail` VARCHAR( 255 ) NOT NULL ,
`EventDate` VARCHAR( 10 ) NOT NULL ,
`DateAdded` DATE NOT NULL
);
I am unable to insert data into the database. I have pasted my calendar.php, event.php and SQL code. Kindly please check the code and help me out in inserting the data.
You need to add the connection variable with the mysqli_select_db(). So your code will be:
<?php
$servername = "localhost";
$username = "username";
$password = "";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
//#mysqli_select_db($conn, "calen");
if(!mysqli_select_db($conn, "calen")) {
die ("database connection failed".mysqli_connect_error());
}
/*
mysqli_connect($hostname,$username,$password) or die ($error);
mysqli_select_db($dbname) or die ($error);
*/
?>
<html>
<head>
<script>
function lastmonth(month,year)
{
if(month == 1)
{
--year;
month = 13;
}
--month
var monthstring= ""+month+"";
var monthlength = monthstring.length;
if(monthlength <=1)
{
monthstring = "0" + monthstring;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
}
function nextmonth(month,year)
{
if (month == 12) {
++year;
month = 0;
}
++month
var monthstring= ""+month+"";
var monthlength = monthstring.length;
if (monthlength <=1) {
monthstring = "0" + monthstring;
}
document.location.href ="<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
}
</script>
</head>
<body>
<?php
if (isset($_GET['day'])) { //to pass variable
$day=$_GET['day'];
} else {
$day = date("j");
}
if (isset($_GET['month'])) {
$month=$_GET['month'];
} else {
$month = date("n");
if (isset($_GET['year'])) {
$year=$_GET['year'];
} else {
$year = date("y");
}
$currentTimeStamp = strtotime("$year-$month-$day");
$monthname = date("F", $currentTimeStamp);
$numofdays = date("t", $currentTimeStamp);
$counter = 0;
?>
<?php
if (isset($_GET['add'])) {
$title =$_POST['txttitle'];
$detail =$_POST['txtdetail'];
$eventdate = $month."/".$day."/".$year;
$insert = "INSERT INTO calendar (Title,Detail,EventDate,DateAdded) VALUES ('".$title."','".$detail."','".$eventdate."', NOW())";
$check = mysqli_query($conn,$insert);
if ($check) {
echo "Event Added...";
} else {
echo "Failed....";
}
}
?>
<table border='1'>
<tr>
<td> <input style='width:50px;' type='button' value='<' name='previous' onclick="lastmonth(<?php echo $month.",".$year ?>)"> </td>
<td colspan='5' align='center'> <?php echo $monthname.",".$year ?> </td>
<td><input style='width:50px;' type='button' value='>' name='next' onclick="nextmonth(<?php echo $month.",".$year ?>)"></td>
</tr>
<tr>
<td width='50px' align='center'>Sun</td>
<td width='50px'align='center'>Mon</td>
<td width='50px'align='center'>Tue</td>
<td width='50px'align='center'>Wed</td>
<td width='50px'align='center'>Thu</td>
<td width='50px'align='center'>Fri</td>
<td width='50px'align='center'>Sat</td>
</tr>
<?php
echo "<tr>";
for ($i=1;$i<$numofdays+1;$i++,$counter++) {
$TimeStamp = strtotime("$year-$month-$i");
if ($i == 1) {
$firstday = date("w", $TimeStamp); //which day 1 falls on
for ($j = 0; $j < $firstday; $j++, $counter++) {
echo "<td> </td>";
}
}
if($counter % 7 == 0) {
echo "</tr><tr>";
}
$monthstring=$month;
$monthlength=strlen($monthstring);
$daystring=$i;
$daylength=strlen($daystring);
if ($monthlength<=1) {
$monthstring = "0".$monthstring;
}
if ($daylength<=1) {
$daystring="0".$daystring;
}
echo "<td align='center'> <a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$daystring."&year=".$year."&v=true'>".$i."</a> </td>";
}
echo "</tr>";
?>
</table>
<?php if (isset($_GET['v'])) {
echo "<a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$daystring."&year=".$year."&v=true&f=true'>Add Event </a>";
if (isset($_GET['f'])) {
include("event.php");
}
}
?>
</body>
</html>
Hope this works for you!
More information at http://www.w3schools.com/php/func_mysqli_select_db.asp

Not getting second Fetch

Hey everyone I have been trying to figure this out for a while and just cant get around while its not showing the second fetch where weaponF is,
<?php
session_start();
if(!$_SESSION['logged']){
header("Location: login_page.php");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<style type="text/css">
div {
position: relative;
left: 5px;
top: 25px;
width: 280px;
padding: 10px;
color: black;
display: none;
}
</style>
<script language="JavaScript">
function setVisibility(id1,id2,id3) {
if(document.getElementById('bt1').value=='H'){
document.getElementById('bt1').value = 'S';
document.getElementById(id1).style.display = 'none';
document.getElementById(id2).style.display = 'none';
document.getElementById(id3).style.display = 'none';
}else{
document.getElementById('bt1').value = 'H';
document.getElementById(id1).style.display = 'inline';
document.getElementById(id2).style.display = 'inline';
document.getElementById(id3).style.display = 'inline';
}
}
function setvisibility(id4){
if(document.getElementById('bt2').value=='HP'){
document.getElementById('bt2').value = 'SP';
document.getElementById('id4').style.display = 'none';
}else{
document.getElementById('bt2').value = 'HP';
document.getElementById('id4').style.display = 'inline';
}
}
function setvisibility(id5){
if(document.getElementById('bt3').value=='HC'){
document.getElementById('bt3').value = 'SC';
document.getElementById('id5').style.display = 'none';
}else{
document.getElementById('bt3').value = 'HC';
document.getElementById('id5').style.display = 'inline';
}
}
function setvisibility(id6){
if(document.getElementById('bt4').value=='HM'){
document.getElementById('bt4').value = 'SM';
document.getElementById('id6').style.display = 'none';
}else{
document.getElementById('bt4').value = 'HM';
document.getElementById('id6').style.display = 'inline';
}
}
function setvisibility(id7){
if(document.getElementById('bt5').value=='HI'){
document.getElementById('bt5').value = 'SI';
document.getElementById('id7').style.display = 'none';
}else{
document.getElementById('bt5').value = 'HI';
document.getElementById('id7').style.display = 'inline';
}
}
</script>
<body>
<center>
<?php
$con=mysqli_connect(secret);
$validUser = mysqli_real_escape_string($con, $_SESSION['username']);
$result = mysqli_query($con, "SELECT level, exp, maxexp, str, dex, inte, sta, crit, hp, atk, def, dfire, dwater, dposion, atkfire, atkwater, atkposion, weapon FROM users WHERE username = '$validUser'");
$data = mysqli_fetch_array($result,MYSQLI_ASSOC);
$weapon = $data['weapon'];
$weaponQ = mysqli_query($con, "SELECT * FROM equipment WHERE wname= '$weapon'") or die(mysqli_error($con));
$weaponF = mysqli_fetch_array($weaponQ,MYSQLI_ASSOC);
mysqli_close($con);
?>
<body><center>
<table border="1">
<td>Level:<?php echo $data['level']; ?></td>
<td
<?php if ($data['exp'] == $data['maxexp']) {
echo "bgcolor = white";
}
else
{
echo "bgcolor = white";
}
?>
>Exp:<?php echo $data['exp']; ?>/<?php echo $data['maxexp']; ?></td>
<td>Str:<?php echo $data['str']; ?></td>
<td>Dex:<?php echo $data['dex']; ?></td>
<td>Int:<?php echo $data['inte']; ?></td>
<td>Stam:<?php echo $data['sta']; ?></td>
<td>Crit:<?php echo $data['crit']; ?>%</td>
</table>
<?php
if ($data['exp'] == $data['maxexp']) {
echo "<a href='levelup.php'>Level up </a>";
}
else
{
echo "";
}
?>
</center>
<table border="1" align="left">
<tr>
<td>
<a onclick="setVisibility('sub3','sub4','sub5');" id="bt1" href="#">Explore</a><br /><br />
<a onclick="setVisibility('sub6');" id="bt4" href="#">Market</a><br /><br />
<a onclick="setVisibility('sub1');" id="bt2" href="#">Profile</a><br /><br />
<a onclick="setVisibility('sub2');" id="bt3" href="#">Casino</a><br /><br />
<a onclick="setVisibility('sub7');" id="bt5" href="#">Inventory</a><br /><br />
Logout
</td>
</tr>
</table>
<br />
<div id="sub3" align="center">Map</div>
<br><br><br><br><br>
<div id="sub4" align="center">Arrows</div>
<div id="sub5" align="center">Mobs</div>
<div id="sub1" align="center">
<table border="1" align="center">
<td>
<?php
echo "<font size='+2'>Base Stats</font>";
echo "<br><br>";
echo "Str: ";
echo $data['str'];
echo "<br>";
echo "Dex: ";
echo $data['dex'];
echo "<br>";
echo "Int: ";
echo $data['inte'];
echo "<br>";
echo "Stam: ";
echo $data['sta'];
echo "<br>";
echo "Crit: ";
echo $data['crit'];
echo "%";
echo "<br>";
echo "Atk: ";
echo $data['atk'];
echo "<br>";
echo "Def: ";
echo $data['def'];
echo "<br><br>";
echo "<font size='+2'>Bonus Atk</font>";
echo "<br><br>";
echo "Atk Fire: ";
echo $data['atkfire'];
echo "%";
echo "<br>";
echo "Atk Water: ";
echo $data['atkwater'];
echo "%";
echo "<br>";
echo "Atk Posion: ";
echo $data['atkposion'];
echo "%";
echo "<br><br>";
echo "<font size='+2'>Bonus Res</font>";
echo "<br><br>";
echo "Def Fire: ";
echo $data['dfire'];
echo "%";
echo "<br>";
echo "Def Water: ";
echo $data['dwater'];
echo "%";
echo "<br>";
echo "Def Posion: ";
echo $data['dposion'];
echo "%";
?>
</td>
</table>
</div>
<div id="sub2" align="center">Casino</div>
<div id="sub6" align="center">Market</div>
<div id="sub7" align="center">
<table border="1" bordercolor="white">
<tr>
<td bordercolor="white" height="50px" width="50px"></td>
<td width="50px" height="50px" bordercolor="black">
Head
</td>
</tr><br />
<tr>
<td width="50px" height="50px" bordercolor="black">
<img onmouseover="<?php echo $weaponF['name']; ?>" src="equipment/<?php echo $data['weapon']; ?>.png" />
</td>
<td width="50px" height="50px" bordercolor="black">
Chest
</td>
<td width="50px" height="50px" bordercolor="black">
RightArm
</td>
</tr>
<tr>
<td bordercolor="white" height="50px" width="50px">
</td>
<td bordercolor="black" height="50px" width="50px">
Pants
</td>
</tr>
<tr>
<td bordercolor="white" height="50px" width="50px">
</td>
<td bordercolor="black" height="50px" width="50px">
Shoes
</td>
</tr>
</table>
</div>
<?php echo $data['weapon'];
echo $weaponF['wname']; ?>
</body>
It dose not show any errors or faults, Please help haha here is all my code make it easier to view and help I hope lol
i think username and name is your table columns so try
$validUser = mysqli_real_escape_string($con, $_SESSION['username']);
mysqli_query("SELECT * FROM users WHERE username ='$validUser' LIMIT 1");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT level, exp, maxexp, str, dex, inte, sta, crit, hp, atk, def, dfire, dwater, dposion, atkfire, atkwater, atkposion, weapon FROM users WHERE username = '$validUser'");
$data = mysqli_fetch_array($result,MYSQLI_ASSOC);
$weapon = $data['weapon'];
$weaponQ = mysqli_query($con, "SELECT * FROM equipment WHERE wname= '$weapon'") or die(mysqli_error($con));
if(mysqli_num_rows($weaponQ) > 0) {
$weaponF = mysqli_fetch_array($weaponQ,MYSQLI_ASSOC);
}
else {
echo 'No rows found';
}
mysqli_close($con);
and also there is no work of below query so you can remove this:-
mysqli_query("SELECT * FROM users WHERE username ='$validUser' LIMIT 1");

fail to manage checkbox using Pagination php using cookies

I want to manage pagination by using cookies.
I need to get values from selected checkboxe's and pass that values through pagination witch is done by php/mysql. And if on another page user select other checkboxes add their values to array of earlier seleced. For that i wrote one code but it did not work..What wrong with my code????
Following file is the manual.php file.
<script type="text/javascript" src="paginate.js"> </script>
<tr>
<td><strong>Select</strong></td>
<td width="59"><strong>Sr No.</strong></td>
<td width="300"><strong>Question </strong></td>
<td width="30"><strong>CorrectAnswer </strong></td>
<td width="50"><strong>Catagory </strong></td>
<td><strong>View Details</strong></td>
</tr>
<?php
include("config.php");
$start = 0;
$per_page = 10;
//$tablename = "testlist";
$targetpage = "manual.php?id=42";
if(!isset($_GET['page'])){
$page = 1;
} else{
$page = $_GET['page'];
}
if($page<=1)
$start = 0;
else
$start = $page * $per_page - $per_page;
$sql="select * from math order by id";
$num_rows = mysql_num_rows(mysql_query($sql));
$num_pages = $num_rows / $per_page;
$sql .= " LIMIT $start, $per_page";
$result=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result))
{ ?>
<tr>
<td><input name="<?php echo $row['id'];?>" type="checkbox" class="remember_cb"></td>
<td><center><?php echo htmlspecialchars_decode($row['id'], ENT_QUOTES); ?></center>
</td>
<td style="padding-left:25px;margin:15px"><?php echo $_SESSION['question']=
htmlspecialchars_decode($row['question'], ENT_QUOTES); ?></center>
</td>
<td><center><?php echo htmlspecialchars_decode($row['correctAnswer'], ENT_QUOTES); ?>
</center></td>
<td><center><?php echo htmlspecialchars_decode($row['category'], ENT_QUOTES); ?>
</center></td>
<td><a href="<?php echo "manual_update.php?id=".$row['id']."&mode=update";?
>"id="dialog_10">View</a></td>
</tr>
<?php } ?>
<tr>
<td><strong>Select </strong></td>
<td><strong>Sr No </strong></td>
<td><strong>Question </strong></td>
<td><strong>CorrectAnswer </strong></td>
<td><strong>Category </strong></td>
<td><strong>View Details</strong></td>
</tr>
<?php
if($page > 1){
$prev = $page - 1;
$prev = " <a href='$targetpage&page=$prev'>prev</a> ";
} else {
$prev = "";
}
if($page < $num_pages){
$next = $page + 1;
$next = " <a href='$targetpage&page=$next'>next</a> ";
}
else
{
$next = "";
}
echo $prev;
echo $next;
?>
paginate.js
var aa_checkbox;
function init_checkbox(){
//setup blank cb cookie
if(!Cookie.read('checkbox'))
{
Cookie.write('checkbox', JSON.encode({}));
}
//setup "associative array" to match what is currently in the cookie
aa_checkbox = JSON.decode(Cookie.read('checkbox'));
//set up each checkbox with class="remember_cb"
$$('input.remember_cb').each(function(el){
//mark checked if it is in the cookie
if(aa_checkbox[el.name]){
el.checked = 'checked'
}
//setup onclick event to put checkbox status in the
if(el.checked){
aa_checkbox[el.name] = 1;
}else{
delete(aa_checkbox[el.name]);
}
})
})
//save aa_checkbox back into cookie upon leaving a page
window.onbeforeunload = function(){Cookie.write('cb',
JSON.encode(aa_checkbox));};
setup_form();
return true;
}
function setup_form(){
//set up form so that it adds the inputs upon submit.
$$('form.remember_cb_form').each(function(form){
form.addEvent('submit', function(ev){
//clean up previously inserted inputs
var aa_hidden_insert = $$('input.hidden_insert');
$each(aa_hidden_insert, function(el){
el.parentNode.removeChild(el);
})
var el_form = this;
//insert hidden elements representing the values stored in aa_checkbox
$each(aa_checkbox, function(i_value, s_name){
if(i_value){
var el_input = document.createElement('input');
el_input.type = 'hidden';
el_input.value = i_value;
el_input.name = s_name;
el_input.setAttribute('class', 'hidden_insert');
el_form.appendChild(el_input);
}
});
});
});
}
window.addEvent('domready', init_checkbox);
function selectall()
{
var selectAll = document.forms[0].length;
if(document.forms[0].topcheckbox.checked == true)
{
for(i=1;i<selectAll;i++)
{
document.forms[0].elements[i].checked = true;
}
}
else
{
for(i=1;i<selectAll;i++)
document.forms[0].elements[i].checked = false;
}
}
function goSelect()
{
var select = document.forms[0].length;
var checkboxes=""
for(i=1;i<select;i++)
{
if(document.forms[0].elements[i].checked==true)
checkboxes+= " " + document.forms[0].elements[i].name
}
if(checkboxes.length>0)
{
var con=confirm("You have selected ...........");
if(con)
{
window.location.assign("submit.php?recsno="+checkboxes)
}
}
else
{
alert("No record is selected.")
}
}

Categories