Jump to content

[SOLVED] can only delete from bottom up wtf?


ag3nt42

Recommended Posts

Hello again all,

 

Yet another issue brought to you by ag3nt42...

 

lol

 

The below code is not working properly.. I believe I have it setup to allow me to delete individual rows in the database no matter which order they are displayed in...

 

however the code apparently does not think thats how it should happen...

I'm at a loss for words here I do not understand why its being so weird..

 

It tells me my query is successfull yet nothing has changed? wtf is that?

and you can only delete the value if you delete them in order from last to first.

 

WILL NOT delete first to last or anywhere in the middle like it should..

 

here is the code:

 

Form page..:

//* DISPLAY INTERFACE *//
echo("
<html>
<head>
<link rel='stylesheet' type='text/css' href='../admin.css' />
</head>
<body>

<table>
<tr>
	<td colspan='2'><h1>Client Types</h1></td>
</tr>
<tr>
	<td colspan='2'>
		<fieldset><legend>Client Types</legend>
			<form action='../Ca_info/Cct_info.php' method='post'>
				<table>
					<tr>
						<td style='text-align:right;'><label>Type: </label></td>
						<td style='text-align:left;'><input type='text' value='' name='Ctype' /></td>
					</tr>
					<tr>
						<td> </td>
					</tr>
					<tr>
						<td style='text-align:right;'><input type='reset' value='Reset' /></td>
						<td style='text-align:left;'><input type='submit' value='Submit' /></td>
					</tr>
				</table>
			</form>
		</fieldset>
	</td>
</tr>
<tr>
	<td><h2>Available Types</h2></td>
</tr>
</table>	
<div class='TypeScroll'>
<table>
");

////////////////////////
//* SNATCH AVAILABLE *//
////////////////////////

//* STOP THE BITCHING *//
$Z=array('','','','','');

$database=$tblpre."ClientType";
$AvailableSQL="SELECT Type FROM [".$database."]";
$result=mssql_query($AvailableSQL)or die(mssql_error());
$count=mssql_num_rows(mssql_query($AvailableSQL));
$y=0;
while($row=mssql_fetch_row($result))
{
$Z=$row[0];
$y++;
echo("

<tr>
	<td width='50%' style='text-align:right;'>".$Z."
		<form action='../Ca_info/Cct_info.php' method='post'>
			<input type='hidden' value='".$Z."' name='Type".$y."' />

	</td>
	<td width='50%' style='text-align:left;'>

			<input type='submit' value='Delete' />
		</form>
	</td>
</tr>
<tr>
	<td colspan='2'> </td>
</tr>	
");
}

//* IF NONE ARE AVAILABLE *//
if($count<=0)
{
echo("<tr>".PHP_EOL."<td>No Currently Available Types</td>".PHP_EOL."</tr>".PHP_EOL);
}
else
{
echo("");
}


echo("</table>".PHP_EOL."</div>".PHP_EOL."</table>".PHP_EOL."</body>".PHP_EOL."</html>");
?>

 

the process page:

 

////////////////////////////////
//****************************//
//* Harvest Form Information *//
//****************************//
////////////////////////////////
//ADD
if(!(isset($_POST['Ctype']))){$Delete='Yes';$Ctype='';}else{$Delete='No';$Ctype=$_POST['Ctype'];}


//DELETE
//* STOP THE BITCHING *//
$Type= array('','','','','');
$Z=array('','','','','');

//* CHECK HOW MANY *//
$database=$tblpre."ClientType";
$AvailableSQL="SELECT * FROM [".$database."]";
$result=mssql_query($AvailableSQL)or die(mssql_error());
$y=0;
$count=mssql_num_rows(mssql_query($AvailableSQL));
while($row=mssql_fetch_row($result))
{
$Z[$y]=$row[0];
$y++;
}


////////////////////////////
//************************//
//* Setup SQL Variables  *//
//************************//
////////////////////////////
//The Table+Prefix
$datatable=$tblpre."ClientType";

//COLLECT DELETE INPUT
for($x=0;$x<=$count;$x++)
{
if(!(isset($_POST['Type'.$x]))){$Type[$x]='';}else{$Type[$x]=$_POST['Type'.$x];}

//SQL VARIABLE MUST BE SET HERE FOR X TO BE CORRECT
$TypeDelete="DELETE FROM [".$datatable."] WHERE Type='".$Type[$x]."'";
echo($Type[$x]);
}



$TypeInsert="INSERT INTO [".$datatable."] VALUES ('".$Ctype."');";


////////////////////////////
//************************//
//* Start SQL Injections *//
//************************//
////////////////////////////
$Success=0;
$Fail=0;
// IF ADDING
if($Delete=='No')
{
if(mssql_query($TypeInsert))
{
	echo("<font color='green'>".$Ctype."Type Added Successfully!</font><br />");
	$Success++;
}

else
{
	echo("<font color='red'>".$Ctype."FAILED</font>".mssql_error());
	$Fail++;
}
}
//IF DELETING
elseif($Delete=='Yes')
{
if(mssql_query($TypeDelete))
{
	echo("<font color='green'>Type Deleted Successfully!</font><br />");
	$Success++;
}
else
{
	echo("<font color='red'>FAILED</font>".mssql_error());
	$Fail++;
}
}

if($Success<=0)
{//NOTHING
echo('');
}
elseif($Success==1)
{//REDIRECT
echo("<meta http-equiv='refresh' content='3;url=http://".$domain.$sPath."admin/Edits/ClientTypes.php'>");
}

?>

 

ok I have no idea how this is working but it is...

 

////////////////////////////
//************************//
//* Setup SQL Variables  *//
//************************//
////////////////////////////
//The Table+Prefix
$datatable=$tblpre."ClientType";

//COLLECT DELETE INPUT
for($x=1;$x<=$count;$x++)
{
if(!(isset($_POST['Type'.$x]))){$Type[$x]='';}else{$Type[$x]=$_POST['Type'.$x];}

//SQL VARIABLE MUST BE SET HERE FOR X TO BE CORRECT
$TypeDelete[$x]="DELETE FROM [".$datatable."] WHERE Type='".$Type[$x]."'";
echo($Type[$x]);
}



$TypeInsert="INSERT INTO [".$datatable."] VALUES ('".$Ctype."');";


////////////////////////////
//************************//
//* Start SQL Injections *//
//************************//
////////////////////////////
$Success=0;
$Fail=0;
// IF ADDING
if($Delete=='No')
{
if(mssql_query($TypeInsert))
{
	echo("<font color='green'>".$Ctype."Type Added Successfully!</font><br />");
	$Success++;
}

else
{
	echo("<font color='red'>".$Ctype."FAILED</font>".mssql_error());
	$Fail++;
}
}
//IF DELETING
elseif($Delete=='Yes')
{
for($x=1;$x<=$count;$x++)
{
	if(mssql_query($TypeDelete[$x]))
	{
		echo("<font color='green'>Type Deleted Successfully!</font><br />");
		$Success++;
	}
	else
	{
		echo("<font color='red'>FAILED</font>".mssql_error());
		$Fail++;
	}
}
}

if($Success<=0)
{//NOTHING
echo('');
}
elseif($Fail<=0)
{//REDIRECT
echo("<meta http-equiv='refresh' content='3;url=http://".$domain.$sPath."admin/Edits/ClientTypes.php'>");
}

?>

I'm guessing it only works because I'm looping through to delete ALL entries

(loop is based on SQL count)

 

Even tho i'm looping through and deleting all the entries... only one entry has a value passed because only one entry's value is sent over..

 

its frikin weird and I barely understand it but it workds and I wrote it ....?lol

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.