Re: Problem with sessions.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Balasubramanyam A schreef:
Could someone help with this code? It is a search and delete program. I'm
executing bunch of code within if-else statement. After searching the
records in else block the code is redirecting to if block. I'm not able
delete the records in else block. How do avoid the control move to if block?

1. your problem description is pretty useless - apart form being seemingly
incoherent you also mention an 'if block' and an 'else block' in such a way as
to imply that there is only one of each (there are plenty of each in the code provided).

2. your code is not properly indented at all which makes reading it
and trying to figure out what it does (and what it is supposed to do)
too much bother.

3. your doing alsorts of things wrong aside from any flawed logic that
the script apparently contains.

e.g.

1. why set the following session value unconditionally each time?
why not just use the POST value?

$_SESSION['voucher_value'] =  $_POST['voucher_to'];


2. I assume that k1 is not a constant you have defined elsewhere...

if($_SESSION['voucher_value'] == k1)


3. you have big SQL injection holes in the script, also you make blind
assumptions about incoming request data:

$array= $_POST['checkbox'];
foreach ($array as $key=>$value) {
$sql1 = "DELETE FROM $tbl_name WHERE voucher_number='$array[$key]'";



<?php
session_start();
require_once('connection.php');
$_SESSION['voucher_value'] =  $_POST['voucher_to'];
if(!($_SESSION['voucher_value'] == b1) )
{
$tbl_name = "voucher";
$kodaikanal = "Resident Scientist <br /> IIA, Kodaikanal <br /> Observatory
<br /> KODAIKANAL - 624 103";
$hosakote = "Scientist in-charge <br /> CREST Campus <br /> HOSAKOTE - 562
114";
$leh_ladakh = "Engineer in-charge <br /> IAO-HANLE <br />Fort Road.SKARA <br
/>P.O.Box No.100<br />LEH-LADAKH - 194 101 <br /> (J & K)";
$kavalur = "Resident Scientist <br /> Vainu Bappu Observatory <br /> KAVALUR
- 635 701";

$_SESSION['voucher_value'] =  $_POST['voucher_to'];
if($_SESSION['voucher_value'] == k1)
{
$add_val =  $kodaikanal;
}
elseif($_SESSION['voucher_value'] == h1)
{
$add_val =  $hosakote;
}
elseif($_SESSION['voucher_value'] == l1)
{
$add_val =  $leh_ladakh;
}
elseif($_SESSION['voucher_value'] == k2)
{
$add_val =  $kavalur;
}

if ( !(isset ($_POST['delete']) ) ) {
$_SESSION['name_voucher']= $_POST['search_name'];
}
$search_temp = $_SESSION['name_voucher'];


if(isset($_POST['delete'])){
//$checkboxID= $_POST['checkbox'];
$array= $_POST['checkbox'];
foreach ($array as $key=>$value) {
$sql1 = "DELETE FROM $tbl_name WHERE voucher_number='$array[$key]'";
$result1 = mysql_query($sql1);
}


}
$sql="SELECT * FROM $tbl_name where name='$search_temp' &&
address='$add_val'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

if ($count == 0)
{
include('header.php');
print "<br />";
print "<br />";
print "Search does not find any such records";
print "<br />";
exit();
include('footer.php');
}
include('ser_mis.php');
}




else
{

$tbl_name = "voucherb";
if ( !(isset ($_POST['delete']) ) ) {
$_SESSION['name_voucher']= $_POST['search_name'];
}
$search_temp = $_SESSION['name_voucher'];


if(isset($_POST['delete'])){
//$checkboxID= $_POST['checkbox'];
$array= $_POST['checkbox'];
foreach ($array as $key=>$value) {
$sql1 = "DELETE FROM $tbl_name WHERE voucher_number='$array[$key]'";
$result1 = mysql_query($sql1);
}
if(!(mysql_affected_rows() == 1))
{
include('header.php');
print "<br />";
print "<br />";
print "Records has not been deleted. Please contact administrator";
include('footer.php');
exit();
}else
{
include('header.php');
print "<br />";
print "<br />";
print "The record(s) has been successfully deleted from database";
print "<br />";
exit();
include('footer.php');
}
}
$sql="SELECT * FROM $tbl_name where name='$search_temp'";// &&
address='$add_val'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

/*if ($count == 0)
{
include('header.php');
print "<br />";
print "<br />";
print "Search does not find any such records";
print "<br />";
exit();
include('footer.php');
}*/
include('ser_misb.php');
}

?>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux