Problemas al conectar pagina php con base de datos en phpmyadmin

  • Autor Autor Luis Martin
  • Fecha de inicio Fecha de inicio
Luis Martin

Luis Martin

1
Lambda
Verificado
Verificación en dos pasos activada
Verificado por Whatsapp
¡Ha verificado su Paypal!
Verificado por Binance
Suscripción a IA
Hola, tengo dias en este proyecto pero no he conseguido solucion, intento crear una base de datos para mi negocio desde un servidor local con wampserver, y lo que he intentado es crear una pagina php, donde muestre los clientes registrados y en otra, mediante un formulario, poder ingresar nuevos clientes, pero no me funciona, a continuacion muestro los codigos utilizados:

Pagina para conectar con phpmyadmin: base.php
Insertar CODE, HTML o PHP:
<?php 
$host = "localhost";
$user = "root";
$pw= "";
$bd = "centro_optico_mm";

$link = mysql_connect($host,$user,$pw);
mysql_select_db($bd,$link);

?>

Pagina de formulario para ingresar nuevos registros a la base de datos: nuevo.php
Insertar CODE, HTML o PHP:
<html>

<body>
<form method="post" action="add_reg.php">
Nombre: <input type="text" name="Nombre"><p>
Apellido: <input type="text" name="Apellido"><p>
Telefono <input type="text" name="Telefono"><p>
<br>
<a>Correccion:</a>
<br>
O.D: <input type="text" name="O.D"> Cil: <input type="text" name="CilDerecho"> Eje: <input type="text" name="EjeDerecho"> Add: <input type="text" name="AddDerecho"><p>
O.I: <input type="text" name="O.I"> Cil: <input type="text" name="CilIzquierdo"> Eje: <input type="text" name="EjeIzquierdo"> Add: <input type="text" name="AddIzquierdo"><p><p>
Tipo: <input type="text" name="Tipo"><p>
<input type="submit" name="enviar" value="enviar">
</form>

</body>

</html>

Pagina para procesar el formulario: add_reg.php
Insertar CODE, HTML o PHP:
<?php

include("base.php");
	if(1==1) 
	
	{
		$con = mysql_connect($host,$user,$pw)
		or die("problemas al conectar al servidor");
		
		mysql_select_db($bd,$con)
		or die("problemas al conectar a la base de datos");
		
		mysql_query("INSERT INTO cliente (Nombre,Apellido,Telefono,OD,CilDerecho,EjeDerecho,AddDerecho,OI,CilIzquierdo,EjeIzquierdo,AddIzquierdo,Tipo) 
	values ('$_POST[Nombre]','$_POST[Apellido]','$_POST[Telefono]','$_POST[OD]','$_POST[CilDerecho]','$_POST[EjeDerecho]','$_POST[AddDerecho]','$_POST[OI]','$_POST[CilIzquierdo]','$_POST[EjeIzquierdo]','$_POST[AddIzquierdo]','$_POST[Tipo]'",$con);
	
	}
	else {
		echo "Ocurrió un error";
	}
?>

y por ultimo, la pagina donde muestro todos los registros en la base de datos:
Insertar CODE, HTML o PHP:
<html>
<head><title>Listado completo de Registros</title>
<link rel="stylesheet" type="text/css" href="tabla.css"/>
</head>
<body>
<div class="datagrid">
<?php
$sql = "SELECT * FROM cliente ORDER BY Nombre";
include ("base.php"); 

$result = mysql_query($sql) or die (mysql_error());
if ($row = mysql_fetch_array($result))
{
echo "<table border = '1' width='50%'>";
mysql_field_seek($result,0); //
while ($field = mysql_fetch_field($result)){ 
}

echo "<thead> \n";
echo '<tr>';
echo '<th width="5%">'."ID".'</th>';
echo '<th width="15%">'."Nombre".'</th>';
echo '<th width="15%">'."Apellido".'</th>';
echo '<th width="15%">'."Telefono".'</th>';
echo '<th width="15%">'."OD".'</th>';
echo '<th width="15%">'."CilDerecho".'</th>';
echo '<th width="15%">'."EjeDerecho".'</th>';
echo '<th width="15%">'."AddDerecho".'</th>';
echo '<th width="15%">'."OI".'</th>';
echo '<th width="15%">'."CilIzquierdo".'</th>';
echo '<th width="15%">'."EjeIzquierdo".'</th>';
echo '<th width="15%">'."AddIzquierdo".'</th>';
echo '<th width="15%">'."Tipo".'</th>';
echo '<th width="15%">'."Modificar".'</th>';
echo '<th width="15%">'."Borrar".'</th>';
echo '</tr>';
echo '</tr>';
echo "</thead> \n";
do {
echo '<tr>';
echo "<td width='5%'>".$row["Nombre"]."</td> \n";
echo "<td>".$row["Nombre"]."</td> \n";
echo "<td>".$row["Apellido"]."</td> \n";
echo "<td>".$row["Telefono"]."</td> \n";
echo "<td>".$row["OD"]."</td> \n";
echo "<td>".$row["CilDerecho"]."</td> \n";
echo "<td>".$row["EjeDerecho"]."</td> \n";
echo "<td>".$row["AddDerecho"]."</td> \n";
echo "<td>".$row["OI"]."</td> \n";
echo "<td>".$row["CilIzquierdo"]."</td> \n";
echo "<td>".$row["EjeIzquierdo"]."</td> \n";
echo "<td>".$row["AddIzquierdo"]."</td> \n";
echo "<td>".$row["Tipo"]."</td> \n";
echo "</tr>";
}

while ($row = mysql_fetch_array($result));
echo "</table>";
echo '<p><a href="index.html">Volver</a></p>';
} else
{
echo "<p>No se ha encontrado ning&uacute;n registro</p>";
echo '<p><a href="index.html">Volver</a></p>';
}
?>
</div>
</body>
</html>

Problemas:

1.Al ir a nuevo.php y rellenar el formulario, doy enviar y me envia a add_reg.php, donde salen los siguientes mensajes:
( ! ) Notice: Undefined index: OD in C:\wamp\www\Centro Optico MM\add_reg.php on line 14
Call Stack
# Time Memory Function Location
1 0.0265 147224 {main}( ) ..\add_reg.php:0

( ! ) Notice: Undefined index: OI in C:\wamp\www\Centro Optico MM\add_reg.php on line 14
Call Stack
# Time Memory Function Location
1 0.0265 147224 {main}( ) ..\add_reg.php:0

Por lo cual no se envian los nuevos registros.


Cabe destacar: que esta es la base de datos en phpmyadmin:

Dibujo11.webp
Dibujo22.webp

Ademas procedo a subir todos los archivos, incluyendo la base de datos:
Enlace Dropbox


Si alguien me ayuda lo agradeceria muchisimo :encouragement:
 
En el formulario tienes "O.D" y "O.I" ( con punto)
Y en add_reg.php tienes "OD" y "OI" ( sin punto)

¿ no será eso?
 
En el formulario tienes "O.D" y "O.I" ( con punto)
Y en add_reg.php tienes "OD" y "OI" ( sin punto)

¿ no será eso?

Ya lo modifique y sale el mismo error igual :S
 
[MENTION=48300]Martmen[/MENTION] Mantenga el cambio que mencionó piano y cambie en add_reg.php :

PHP:
<?php

include("base.php");
	$Nombre = $_REQUEST['Nombre'];
	$Apellido = $_REQUEST['Apellido'];
	$Telefono = $_REQUEST['Telefono'];
	$OD = $_REQUEST['OD'];
	$CilDerecho = $_REQUEST['CilDerecho'];
	$EjeDerecho = $_REQUEST['EjeDerecho'];
	$AddDerecho = $_REQUEST['AddDerecho'];
	$OI = $_REQUEST['OI'];
	$CilIzquierdo = $_REQUEST['CilIzquierdo'];
	$EjeIzquierdo = $_REQUEST['EjeIzquierdo'];
	$AddIzquierdo = $_REQUEST['AddIzquierdo'];
	$Tipo = $_REQUEST['Tipo'];

	$con = mysql_connect($host,$user,$pw)
	or die("problemas al conectar al servidor");
	
	mysql_select_db($bd,$con)
	or die("problemas al conectar a la base de datos");
	
	$insert = mysql_query("INSERT INTO cliente (Nombre,Apellido,Telefono,OD,CilDerecho,EjeDerecho,AddDerecho,OI,CilIzquierdo,EjeIzquierdo,AddIzquierdo,Tipo) 
	values ('$Nombre','$Apellido','$Telefono','$OD','$CilDerecho','$EjeDerecho','$AddDerecho','$OI','$CilIzquierdo','$EjeIzquierdo','$AddIzquierdo','$Tipo')");
	
	if(!$insert){
		die("Error: ".mysql_error());
	}

	echo "Ha registrado al usuario $Nombre.";
	
?>
 
[MENTION=48300]Martmen[/MENTION] Mantenga el cambio que mencionó piano y cambie en add_reg.php :

PHP:
<?php

include("base.php");
	$Nombre = $_REQUEST['Nombre'];
	$Apellido = $_REQUEST['Apellido'];
	$Telefono = $_REQUEST['Telefono'];
	$OD = $_REQUEST['OD'];
	$CilDerecho = $_REQUEST['CilDerecho'];
	$EjeDerecho = $_REQUEST['EjeDerecho'];
	$AddDerecho = $_REQUEST['AddDerecho'];
	$OI = $_REQUEST['OI'];
	$CilIzquierdo = $_REQUEST['CilIzquierdo'];
	$EjeIzquierdo = $_REQUEST['EjeIzquierdo'];
	$AddIzquierdo = $_REQUEST['AddIzquierdo'];
	$Tipo = $_REQUEST['Tipo'];

	$con = mysql_connect($host,$user,$pw)
	or die("problemas al conectar al servidor");
	
	mysql_select_db($bd,$con)
	or die("problemas al conectar a la base de datos");
	
	$insert = mysql_query("INSERT INTO cliente (Nombre,Apellido,Telefono,OD,CilDerecho,EjeDerecho,AddDerecho,OI,CilIzquierdo,EjeIzquierdo,AddIzquierdo,Tipo) 
	values ('$Nombre','$Apellido','$Telefono','$OD','$CilDerecho','$EjeDerecho','$AddDerecho','$OI','$CilIzquierdo','$EjeIzquierdo','$AddIzquierdo','$Tipo')");
	
	if(!$insert){
		die("Error: ".mysql_error());
	}

	echo "Ha registrado al usuario $Nombre.";
	
?>

Muchas gracias Hermano esa era la solucion. Pero me surgio otro problema, me podrias ayudar?

He agregado un buscador y la opcion de modificar y borrar los clientes, los codigos que he realizado son estos:

Buscador:
Insertar CODE, HTML o PHP:
<form method="POST" action="buscador.php">
<strong>Ingrese Nombre de la Persona a Buscar:</strong> <input type="text" name="buscar" size="20"><br><br> <input type="submit" value="Buscar"> 
</form>

Pagina buscador.php
Insertar CODE, HTML o PHP:
<html>
<head><title>Busqueda de registro</title>
<link rel="stylesheet" type="text/css" href="tabla.css"/>
</head>
<body>
<div class="datagrid">
<?php
$buscar = $_POST['buscar']; 
$sql = "SELECT * FROM cliente WHERE Nombre LIKE '%".$buscar."%' ORDER BY Nombre"; 
include ("base.php");
$result = mysql_query($sql) or die (mysql_error());
if (!isset($buscar)){
echo 'Debe especificar una cadena a buscar';
echo '<p><a href="../Centro Optico MM/">Volver</a></p>';
echo '</html></body>';
exit;
}
if ($row = mysql_fetch_array($result)){
echo "<table border = '1' width='50%'>";
mysql_field_seek($result,0);
while ($field = mysql_fetch_field($result)){
}
echo "<thead> \n";
echo '<tr>';
echo '<th width="15%">'."Nombre".'</th>';
echo '<th width="15%">'."Apellido".'</th>';
echo '<th width="15%">'."Telefono".'</th>';
echo '<th width="15%">'."OD".'</th>';
echo '<th width="15%">'."CilDerecho".'</th>';
echo '<th width="15%">'."EjeDerecho".'</th>';
echo '<th width="15%">'."AddDerecho".'</th>';
echo '<th width="15%">'."OI".'</th>';
echo '<th width="15%">'."CilIzquierdo".'</th>';
echo '<th width="15%">'."EjeIzquierdo".'</th>';
echo '<th width="15%">'."AddIzquierdo".'</th>';
echo '<th width="15%">'."Tipo".'</th>';
echo '<th width="15%">'."Modificar".'</th>';
echo '<th width="15%">'."Borrar".'</th>';
echo '</tr>';
echo '</tr>';
echo "</thead> \n";
do {
echo '<tr>';
echo "<td>".$row["Nombre"]."</td> \n";
echo "<td>".$row["Apellido"]."</td> \n";
echo "<td>".$row["Telefono"]."</td> \n";
echo "<td>".$row["OD"]."</td> \n";
echo "<td>".$row["CilDerecho"]."</td> \n";
echo "<td>".$row["EjeDerecho"]."</td> \n";
echo "<td>".$row["AddDerecho"]."</td> \n";
echo "<td>".$row["OI"]."</td> \n";
echo "<td>".$row["CilIzquierdo"]."</td> \n";
echo "<td>".$row["EjeIzquierdo"]."</td> \n";
echo "<td>".$row["AddIzquierdo"]."</td> \n";
echo "<td>".$row["Tipo"]."</td> \n";
echo "<td>".'[<a href="../Centro Optico MM/modificar.php?id='.$row["Nombre"].'">Modificar</a>]'."</td> \n";
echo "<td>".'[<a href="../Centro Optico MM/borrar.php?id='.$row["Nombre"].'">Borrar</a>]'."</td> \n";
echo "</tr>";
}
 while ($row = mysql_fetch_array($result));
echo "</table>";
echo '<p><a href="../Centro Optico MM/">Volver</a></p>';
} else {
echo "<p>No se ha encontrado ning&uacute;n registro</p>";
echo '<p><a href="../Centro Optico MM/">Volver</a></p>';
}
?>
</div>
</body>
</html>

Hasta el momento todo funciona perfectamente, pero al momento de modificar o borrar ocurre el problema:

Pagina
Insertar CODE, HTML o PHP:
<html>
<body>
<?php
$sql = "SELECT * FROM cliente WHERE Nombre=".$_REQUEST['id'];
//echo $sql;
include ("base.php");
$result = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($result);
?>
<form method="post" action="../Centro Optico MM/modif.php">
Nombre: <input type="text" name="Nombre" value="<?php echo $row['Nombre']; ?>"><p>
Apellido: <input type="text" name="Apellido" value="<?php echo $row['Apellido']; ?>"><p>
Telefono <input type="text" name="Telefono" value="<?php echo $row['Telefono']; ?>"><p>
<br>
<a>Correccion:</a>
<br>
O.D: <input type="text" name="O.D" value="<?php echo $row['OD']; ?>"> Cil: <input type="text" name="CilDerecho" value="<?php echo $row['CilDerecho']; ?>"> Eje: <input type="text" name="EjeDerecho" value="<?php echo $row['EjeDerecho']; ?>"> Add: <input type="text" name="AddDerecho" value="<?php echo $row['AddDerecho']; ?>"><p>
O.I: <input type="text" name="O.I" value="<?php echo $row['OI']; ?>"> Cil: <input type="text" name="CilIzquierdo" value="<?php echo $row['CilIzquierdo']; ?>"> Eje: <input type="text" name="EjeIzquierdo" value="<?php echo $row['EjeIzquierdo']; ?>"> Add: <input type="text" name="AddIzquierdo" value="<?php echo $row['AddIzquierdo']; ?>"><p><p>
Tipo: <input type="text" name="Tipo" value="<?php echo $row['Tipo']; ?>"><p>
<input type="hidden" name ="id" value="<?php echo $_REQUEST['id'];?>">
<input type="Submit" name="modificar" value="Modificar">
</form>
</body>
</html>

Pagina modif.php
Insertar CODE, HTML o PHP:
<?php 
include ("base.php"); 
$Nombre=$_POST["Nombre"]; 
$apellido=$_POST["Apellido"]; 
$Telefono=$_POST["Telefono"];
$OD=$_POST["OD"];
$CilDerecho=$_POST["CilDerecho"];
$EjeDerecho=$_POST["EjeDerecho"];
$AddDerecho=$_POST["AddDerecho"];
$OI=$_POST["OI"];
$CilIzquierdo=$_POST["CilIzquierdo"];
$EjeIzquierdo=$_POST["EjeIzquierdo"];
$AddIzquierdo=$_POST["AddIzquierdo"];
$Tipo=$_POST["Tipo"];
$id=$_POST["id"];
$up = "update cliente set Nombre ='$Nombre', Apellido='$Apellido', Telefono='$Telefono', OD='$OD', CilDerecho='$CilDerecho', EjeDerecho='$EjeDerecho', AddDerecho='$AddDerecho', OI='$OI', CilIzquierdo='$CilIzquierdo', EjeIzquierdo='$EjeIzquierdo', AddIzquierdo='$AddIzquierdo', Tipo='$Tipo', where id_contacto=$id"; 
if (mysql_query ($up, $link)) 
{
echo "La Modificacion se ha realizado con exito!!!!";
}
Else 
{
echo mysql_error($link);
exit;
echo "Error en la actualizacion!!!!";
}
mysql_close();?>

Pagina borrar.php:
Insertar CODE, HTML o PHP:
<html>
<body>
<?php
$sql = "SELECT * FROM cliente WHERE Nombre=".$_REQUEST['id'];
//echo $sql;
include ("base.php");
$result = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($result);
?>
<form method="post" action="../Centro Optico MM/borra.php">
Nombre: <input type="text" name="Nombre" value="<?php echo $row['Nombre']; ?>"><p>
Apellido: <input type="text" name="Apellido" value="<?php echo $row['Apellido']; ?>"><p>
Telefono <input type="text" name="Telefono" value="<?php echo $row['Telefono']; ?>"><p>
<br>
<a>Correccion:</a>
<br>
O.D: <input type="text" name="O.D" value="<?php echo $row['OD']; ?>"> Cil: <input type="text" name="CilDerecho" value="<?php echo $row['CilDerecho']; ?>"> Eje: <input type="text" name="EjeDerecho" value="<?php echo $row['EjeDerecho']; ?>"> Add: <input type="text" name="AddDerecho" value="<?php echo $row['AddDerecho']; ?>"><p>
O.I: <input type="text" name="O.I" value="<?php echo $row['OI']; ?>"> Cil: <input type="text" name="CilIzquierdo" value="<?php echo $row['CilIzquierdo']; ?>"> Eje: <input type="text" name="EjeIzquierdo" value="<?php echo $row['EjeIzquierdo']; ?>"> Add: <input type="text" name="AddIzquierdo" value="<?php echo $row['AddIzquierdo']; ?>"><p><p>
Tipo: <input type="text" name="Tipo" value="<?php echo $row['Tipo']; ?>"><p>
<input type="hidden" name ="id" value="<?php echo $_REQUEST['id'];?>">
<input type="Submit" name="eliminar" value="Eliminar">
<input type="Submit" name="cancelar" value="Cancelar" onClick="../Centro Optico MM/index.html">
</form>
</body>
</html>

Pagina borra.php:
Insertar CODE, HTML o PHP:
<?php
include ("base.php");
$Nombre=$_POST["Nombre"]; 
$apellido=$_POST["Apellido"]; 
$Telefono=$_POST["Telefono"];
$OD=$_POST["OD"];
$CilDerecho=$_POST["CilDerecho"];
$EjeDerecho=$_POST["EjeDerecho"];
$AddDerecho=$_POST["AddDerecho"];
$OI=$_POST["OI"];
$CilIzquierdo=$_POST["CilIzquierdo"];
$EjeIzquierdo=$_POST["EjeIzquierdo"];
$AddIzquierdo=$_POST["AddIzquierdo"];
$Tipo=$_POST["Tipo"];
$id=$_POST["id"];
$up = "delete from agenda where id_contacto=$id";
if (mysql_query ($up, $link))
{
echo "El registro ha sido borrado satisfactoriamente.";
}
else
{
echo mysql_error($link);
exit;
}
mysql_close();
?>
<a href="../Centro Optico MM/index.html">Volver</a>


Cuando por ejemplo eligo un cliente llamado "Antonio" y le doy modificar me sale el siguiente error en la pagina /modificar.php?id=Antonio:
Unknown column 'Antonio' in 'where clause'

O si le doy borrar me sale el siguiente error en la pagina /borrar.php?id=Antonio:
Unknown column 'Antonio' in 'where clause'

Alguna solucion para esto?
 
[MENTION=48300]Martmen[/MENTION]

borrar.php
PHP:
<?php
	include ('base.php');
	$Nombre=$_POST["Nombre"]; 
	$apellido=$_POST["Apellido"]; 
	$Telefono=$_POST["Telefono"];
	$OD=$_POST["OD"];
	$CilDerecho=$_POST["CilDerecho"];
	$EjeDerecho=$_POST["EjeDerecho"];
	$AddDerecho=$_POST["AddDerecho"];
	$OI=$_POST["OI"];
	$CilIzquierdo=$_POST["CilIzquierdo"];
	$EjeIzquierdo=$_POST["EjeIzquierdo"];
	$AddIzquierdo=$_POST["AddIzquierdo"];
	$Tipo=$_POST["Tipo"];
	$id=$_POST["id"];
	$up = "DELETE FROM cliente WHERE Nombre='".$id."'";
	if (mysql_query ($up, $link))
		echo "El registro ha sido borrado satisfactoriamente.";
	else
		echo mysql_error($link);
	exit;
	
	mysql_close();
?>
<a href="index.html">Volver</a>

borrar.php
PHP:
<html>
<body>
<?php
require_once('base.php');
$s = $_REQUEST['id'];
$sql = "SELECT * FROM cliente WHERE Nombre='$s'";
//echo $sql;
include ("base.php");
$result = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($result);
?>
<form method="post" action="borra.php">
Nombre: <input type="text" name="Nombre" value="<?php echo $row['Nombre']; ?>"><p>
Apellido: <input type="text" name="Apellido" value="<?php echo $row['Apellido']; ?>"><p>
Telefono <input type="text" name="Telefono" value="<?php echo $row['Telefono']; ?>"><p>
<br>
<a>Correccion:</a>
<br>
O.D: <input type="text" name="OD" value="<?php echo $row['OD']; ?>"> Cil: <input type="text" name="CilDerecho" value="<?php echo $row['CilDerecho']; ?>"> Eje: <input type="text" name="EjeDerecho" value="<?php echo $row['EjeDerecho']; ?>"> Add: <input type="text" name="AddDerecho" value="<?php echo $row['AddDerecho']; ?>"><p>
O.I: <input type="text" name="OI" value="<?php echo $row['OI']; ?>"> Cil: <input type="text" name="CilIzquierdo" value="<?php echo $row['CilIzquierdo']; ?>"> Eje: <input type="text" name="EjeIzquierdo" value="<?php echo $row['EjeIzquierdo']; ?>"> Add: <input type="text" name="AddIzquierdo" value="<?php echo $row['AddIzquierdo']; ?>"><p><p>
Tipo: <input type="text" name="Tipo" value="<?php echo $row['Tipo']; ?>"><p>
<input type="hidden" name ="id" value="<?php echo $s;?>">
<input type="Submit" name="eliminar" value="Eliminar">
<input type="Submit" name="cancelar" value="Cancelar" onClick="../Centro Optico MM/index.html">
</form>
</body>
</html>

Ahi le queda un detallito en modificar que eso si no lo toque. Prueba, creo que solo fueron estos dos archivos los que modifiqué.
 
[MENTION=48300]Martmen[/MENTION]

borrar.php
PHP:
<?php
	include ('base.php');
	$Nombre=$_POST["Nombre"]; 
	$apellido=$_POST["Apellido"]; 
	$Telefono=$_POST["Telefono"];
	$OD=$_POST["OD"];
	$CilDerecho=$_POST["CilDerecho"];
	$EjeDerecho=$_POST["EjeDerecho"];
	$AddDerecho=$_POST["AddDerecho"];
	$OI=$_POST["OI"];
	$CilIzquierdo=$_POST["CilIzquierdo"];
	$EjeIzquierdo=$_POST["EjeIzquierdo"];
	$AddIzquierdo=$_POST["AddIzquierdo"];
	$Tipo=$_POST["Tipo"];
	$id=$_POST["id"];
	$up = "DELETE FROM cliente WHERE Nombre='".$id."'";
	if (mysql_query ($up, $link))
		echo "El registro ha sido borrado satisfactoriamente.";
	else
		echo mysql_error($link);
	exit;
	
	mysql_close();
?>
<a href="index.html">Volver</a>

borrar.php
PHP:
<html>
<body>
<?php
require_once('base.php');
$s = $_REQUEST['id'];
$sql = "SELECT * FROM cliente WHERE Nombre='$s'";
//echo $sql;
include ("base.php");
$result = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($result);
?>
<form method="post" action="http://forobeta.com/borra.php">
Nombre: <input type="text" name="Nombre" value="<?php echo $row['Nombre']; ?>"><p>
Apellido: <input type="text" name="Apellido" value="<?php echo $row['Apellido']; ?>"><p>
Telefono <input type="text" name="Telefono" value="<?php echo $row['Telefono']; ?>"><p>
<br>
<a>Correccion:</a>
<br>
O.D: <input type="text" name="OD" value="<?php echo $row['OD']; ?>"> Cil: <input type="text" name="CilDerecho" value="<?php echo $row['CilDerecho']; ?>"> Eje: <input type="text" name="EjeDerecho" value="<?php echo $row['EjeDerecho']; ?>"> Add: <input type="text" name="AddDerecho" value="<?php echo $row['AddDerecho']; ?>"><p>
O.I: <input type="text" name="OI" value="<?php echo $row['OI']; ?>"> Cil: <input type="text" name="CilIzquierdo" value="<?php echo $row['CilIzquierdo']; ?>"> Eje: <input type="text" name="EjeIzquierdo" value="<?php echo $row['EjeIzquierdo']; ?>"> Add: <input type="text" name="AddIzquierdo" value="<?php echo $row['AddIzquierdo']; ?>"><p><p>
Tipo: <input type="text" name="Tipo" value="<?php echo $row['Tipo']; ?>"><p>
<input type="hidden" name ="id" value="<?php echo $s;?>">
<input type="Submit" name="eliminar" value="Eliminar">
<input type="Submit" name="cancelar" value="Cancelar" onClick="../Centro Optico MM/index.html">
</form>
</body>
</html>

Ahi le queda un detallito en modificar que eso si no lo toque. Prueba, creo que solo fueron estos dos archivos los que modifiqué.

Amigo muchas gracias esa era la solucion 😀

Trabaje un poco en la opcion de modificar y asi me quedaron los codigos:
modificar.php
Insertar CODE, HTML o PHP:
<?php
require_once('base.php');
$s = $_REQUEST['id'];
$sql = "SELECT * FROM cliente WHERE Nombre='$s'";
//echo $sql;
include ("base.php");
$result = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($result);
?>
<form method="post" action="modif.php">
Nombre: <input type="text" name="Nombre" value="<?php echo $row['Nombre']; ?>"><p>
Apellido: <input type="text" name="Apellido" value="<?php echo $row['Apellido']; ?>"><p>
Telefono <input type="text" name="Telefono" value="<?php echo $row['Telefono']; ?>"><p>
<br>
<a>Correccion:</a>
<br>
O.D: <input type="text" name="OD" value="<?php echo $row['OD']; ?>"> Cil: <input type="text" name="CilDerecho" value="<?php echo $row['CilDerecho']; ?>"> Eje: <input type="text" name="EjeDerecho" value="<?php echo $row['EjeDerecho']; ?>"> Add: <input type="text" name="AddDerecho" value="<?php echo $row['AddDerecho']; ?>"><p>
O.I: <input type="text" name="OI" value="<?php echo $row['OI']; ?>"> Cil: <input type="text" name="CilIzquierdo" value="<?php echo $row['CilIzquierdo']; ?>"> Eje: <input type="text" name="EjeIzquierdo" value="<?php echo $row['EjeIzquierdo']; ?>"> Add: <input type="text" name="AddIzquierdo" value="<?php echo $row['AddIzquierdo']; ?>"><p><p>
Tipo: <input type="text" name="Tipo" value="<?php echo $row['Tipo']; ?>"><p>
<input type="hidden" name ="id" value="<?php echo $s;?>">
<input type="Submit" name="modificar" value="Modificar">
<input type="Submit" name="cancelar" value="Cancelar" onClick="../Centro Optico MM/index.html">
</form>
</body>
</html>

modif.php
Insertar CODE, HTML o PHP:
<?php
    include ('base.php');
    $Nombre=$_POST["Nombre"]; 
    $apellido=$_POST["Apellido"]; 
    $Telefono=$_POST["Telefono"];
    $OD=$_POST["OD"];
    $CilDerecho=$_POST["CilDerecho"];
    $EjeDerecho=$_POST["EjeDerecho"];
    $AddDerecho=$_POST["AddDerecho"];
    $OI=$_POST["OI"];
    $CilIzquierdo=$_POST["CilIzquierdo"];
    $EjeIzquierdo=$_POST["EjeIzquierdo"];
    $AddIzquierdo=$_POST["AddIzquierdo"];
    $Tipo=$_POST["Tipo"];
    $id=$_POST["id"];
	$up = "update cliente set Nombre='".$id."'";
    if (mysql_query ($up, $link))
        echo "La Modificacion se ha realizado con exito!!!!"."<br/>"."<a href='../Centro Optico MM/'>Volver</a>";
    else
        echo mysql_error($link);
    exit;
    
    mysql_close();
?>
<a href="../Centro Optico MM/">Volver</a>

Ahora no sale el error e incluso dice que la modificacion fue correcta, pero cuando reviso el registro en la lista no se modifico, creo que el error esta en modif.php en esta linea:
$up = "update cliente set Nombre='".$id."'";

Que piensas amigo?
 
Cambia esa línea por esto:
PHP:
$up = "update cliente set Nombre='".$Nombre."', 
	Apellido='".$apellido."', 
	Telefono='".$Telefono."', 
	OD='".$OD."', 
	CilDerecho='".$CilDerecho."', 
	EjeDerecho='".$EjeDerecho."', 
	AddDerecho='".$AddDerecho."',
	OI='".$OI."',
	CilIzquierdo='".$CilIzquierdo."',
	EjeIzquierdo='".$EjeIzquierdo."',
	AddIzquierdo='".$AddIzquierdo."',
	Tipo='".$Tipo."' 
	WHERE id = ".$id.";";
 
Última edición:
Atrás
Arriba