Los formularios están separados del código me dijeron que así lo quiere la profesora...
ninguna de los tres funciona, ya que me da error la parte de <javascript>
consultar1.php: <?php$base="basedatos";$server="loca1host";$user="root";$clave="";$resul=mysql_connect($server,$user,$clave);mysql_select_db($base);$cedula=$_POST['CEDULA'];$sq1="SELECT * FROM tabla1 WHERE CEDULA= '".$cedu1a."'";$resul=mysq1_query ($sq1);$reg_num= mysql_num_rows($resu1);if($reg_num<= O){echo "Sin resultados";}else{$consul= mysql_fetch_array($resul);$cedula= $consul ['CEDULA'];$nombre= $consu1 ['NOMBRE']; $apellido= $consul ['APELLIDO']; $edad= $consul ['EDAD']; echo ’<SCRIPTLANGUAGE="javascript">location.href"consultar2.php?&CEDULA='.$cedula.'&NOMBRE='.$nombre.'&APELLIDO='.$apellido.'&EDAD='.$edad.'";</SCRIPT>';}?>
</body>
</html>
Modificar1.php: <?php$base="basedatos";$server="loca1host"; .$user="root";$c1ave=" ";$resul=mysql_connect($server,$user,$c1ave);mysq1_select_db($base);$cedula=$_POST['CEDULA'];$sql="SELECT * FROM tabla1 WHERE CEDULA = '".$cedula."'";$resu1=mysql_query ($sq1);$reg_num= mysql_num_rows($resul);if($reg_num <= 0){echo " Sin resultados";}else{$consul= mysql_fetch_array($resul);$cedula= $consul ['CEDULA'];$nombre= $consul ['NOMBRE'];$apellido= $consu1 ['APELLIDO'];$edad= $consu1 ['EDAD']; echo '<SCRIPTLANGUAGE="javascript">1ocation.href="modificar2.php?&CEDULA='.$cedula.'&NOMBRE='.$nombre. '&APELLIDO='.$ape11ido.'&EDAD='.$edad."' ;</SCRIPT>';}?>
Eliminar1.php: <?php$cedu1a=$_POST['cedu1a'];$sql= "DELETE FROM tabla1 WHERE cedu1a= " '.$cedu1a.' "";$res =mysq1_query ($sq1);if ($res) {echo'<scriptLENGUAJE= "javascript">location.href= "eliminar.php?reg=1&mensaje=E1iminacion Exitosa!";</SCRIPT>'{else{ echo '<SCRIPTLENGUAJE="javascript">location.href="eliminar.php?reg=0&mensaje=E1iminacion Fa1lo...";</SCRIPT>';{?>
Ahí te dejé el archivo en .rar
Modificación de la respuesta de arriba:
Los formularios están separados del código me dijeron que así lo quiere la profesora...
ninguna de los tres funciona, ya que me da error la parte de <javascript>
Formulario Incluir.php <style type="text/css">
<!--
.style1 {font-weight: bold}
.style5 {font-weight: bold}
.style7 {font-weight: bold}
.style9 {font-weight: bold}
.style11 {font-weight: bold}
-->
</style>
<form id="form1" name="form1" method="post" action="incluir1.php">
<label></label>
<p>
<label></label>
</p>
<table width="1024" height="107" border="5" cellpadding="1" cellspacing="1">
<tr>
<th height="23" scope="col"><strong>
<label>CEDULA:
<input name="CEDULA" type="text" id="CEDULA" />
</label>
</strong></th>
</tr>
<tr>
<td height="23" class="style5"><div align="center">NOMBRE:
<input name="NOMBRE" type="text" id="NOMBRE" />
</div></td>
</tr>
<tr>
<td height="23" class="style7"><div align="center">APELLIDO:
<input name="APELLIDO" type="text" id="APELLIDO" />
</div></td>
</tr>
<tr>
<td height="23" class="style9"><div align="center">EDAD:
<input name="EDAD" type="text" id="EDAD" />
</div></td>
</tr>
</table>
<p class="style11">
<label></label>
<label>
<div align="center">
<div align="center">Incluir nuevo registro --->
<input type="submit" name="Submit" value="Registrar" />
</div>
</label>
<div align="left"><strong><a href="consultar.php">Ir a Módulo Consultas</a></strong></div>
<label><br />
</label>
<p>
<label></label>
</p>
<p>
<label></label>
</p>
<p> <span class="style1">
<label> </label>
</span>
<label></label>
</p>
</form>
<p> </p>
Código Incluir1.php <form name="form1" method="post" action="incluir.php">
<label>
Regresar a página anterior
<input type="submit" name="Submit" value="Regresar ">
</label>
</form>
<?php$base="basedatos";$server="localhost";$user="root";$clave="";$resul=mysql_connect($server,$user,$clave);mysql_select_db($base);$cedula=$_POST['CEDULA'];$nombre=$_POST['NOMBRE'];$apellido=$_POST['APELLIDO'];$edad=$_POST['EDAD'];$sql="INSERT INTO tabla1 (CEDULA,NOMBRE,APELLIDO,EDAD) VALUES ('".$cedula."','".$nombre."','".$apellido."','".$edad."')";$resul=mysql_query($sql);if(!$resul){ echo "registro fallido";}else{ echo "registro exitoso";}?>
Formulario Consultar.php <body>
<form id="form1" name="form1" method="post" action="consultar1.php">
<p> </p>
<div align="justify">
<table width="1024" border="5" cellspacing="1" cellpadding="1">
<tr>
<th scope="col"><strong>Cédula
<input name="CEDULA" type="text" id="CEDULA" />
</strong>
</label></th>
</tr>
</table>
</div>
<label>
<div align="justify">Consultar Registro --->>>
<input type="submit" name="Submit" value="Consultar" />
</div>
</div>
</label>
<div align="justify">
</p>
<p align="center">
</div>
<label>
<div align="left">
<div align="justify"><a href="modificar.php">Ir Modificar Registro</a></div>
</label>
</form>
<p> </p>
<p>
<label></label>
</p>
</body>
</html>
código consultar1.php: <?php$base="basedatos";$server="loca1host";$user="root";$clave="";$resul=mysql_connect($server,$user,$clave);mysql_select_db($base);$cedula=$_POST['CEDULA'];$sq1="SELECT * FROM tabla1 WHERE CEDULA= '".$cedu1a."'";$resul=mysq1_query ($sq1);$reg_num= mysql_num_rows($resu1);if($reg_num<= O){echo "Sin resultados";}else{$consul= mysql_fetch_array($resul);$cedula= $consul ['CEDULA'];$nombre= $consu1 ['NOMBRE']; $apellido= $consul ['APELLIDO']; $edad= $consul ['EDAD']; echo ’<SCRIPTLANGUAGE="javascript">location.href"consultar2.php?&CEDULA='.$cedula.'&NOMBRE='.$nombre.'&APELLIDO='.$apellido.'&EDAD='.$edad.'";</SCRIPT>';}?>
</body>
</html>
Formulario Modificar.php <form id="form1" name="form1" method="post" action="modificar2.php">
<p>
<label></label>
</p>
<table width="1024" border="5" cellspacing="1" cellpadding="1">
<tr>
<th scope="col"><strong>Cédula
<input name="CEDULA" type="text" id="CEDULA" />
</strong></th>
</tr>
<tr>
<td><p>
<label> Consultar Registro --->>>
<input type="submit" name="Submit" value=" Consultar" />
</label>
</p></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
<p> </p>
código Modificar1.php: <?php$base="basedatos";$server="loca1host"; .$user="root";$c1ave=" ";$resul=mysql_connect($server,$user,$c1ave);mysq1_select_db($base);$cedula=$_POST['CEDULA'];$sql="SELECT * FROM tabla1 WHERE CEDULA = '".$cedula."'";$resu1=mysql_query ($sq1);$reg_num= mysql_num_rows($resul);if($reg_num <= 0){echo " Sin resultados";}else{$consul= mysql_fetch_array($resul);$cedula= $consul ['CEDULA'];$nombre= $consul ['NOMBRE'];$apellido= $consu1 ['APELLIDO'];$edad= $consu1 ['EDAD']; echo '<SCRIPTLANGUAGE="javascript">1ocation.href="modificar2.php?&CEDULA='.$cedula.'&NOMBRE='.$nombre. '&APELLIDO='.$ape11ido.'&EDAD='.$edad."' ;</SCRIPT>';}?>
Formulario de Modificar2.php <!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=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {font-weight: bold}
.style5 {font-weight: bold}
.style7 {font-weight: bold}
.style9 {font-weight: bold}
-->
</style>
</head>
<body>
<table width="1024" height="167" border="5" cellpadding="1" cellspacing="1">
<tr>
<th height="26" scope="col"><strong>
<label> CEDULA:
<input name="CEDULA" type="text" id="CEDULA" />
</label>
</strong></th>
</tr>
<tr>
<td height="45" class="style5"><label>
<div align="center">NOMBRE:
<input name="NOMBRE" type="text" id="NOMBRE" />
</div>
</label></td>
</tr>
<tr>
<td height="45" class="style7"><div align="center">APELLIDO:
<input name="APELLIDO" type="text" id="APELLIDO" />
</div>
</label></td>
</tr>
<tr>
<td class="style9"><div align="center">EDAD:
<input name="EDAD" type="text" id="EDAD" />
</div></td>
</tr>
</table>
<p class="style11">
<label></label>
<label>
<div align="center">
<div align="center">Modificar Registro--->
<input type="submit" name="Submit" value="Modificar" />
</div>
</label>
<label>
<div align="center"><br />
</div>
<div align="left">
<p><strong><a href="eliminar.php">Ir aMódulo Eliminar </a></strong></p>
</div>
<label></label>
<form id="form1" name="form1" method="post" action="modificar.php">
<input type="submit" name="Submit2" value="Regresar " />
Regresar Página anterior
</form>
<label><br />
</label>
<p>
<label></label>
</p>
<p>
<label></label>
</p>
<p> <span class="style1">
<label> </label>
</span>
<label></label>
</p>
</body>
</html>
Formulario de Eliminar.php <form name="form1" method="post" action="eliminar1.php">
<div align="center"><strong>Cédula
<input name="CEDULA" type="text" id="CEDULA" />
</strong></div>
<p>
<label>Eliminar Registro --->>>
<input type="submit" name="Submit" value="Eliminar" />
</label>
</p>
</form>
<p> </p>
Código Eliminar1.php: <?php$cedu1a=$_POST['cedu1a'];$sql= "DELETE FROM tabla1 WHERE CEDULA= " '.$cedu1a.' "";$res =mysq1_query ($sq1);if ($res) {echo'<scriptLENGUAJE= "javascript">location.href= "eliminar.php?reg=1&mensaje=E1iminacion Exitosa!";</SCRIPT>'{else{ echo '<SCRIPTLENGUAJE="javascript">location.href="eliminar.php?reg=0&mensaje=E1iminacion Fa1lo...";</SCRIPT>';{?>
Ahí arriba te dejé el archivo en .rar
Gracias por tu respuesta Mastermind, estuve dandole y dandole hasta que solucioné el problema de consultar. ¿Cómo? pués borré la linea de código 'echo javascript'
y coloqué esto, no se si eso sea correcto hacerlo ya que la profe lo tenía con echo javascript pero no me funciona...
Otra cosa una pregunta: ¿Qué debería hacer esa linea de código?, ayer en ejecución consulté y en la barra del buscador al final aparecían los resultados, pero yo quiero que los valores me los devuelva en la página ¿es esta la manera de hacerlo?
<form action="consultar.php" method="post" name="form1" id="form1">
<label> Regresar a página anterior
<input type="submit" name="Submit2" value="Regresar " />
</label>
</form>
<?php$base="basedatos";$server="localhost";$user="root";$clave="";$resul=mysql_connect($server,$user,$clave);mysql_select_db($base);$cedula=$_POST['cedula'];$sql="SELECT * FROM tabla1 WHERE cedula = '".$cedula."'";$resul=mysql_query ($sql);$reg_num= mysql_num_rows($resul);if($reg_num <= 0) {echo "Sin resultados";}else{$consul= mysql_fetch_array($resul);$cedula= $consul ['cedula'];$nombre= $consul ['nombre']; $apellido= $consul ['apellido']; $edad= $consul ['edad']; if ($_POST ) { echo 'Cedula del Usuario: '.$cedula. ' <br/>'; echo 'Nombre del Usuario: '.$nombre.' <br/>'; echo 'Apellido del Usuario: '.$apellido.'<br/>'; echo 'Edad del Usuario: '.$edad.'<br/>';}{}}?>
</body>
</html>
Prueba a ver si te corre y me dices, ahora necesito solucionar el problema de Modificar1.php y el eliminar1.php, ¿me ayudas please? yo seguiré trabajando y si soluciono te aviso. Buen dia.
Modificar me da este error "Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in C:\wamp\www\Base de datos MYSQL\modificar1.php on line 23"
<?php$base="basedatos";$server="localhost"; $user="root";$clave=" ";$resul=mysql_connect($server,$user,$c1ave);mysql_select_db($base);$cedula=$_POST['cedula'];$sql="SELECT * FROM tabla1 WHERE cedula = '".$cedula."'";$resul=mysql_query ($sql);$reg_num= mysql_num_rows($resul);if($reg_num <= 0){echo " Sin resultados";}else {$consul= mysql_fetch_array($resul);$cedula= $consul ['cedula'];$nombre= $consul ['nombre'];$apellido= $consul ['apellido'];$edad= $consul ['edad']; echo '<SCRIPTLANGUAGE="javascript">location.href="modificar2.php?&cedula='.$cedula.'&nombre='.$nombre. '&apellido='.$apellido.'&edad='.$edad."' ;</SCRIPT>';}?>
Sí, para actualizar la tabla tendrás que utilizar un update
UPDATE nombreDeTuTabla
SET nombreColumna=valor1, nombreColumna2=valor2,...
WHERE nombreColumnaX=valor
Por ejemplo:
UPDATE tabla1
SET nombre='Antonio', apellido='Suarez'
WHERE cedula=778
En tu caso tendrás que utilizar variables:
<?php$cedula=$_POST['cedula'];$nombre=$_POST['nombre'];$apellido=$_POST['apellido'];$base="basedatos";$server="localhost"; $user="root";$clave=" ";$resul=mysql_connect($server,$user,$clave);mysql_select_db($base);$cedula=$_POST['cedula'];$sql="UPDATE tabla1 SET nombre=".$nombre.", apellido=".$apellido." WHERE cedula = '".$cedula."'";...?>