Problema con primera aplicación php
Hola amigo soy muy novato en esto de php así que agradecería si me puedes ayudar en este problema que tengo ya varios días que es el siguienteojo utilizo algo de javascrict recién empezando diría yo
este es mi categoría.php
<?php require "conexion.php";
//$sql = "select * from categorias ";
//$reg = mysql_db_query($bd,$sql,$con);
?>
<html>
<head>
<title>Documento sin título</title>
<style type="text/css">
<!--
.cate {
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 12px;
}
-->
</style>
<script language="javascript" type="text/javascript">
function eliminar(id)
{
if (confirm("Realmente desea eliminar el registro?"))
{
window.location="eliminar.php?id_empleado="+id;
}
}
</script>
</head>
<body>
<table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><?php
require(basename('cabecera.php'));
?></td>
</tr>
<tr>
<td width="171" valign="top"><?php
require(basename('menu.php'));
?></td>
<td width="579">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td align="center">
<p><strong class="cate">Categoria</strong></p>
<!--<form id="form1" name="form1" method="POST" action="">
<table width="300" border="1" align="center" cellpadding="2" cellspacing="0">
<tr>
<td width="93" align="center">Categoria</td>
<td width="207"><label>
<input name="txt_categoria" type="text" id="txt_categoria" size="35" value="" />
</label></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="button" id="button" value="ok" /></td>
</tr>
</table>
</form>-->
<table width="99%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="87%" valign="top"><strong>Categorias</strong></td>
<td colspan="2" align="center"><strong>Acción</strong></td>
</tr>
<?php
$sql="select * from categorias";
$res= mysql_query($sql,$con);
while($reg=mysql_fetch_array($res))
{
?>
<tr>
<td><?php echo $reg["categoria"];?></td>
<td width="5%" align="center"><a href="editar.php?id_categoria=<?php echo $reg["id_categoria"];?>" title="editar"><img src="../imagenes/alterar.gif" width="16" height="16" border="0" /></a></td>
<td width="5%" align="center"><a href="javascript:void(0)" title="eliminar" onClick="eliminar('<?php echo $reg["id_categoria"];?>')"><img src="../imagenes/excluir.gif" width="16" border="0" height="16" /></a></td>
</tr>
<?php }?>
<tr>
<td colspan="3" align="right"><a href="insertar.php" title="agregar categoria"><img src="../imagenes/insertar.gif" width="55" border="0" height="16" /></a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"><?php
require(basename('footer.php'));
?></td>
</tr>
</table>
</body>
</html>
esta mi conexion.php
<?php
$con=mysql_connect("localhost","root","");
$bd=mysql_select_db("compras");
function saludo()
{
echo "hola mundo";
}
Esta es insertar.php como veras una tabla con dis filas una volver que esta en javascript y la otras para ingresar una nueva categoría
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script language="javascript" type="text/javascript" src="js/funciones.js">
</script>
</head>
<bodyb onload="limpiar()">
<form action="add.php" method="POST" name="form">
<table align="center" width="400" >
<tr>
<td align="center" valign="top" width="400" colspan="2">
<h3>Agregar Categoria</h3>
</td>
</tr>
<tr>
<td align="center" valign="top" width="200" >
Nombre
</td>
<td align="center" valign="top" width="200" >
<input type="text" name="nom" /></td>
</tr>
<tr>
<td align="center" valign="top" width="400" colspan="2">
<input type="button" value="volver" title="volver" onClick="history.back();" />
||
<input type="button" value="Agregar Categoria" title="Agregar Categoria" onClick="validar()" />
</td>
</tr>
</table>
</form>
</body>
</html>
esta es add.php
<?php
require_once("conexion.php");
$sql= "INSERT INTO `categorias`
values ( '".$_POST["nom"]."')";
//echo $sql;
$res=mysql_query($sql,$con);
/*echo "
<script type=''>
alert('El empleado fue ingresado correctamente');
...
este es mi categoría.php
<?php require "conexion.php";
//$sql = "select * from categorias ";
//$reg = mysql_db_query($bd,$sql,$con);
?>
<html>
<head>
<title>Documento sin título</title>
<style type="text/css">
<!--
.cate {
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 12px;
}
-->
</style>
<script language="javascript" type="text/javascript">
function eliminar(id)
{
if (confirm("Realmente desea eliminar el registro?"))
{
window.location="eliminar.php?id_empleado="+id;
}
}
</script>
</head>
<body>
<table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><?php
require(basename('cabecera.php'));
?></td>
</tr>
<tr>
<td width="171" valign="top"><?php
require(basename('menu.php'));
?></td>
<td width="579">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td align="center">
<p><strong class="cate">Categoria</strong></p>
<!--<form id="form1" name="form1" method="POST" action="">
<table width="300" border="1" align="center" cellpadding="2" cellspacing="0">
<tr>
<td width="93" align="center">Categoria</td>
<td width="207"><label>
<input name="txt_categoria" type="text" id="txt_categoria" size="35" value="" />
</label></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="button" id="button" value="ok" /></td>
</tr>
</table>
</form>-->
<table width="99%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="87%" valign="top"><strong>Categorias</strong></td>
<td colspan="2" align="center"><strong>Acción</strong></td>
</tr>
<?php
$sql="select * from categorias";
$res= mysql_query($sql,$con);
while($reg=mysql_fetch_array($res))
{
?>
<tr>
<td><?php echo $reg["categoria"];?></td>
<td width="5%" align="center"><a href="editar.php?id_categoria=<?php echo $reg["id_categoria"];?>" title="editar"><img src="../imagenes/alterar.gif" width="16" height="16" border="0" /></a></td>
<td width="5%" align="center"><a href="javascript:void(0)" title="eliminar" onClick="eliminar('<?php echo $reg["id_categoria"];?>')"><img src="../imagenes/excluir.gif" width="16" border="0" height="16" /></a></td>
</tr>
<?php }?>
<tr>
<td colspan="3" align="right"><a href="insertar.php" title="agregar categoria"><img src="../imagenes/insertar.gif" width="55" border="0" height="16" /></a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"><?php
require(basename('footer.php'));
?></td>
</tr>
</table>
</body>
</html>
esta mi conexion.php
<?php
$con=mysql_connect("localhost","root","");
$bd=mysql_select_db("compras");
function saludo()
{
echo "hola mundo";
}
Esta es insertar.php como veras una tabla con dis filas una volver que esta en javascript y la otras para ingresar una nueva categoría
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script language="javascript" type="text/javascript" src="js/funciones.js">
</script>
</head>
<bodyb onload="limpiar()">
<form action="add.php" method="POST" name="form">
<table align="center" width="400" >
<tr>
<td align="center" valign="top" width="400" colspan="2">
<h3>Agregar Categoria</h3>
</td>
</tr>
<tr>
<td align="center" valign="top" width="200" >
Nombre
</td>
<td align="center" valign="top" width="200" >
<input type="text" name="nom" /></td>
</tr>
<tr>
<td align="center" valign="top" width="400" colspan="2">
<input type="button" value="volver" title="volver" onClick="history.back();" />
||
<input type="button" value="Agregar Categoria" title="Agregar Categoria" onClick="validar()" />
</td>
</tr>
</table>
</form>
</body>
</html>
esta es add.php
<?php
require_once("conexion.php");
$sql= "INSERT INTO `categorias`
values ( '".$_POST["nom"]."')";
//echo $sql;
$res=mysql_query($sql,$con);
/*echo "
<script type=''>
alert('El empleado fue ingresado correctamente');
...
1 respuesta
Respuesta de Jorge Vila
-1