Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/09/2011, 14:02
Alber_h
 
Fecha de Ingreso: septiembre-2009
Mensajes: 138
Antigüedad: 14 años, 8 meses
Puntos: 3
Eliminacion Php - Ajax

Tengo los siguientes codigos enumerados:1,2,3,4.

1)eliminacion.php:

<?php

require('conexion.php');

if(isset($_REQUEST['caja']))

{

$cajavalor=$_GET['caja'];
$sql="delete from curso where id=$cajavalor";

mysql_query($sql,$con);

}

include('Untitled-7.php');

?>



2)Untitled-7.php:


<?php

$con = mysql_connect("localhost","root","");

$sel=mysql_select_db("bd_pd");

$sql="select * from curso";

$sql1=mysql_query($sql);
?>
<br><br><br>
<table style="border:1px solid #FF0000; color:#000099;width:400px;">
<tr style="background:#99CCCC;">
<td align="center">Id</td>
<td align="center">Nombre</td>
<td align="center">Ciclo</td>
<td align="center">Aula</td>
<td align="center">Seleccion</td>
</tr>
<?php
while($row = mysql_fetch_array($sql1)){
echo "<tr id=celdas name=celdas align=center width=350 onmouseover=this.style.cursor='hand'>";
echo "<td>";
echo $row[0];
echo "</td>";
//<a style=\"text-decoration:underline;cursor:pointer;\" onclick=\"eliminarDato('".$row['Id']."')\">".$row['Id'].</a>
//echo "<td width=700>";
//echo $row[0];
//echo "</td>";
echo "<td width=700 name=id>";
echo $row[1];
echo "</td>";
echo "<td width=700>";
echo $row[2];
echo "</td>";
echo "<td width=700>";
echo $row[3];
echo "</td>";
echo "<td width=700>";
echo "<input type=checkbox name=caja value=$row[0]>";
echo "</input>";
echo "</td>";
echo "</tr>";
}
?>
</table>

3)ajaxelim.js:

function objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

function eliminarDato(caja){
//donde se mostrará el resultado de la eliminacion
divResultado = document.getElementById('resultado');
//usaremos un cuadro de confirmacion
var eliminar = confirm("De verdad desea eliminar este dato?")

if ( eliminar ) {
//instanciamos el objetoAjax
ajax=objetoAjax();
//uso del medotod GET
//indicamos el archivo que realizará el proceso de eliminación
//junto con un valor que representa el id del empleado
ajax.open("GET", "eliminacion.php?caja="+caja);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
//mostrar resultados en esta capa
divResultado.innerHTML = ajax.responseText
}
}
//como hacemos uso del metodo GET
//colocamos null
ajax.send(null)
}
}




4)index.php:

<html>
<head>
<title>PPD2</title>
<link href="Untitled-2.css" rel="stylesheet" type="text/css">

<script language="JavaScript" type="text/javascript" src="ajaxelim.js"></script>

</head>
<body>

<form name="eliminar" method="get" onSubmit="eliminarDato('eliminacion.php'); return false">
<div id="Layer16" align="center">
<input type="submit" name="Submit4" value="Eliminar" onClick="eliminarDato($row[Id])">

</div>
</form>

</body>
</html>

Les Resumo todo esto: El codigo 1 que es eliminacion.php se encarga de eliminar el registro en la tabla curso recogiendo el valor del indice de la tabla de datos que se obtiene mediante el codigo 2 que es untitled-7.php,luego en el codigo 3 que ajaxelim.js envia ese valor recogido que se obiene a partir del codigo 1 yt 3 respectivamente y para terminar el codigo 4 que es index.php, aqui es donde trato de eliminar ese registro que esta en mi tabla de mi aplicacion haciendo click en el checkbox.

En resumen general trato de eliminar un registro de mi base de datos mediante ajax con mi tabla de mi aplicacion haciendo click en el checkbox.