Assalamu'alaikum, i am use this scripts for calculate the value of checkbox named "Biaya" and it is works.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<?php
mysql_connect("localhost", "root")or die("cannot connect");
mysql_select_db("spp")or die("cannot select DB");
$sql="SELECT `idtagihan`, `namatagihan`,`biaya` from tagihan";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table border=1>
<tr>
<td>
<form name="form1" method="post">
<table>
<tr>
<td>Id</td>
<td>Nama</td>
<td>Harga</td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['idtagihan']; ?>></td>
<td><?php echo $rows['namatagihan']; ?></td>
<td>Rp. <?php echo $rows['biaya']; ?>,-</td>
<td><input type="checkbox" name=check[] value="<?php echo $rows['namatagihan']; ?>" data-weight="<?php echo $rows['biaya']; ?>"></td>
</tr>
<?php
}
?>
<tr>
<td colspan=3><input name="Next" type="submit" id="Next" value="Next"></td>
</tr>
<?php
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
<div>Total: <span id="total">0</span></div>
</body>
</html>
<script type="text/javascript">
(function () {
var totalEl = document.getElementById('total'),
total = 0,
checkboxes = document.form1['check[]'],
handleClick = function () {
total += parseInt(this.getAttribute('data-weight'), 10) * (this.checked ? 1 : -1);
totalEl.innerHTML = total;
},
i, l
;
for (i = 0, l = checkboxes.length; i < l; ++i) {
checkboxes[i].onclick = handleClick;
}
}());
</script>
The result is like this :
First result pic
Then i develop that code for updating it's value to database but it cannot calculate anymore. Here is the whole php code :
<?php
// Start session
session_start();
require_once('includes/functions.inc.php');
// Check login status... if not logged in, redirect to login screen
if (check_login_status() == false) {
redirect('login.php');
}
// Connection to the database
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="spp"; // Database name
$tbl_name="tagihan"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
if(isset($_POST['check'])){$checkbox = $_POST['check'];
if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"])
$id = "('" . implode( "','", $checkbox ) . "');" ;
$sql2="UPDATE tagihan SET status = '".(isset($activate)?'Lunas':'Belum Lunas')."' WHERE idtagihan IN $id" ;
$result = mysql_query($sql2) or die(mysql_error());
}
$nim = $_SESSION['nim'];
$sql="SELECT `idtagihan`, `namatagihan`, `biaya` FROM tagihan WHERE nim='".$nim."' and status='Belum lunas' ";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html;charset=utf-8" />
<title>Pembayaran SPP</title>
<link rel="stylesheet" type="text/css" href="css/gaya.css" />
<link href="css/menu.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="halaman">
<h1>Pembayaran SPP</h1>
<p>Keluar
<?php
$nim = $_SESSION['nim'];
?>
<label>Nim anda : </label> <input type="total" name="nim" id="nim" readOnly="readonly" value="<?php echo $nim; ?>" >
</p>
</br>
<div class="tabel" >
<form name="frmactive" method="post" action="">
<table>
<tr>
<td>Id</td>
<td>Nama</td>
<td>Harga</td>
<td>Pilih</td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['idtagihan']; ?></td>
<td><?php echo $rows['namatagihan']; ?></td>
<td>Rp. <?php echo $rows['biaya']; ?>,-</td>
<td><input class="css-checkbox" type="checkbox" name='check[]' name='cek[]' value="<?php echo $rows['idtagihan']; ?>" biaya = "<?php echo $rows['biaya']; ?>"></td>
</tr>
<?php
}
?> </table>
<div class="tabelspp" >
<table>
<tr>
<td><label>Total Rp.</label><input type="total" id="total2" readOnly="readonly"></input><label>,-</label>
<input type="submit" name="activate" id="activate" value="Bayar" /> </td>
</tr>
</table> </form> </div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<script type="text/javascript">
(function () {
var totalEl = document.getElementById('total2'),
total2 = 0,
checkboxes = document.form1['check[]'],
handleClick = function () {
total2 += parseInt(this.getAttribute('biaya'), 10) * (this.checked ? 1 : -1);
totalEl.value = total2;
},
i, l
;
for (i = 0, l = checkboxes.length; i < l; ++i) {
checkboxes[i].onclick = handleClick;
}
}());
</script>
Then here is the result :
Second result pic
I can update the database successfully. But my question is how to make that second script can calculate the value's checkbox again same as first script? I need to resolve this, i hope there someone who can answer this. I am happy if there anyone reply my post. Thank you.
for first, try to change the name of the form
from
<form name="frmactive" method="post" action="">
to this
<form method="post" action="" name="form1">
Related
I have tried to insert html table multiple row data to database but not success without error.
Please refer below for my code and kindly advice what do I missed.
Retrieve data for dropdown selection
<?php
//including the database connection file
include_once("config_db.php");
$gettminfo=mysql_query("SELECT * FROM tb_tm ORDER BY tm_abb");
?>
Html Code for the table
<!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" />
<link rel="stylesheet" type="text/css" href="css/spa_invoice.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<!--Add & delete rows from table dynamically-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(function(){
$('#addRow').click(function(){
var html = $('#row_template').html();
$('#dataTable').append(html);
$(".tablerow").each(function(index) {
$(this).html(index + 1);
});
});
$('#deleteRow').click(function(){
$('#dataTable .mychkbox:checked').parents('tr').remove();
calc_ttl();
});
$('#dataTable').on('change','.select-desc',function(){
var cur_val = $(this).val();
$(this).parents('tr').find('input[name="order_unit_prc[]"]').val(cur_val);
});
$('#dataTable').on('keyup','input[name="order_qty[]"]', function(){
var qty = +$(this).val();
var unit = +$(this).parents('tr').find('input[name="order_unit_prc[]"]').val();
$(this).parents('tr').find('input[name="order_amt[]"]').val(qty*unit);
calc_ttl();
});
});
</script>
<form action="" method="post" name="form_spa_inv">
<fieldset class="row3">
<table>
<tr>
<td><input type="button" value="Add Treatment" id="addRow" /></td>
<td><input type="button" value="Remove Treatment" id="deleteRow" /></td>
</tr>
</table>
<table id="dataTable" class="form" border="1">
<tr>
<td></td>
<td>No</td>
<td>Description</td>
<td>Qty</td>
<td>Unit Price</td>
<td>Amount</td>
</tr>
</table>
<!-- table row template here -->
<table id="row_template" style="display:none">
<tr>
<td><input type="checkbox" name="chk[]" class="mychkbox" /></td>
<td class="tablerow"></td>
<td>
<select name="order_desc[]" id="order_desc" class="select-desc">
<option value="">-- Select Treatment --</option>
<?php
while($dd=mysql_fetch_array($gettminfo)) {
?>
<option value="<?php echo $dd['tm_unit_prc']?>"><?php echo $dd['tm_abb'] ?> - <?php echo $dd['tm_desc'] ?></option>
<?php
}
?>
</select>
</td>
<td>
<input type="text" name="order_qty[]" id="order_qty" size="10">
</td>
<td>
<input type="text" name="order_unit_prc[]" id="order_unit_prc" readonly>
</td>
<td>
<input type="text" name="order_amt[]" id="order_amt" readonly>
</td>
</tr>
</table>
</fieldset>
<p style="text-align: center;"><input type="submit" name="Submit" value="Create">
</form>
</body>
</html>
Insert mysql query
<?php
//including the database connection file
include_once("config_db.php");
if(isset($_POST['Submit']))
{
for($i=0; $i < count($_POST['order_desc']); $i++) {
$order_desc = addslashes($_POST['order_desc'][$i]);
$order_qty = addslashes($_POST['order_qty'][$i]);
$order_unit_prc = addslashes($_POST['order_unit_prc'][$i]);
$order_amt = addslashes($_POST['order_amt'][$i]);
//insert data to database tb_odr_dtl
$insert_odrdtl=mysql_query("INSERT INTO tb_odr_dtl(order_desc,order_qty,order_unit_prc,order_amt) VALUES('$order_desc','$order_qty','$order_unit_prc','$order_amt')");
mysql_query($insert_odrdtl);
//display success message
if($insert_odrdtl) {
echo "<script>alert('Invoice created successfully!')</script>";
echo "<script>window.open('cv.php','_self')</script>";
}
}
}
?>
Change server site code to following:
<?php
//including the database connection file
include_once("config_db.php");
if(isset($_POST['Submit']))
{
for($i=0; $i < count($_POST['order_desc']); $i++) {
$order_desc = addslashes($_POST['order_desc'][$i]);
$order_qty = addslashes($_POST['order_qty'][$i]);
$order_unit_prc = addslashes($_POST['order_unit_prc'][$i]);
$order_amt = addslashes($_POST['order_amt'][$i]);
//insert data to database tb_odr_dtl
$insert_odrdtl=mysql_query("INSERT INTO tb_odr_dtl(order_desc,order_qty,order_unit_prc,order_amt) VALUES('$order_desc','$order_qty','$order_unit_prc','$order_amt')");
//mysql_query($insert_odrdtl); //delete this line of code
//display success message
if($insert_odrdtl) {
echo "<script>alert('Invoice created successfully!')</script>";
echo "<script>window.open('cv.php','_self')</script>";
}
}
}
?>
I'm struggling now for a few days to get the value of a checkbox in my code.
Basically I have an admin-page where the customer can select and deselect images that will put online.
You can select and deselect images that will be shown on the homepage, and separate on the gallery-page. Both checked is also possible.
I have another checkbox that can be selected to remove the image from the list(image_deleted).
There is still a database entry and the images are still on file-system but later on I'll create a cleanup-job.
Here is my code:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
ob_start();
require('../../lib/dbconnection.php');
require("../../lib/checklogin.php");
require("includes/upload.inc.php");
$query = 'SELECT * FROM gallery where image_deleted != 1 order by id desc';
$result=$conn->query($query);
$count=$result->num_rows;
?>
<!DOCTYPE html>
<html>
<head>
<title>Classic Nails - CMS</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="ClassicNails">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../css/screen.css">
<link rel="stylesheet" href="../css/libs/magnific-popup.css">
<script src="../js/libs/min/jquery-min.js" type="text/javascript"></script>
<script src="../js/min/custom-min.js" type="text/javascript"></script>
<script src="js/jquery.magnific-popup.js"></script>
<script>
$(document).ready(function() {
$('.image-link').magnificPopup({
type:'image',
gallery:{
enabled:true
}
});
});
</script>
</head>
<body>
<?php include('includes/header.inc.php'); ?>
<?php include('includes/nav.inc.php'); ?>
<div class="wrapper">
<article class="content">
<h1>Foto gallery</h1>
<?php
if (isset($uploadResult)) {
echo "<p><strong>$uploadResult</strong></p>";
}
?>
<form action="" method="post" enctype="multipart/form-data" name="uploadImage" id="uploadImage">
<p>
<label for="image">Upload image:</label>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />
<input type="file" name="images" id="imagesd" />
</p>
<p>
<input type="submit" name="upload" id="upload" value="Upload" />
</p>
</form>
<div id="maincontent">
<h2>Foto informatie</h2>
<form name="FotoInformatie" id="fotoInformatie" method="post" action="">
<table>
<tr>
<td align="center"><strong>Foto<strong></td>
<td align="center"><strong>Titel</strong></td>
<td align="center"><strong>Beschrijving</strong></td>
<td align="center"><strong>Homepage</strong></td>
</tr>
<?php
while ($rows=$result->fetch_assoc()) {
?>
<tr>
<td class="hide" align="center"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td>
<td><img src="../img/thumbs/<?php echo $rows['filename']; ?>"></td>
<td align="center"><input name="title[]" type="text" id="title" value="<?php echo $rows['title']; ?>"></td>
<td align="center"><input name="caption[]" type="text" id="caption" value="<?php echo $rows['caption']; ?>"></td>
<td><input type="checkbox" name="checkboxHome[]" id="checkBoxHome" value="<?php echo ($rows['home'] == 1) ? 'checked="checked"' : ''; ?>"/></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="center">
<input type="submit" name="submit" value="Submit">
</tr>
</table>
</form>
</div>
</article> <!-- end of content -->
</div> <!-- end of container -->
<?php include('includes/footer.inc.php'); ?>
</body>
</html>
<?php
if(isset($_POST['submit'])) {
$title = $_POST['title'];
$caption = $_POST['caption'];
if ($_POST['checkboxHome'] == "") {
$checkboxHome[] = '0';
} else {
$checkboxHome[] = '1';
}
for($i=0;$i<$count;$i++){
$result1=mysqli_query($conn, "UPDATE gallery SET title='$title[$i]', caption='$caption[$i]', home='$checkboxHome[$i]' WHERE id='$id[$i]'");
header("location:/admin/foto-admin.php");
}
}
?>
The checkbox only works on the first row in my DB. When I select another record, only the first record in my db will be updated.
Another issue is that my checkbox won't be checked so I don't know based on my screen when a image is online or not. in the database I see a 1 of a 0.
I know that sql-injection is possible and I have to prepare the statements, but that is the next step when I get this checkbox-issue working.
Hope someone can help me with my code. It's giving me a headache.
Check these
Attribute name="id[]" for id field is not given. And it should get inside
if(isset($_POST['submit'])) {
$id = $_POST['id'];
}
Incorrect spelling in getting Post value
change
$checkboxHome = $_POST['checkboxHome'];
$checkboxFotoboek= $_POST['checkboxFotoboek'];
$checkboxDelete = $_POST['image_deleted'];
to
$checkboxHome = $_POST['checkBoxHome'];
$checkboxFotoboek= $_POST['checkBoxFotoboek'];
$checkboxDelete = $_POST['checkboxDelete'];
You are trying to get wrong value.
Your check-box name is checkBoxHome and you are trying to get $_POST['checkboxHome'] instead of $_POST['checkBoxHome'] .
Try $_POST['checkBoxHome'] and print it as print_r('checkBoxHome')
Same mistake in checkBoxFotoboek check-box.
try this
if(isset($_POST['submit'])) {
$title = $_POST['title'];
$caption = $_POST['caption'];
$checkboxHome = $_POST['checkBoxHome'];
$checkboxFotoboek= $_POST['checkBoxFotoboek'];
$checkboxDelete = $_POST['checkboxDelete'];
for($i=0;$i<$count;$i++){
$result1=mysqli_query($conn, "UPDATE gallery SET title='$title[$i]', caption='$caption[$i]', home='$checkboxHome[$i]', fotoboek='$checkboxFotoboek[$i]', image_deleted='$checkboxDelete[$i]' WHERE id='$id[$i]'");
header("location:/admin/foto-admin.php");
}
}
?>
im having problems trying to show the selected items array. I mean, i have a list that shows a table with ID, Name,Apellido. (name is the one with dinamic array [].
When i se the table everthing is allright, but when i click the edit button, i get right id, the right apellido and name gets the last array inserted.
If i click to edit ID number 5 and i have 15, it will show me the 15 instead of number 5 (the selected one).
could anyone find what im doing wrong?
thanks
this are the files im using
list.php
update.php
<!DOCTYPE html>
<?php
$host="localhost"; // Host name
$username="inputmultiplicad"; // Mysql username
$password="inputmultiplicado"; // Mysql password
$db_name="inputmultiplicado"; // Database name
$tbl_name="input_field"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$id=$_GET['id'];
$first_name=$_GET['first_name'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
// Retrieve data from database to implode/explode
$select_tbl=mysql_query("select * from input_field");
while($fetch=mysql_fetch_object($select_tbl))
{
echo $id;
$r=$fetch->firstname;
$i=explode(",",$r);
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/estilos.css" media="screen" />
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<link href='http://fonts.googleapis.com/css?family=Oxygen' rel='stylesheet' type='text/css'>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="main contenedor">
<header>
<section class="logo">LOGO</section> <!--logo-->
</header>
<div id="contenedor">
<div class="insertar_formulario">
<h3>Editar Cliente</h3>
<h3>id</h3>
<? echo $rows['id'];
?>
<form name="form1" method="post" action="update_ac.php">
<section class="nombre"><h2>Nombre</h2>
<?
for($x = 0; $x < count($i); $x++ )
{
echo "<input type='text' name='firstname[]' value='$i[$x]'><input type='button' value='+'/><br />";
};
?>
</section>
<section class="apellido"><h2>Apellido</h2>
<input type='text' name='apellido[]' value='<? echo $rows['apellido']; ?>'/>
</section>
<section class="enviar">
<input type="submit" name="Submit" value="Submit">
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</section>
</form>
</div>
</div><!--contenedor-->
</div> <!--main contenedor-->
</body>
</html>
<?php
// close connection
mysql_close();
?>
list.php
<?php
$host="localhost"; // Host name
$username="inputmultiplicad"; // Mysql username
$password="inputmultiplicado"; // Mysql password
$db_name="inputmultiplicado"; // Database name
$tbl_name="input_field"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>
<tr>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Add+</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['id']; ?></td>
<td><? echo $rows['firstname']; ?></td>
<td align="center">Editar</td>
<td bgcolor="#FFFFFF">delete</td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
?>
SOLVED, it was something stupid
Change update.php
this:
$select_tbl=mysql_query("select * from input_field");
to:
$select_tbl=mysql_query("select * from input_field WHERE id='$id'");
I have a php application that fetches the requests from mysql database and displays them for further approval. The form is fetched from send_req.php and is displayed inside the div on showrequests.php. This is the code for send_req.php
<table style="border:0;border-color:transparent">
<tr style="background-color:lightblue">
<td>Product ID</td>
<td>Name</td>
<td>Quantity</td>
<td><input type="checkbox" name="selectAll" /></td>
<td>Authorized Quantity</td>
</tr>
<form method="post" action="send_req.php">
<?php
$reqNum = $_POST['rId'];
echo "<h3>Request # $reqNum</h3>";
$showReqs = mysql_query("Select * from request where request_number='".$reqNum."' and status=0");
while($resultA = mysql_fetch_array($showReqs))
{
$rBy = $resultA['requested_by'];
$rTime = $resultA['request_time'];
$rId = $resultA['id'];
$pId = $resultA['product_id'];
$getPrName = mysql_query("select name from products where id='$pId'");
$prN = mysql_fetch_array($getPrName);
$prName = $prN['name'];
$rQuantity = $resultA['requested_quantity'];
$status = $resultA['status'];
?>
<tr>
<input type="hidden" name="rId[]" value="<?php echo $rId; ?>"/>
<td style="background-color:orange"><input type="text" name="prId[]" value="<?php echo $pId; ?>" readonly="readonly" style="border:0px"/></td>
<td style="background-color:orange"><input type="text" name="prName[]" value="<?php echo $prName; ?>" readonly="readonly" style="border:0px"/></td>
<td style="background-color:orange"><input type="text" name="quantity[]" value="<?php echo $rQuantity; ?>" readonly="readonly" style="border:0px"/></td>
<td style="background-color:orange"></td>
<td><input type="text" name="pQuantity[]" /></td>
</tr>
<?php }
?>
<tr>
<td></td>
<td></td>
<td></td>
<input type="hidden" name="rNum" value="<?php echo $reqNum; ?>" />
<td></td>
<td><input type="submit" name="submitReq" value="Send" id="submit_req" style="backgroundColor:Transparent;border:0;color:blue;width:100;"/></td>
</tr>
</form>
</table>
<?php
echo "Requested By:$rBy at ".substr($rTime,11,18)." ".substr($rTime,0,10);
?>
This is the showrequests.php page
<html>
<head>
<script type="text/javascript">
function getRequest(ob)
{
var id = ob.id;
if(window.XMLHttpRequest)
{
ajaxOb = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
ajaxOb = new ActiveXObject("Microsoft.XMLHTTP");
}
ajaxOb.open("POST", "send_req.php");
ajaxOb.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxOb.send("rId=" + id);
ajaxOb.onreadystatechange = function()
{
if(ajaxOb.readyState == 4)
{
if(ajaxOb.status == 200)
{
document.getElementById("showTable").innerHTML = ajaxOb.responseText;
}
}
}
}
</script>
</head>
<body>
<?php
$mysql_con = mysql_connect("localhost","root","") or die("Could not connect ".mysql_error());
$mysql_db = mysql_select_db("cart",$mysql_con) or die("Unable to select db ".mysql_error());
echo "<h2 align='center'>Pending Requests</h2>";
$showReq = mysql_query("Select distinct(request_number) as rNums from request where status=0");
?>
<div style="float:left;margin-right:15px;">
<br/>
<?php
while($result = mysql_fetch_array($showReq))
{
$rNum = $result['rNums'];
?>
<input type="button" name="fetchReq" id="<?php echo $rNum; ?>" value="<?php echo "Request # $rNum"; ?>" style="margin-bottom:5px;backgroundColor:Transparent;border:0;color:blue;width:100;text-Decoration:underline" onclick="getRequest(this)"/>
<?php
echo "<br/>";
}
?>
</div>
<div id="showTable" style="float: left">
</div>
</body>
</html>
My problem now is that everything works fine in chrome and IE but the form is not submitted when i click the submit button in firefox. I am using firefox 20.0.1. Update: I have removed the html,head and body tags from send_req.php
still not working
form is not allowed inside table. Please see also
Form inside a table
Regards,
Michael
Reminder : the structure of an HTML document is :
<!-- No div before html tag -->
<!DOCTYPE html> <!-- Doctype for HTML5 ; use whatever doctype you need -->
<html>
<head>
</head>
<!-- No div before body tag -->
<body>
<!-- Divs only belongs here -->
</body>
</html>
<!-- No div after html tag -->
If you don't follow this basic structure, you're forcing the browser to interpret your invalid code (+ quirks mode when you don't provide a doctype).
Some browser guess well what you tried to do, others don't, as Firefox might.
Please use a HTML validator as W3's validator to check your syntax.
<?php
session_start();
include("configdb.php");
if(!session_is_registered(username)){
header("location:index.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Projects</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function un_check(){
for (var i = 0; i < document.frmactive.elements.length; i++) {
var e = document.frmactive.elements[i];
if ((e.name != 'allbox') && (e.type == 'checkbox')) {
e.checked = document.frmactive.allbox.checked;
}
}
}
function Confirm(form){
alert("Project has been activated!");
form.submit();
}
function unConfirm(form){
alert("Project has been Deactivated!");
form.submit();
}
</script>
</head>
<body>
<div id="costDiv">
<div id="divErc"></div>
<div id="costBack">
<?php
if(isset($_POST['checkbox'])){$checkbox = $_POST['checkbox'];
if(isset($_POST['activate'])?$activate = $_POST["activate"]:$deactivate = $_POST["deactivate"])
$id = "('" . implode( "','", $checkbox ) . "');" ;
$sql="UPDATE projects SET p_isActive = '".(isset($activate)?'1':'0')."' WHERE p_id IN $id";
$result = mysql_query($sql) or die(mysql_error());
}
?>
<?php include("hor_menu.php"); ?>
<form name="frmactive" method="post" action="">
<table width="350" border="0" cellspacing="1" cellpadding="5" align="center" style="margin-left:150px ; margin-right:auto ; margin-top:20px ; margin-bottom:auto ; position:absolute ; width:400px">
<tr>
<td align="center" ><input type="checkbox" name="allbox" onclick="un_check(this);" title="Select or Deselct ALL" style="background-color:#ccc;"/></td>
<td align="left"><strong>Project</strong></td>
<td align="left"><strong>Country</strong></td>
<td align="left"><strong>Active</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['p_id']; ?>"/></td>
<td><?php echo $rows['p_name']; ?></td>
<td><?php echo $rows['p_country']; ?></td>
<td><?php if ($rows['p_isActive'] == '1'){ echo'Active';} else{ echo 'Inactive';} ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5"><input name="activate" type="submit" id="activate" value="Activate" onClick="Confirm(this.form)" />
<input name="deactivate" type="submit" id="deactivate" value="Deactivate" onClick="unConfirm(this.form)"/></td>
</tr>
</table>
?>
</td>
</tr>
</table>
</form>
</body>
</html>
i have this code.when i check a checkbox project will be either activated or deactivated according to bottom.however this code works perfectly on all browsers except google chrome and safari.can anyone help please.it keeps giving that have an error in my sql syntax espeaciall after the where clause in the update query.thank you
If you get an SQL error depending on browser, then you most likely need to check your inputs. PHP execution does not differ depending on what browser you're using, other than what data it gets from client side controls like textboxes or triggers.
I suggest you log the $sql variable in some way, you could try just using var_dump, to see how the data changes between browsers.
This is not legal: id="checkbox[]" get rid of it.
It's not necessary to assign everything an ID. Only assign an ID if you actually use it in the javascript. Otherwise just leave it out.
INPUT fields do need a name attribute, but that works completely differently from an ID.