0% found this document useful (0 votes)
36 views4 pages

Base de Datos en Phpmyadmin: Programación Dinámica-Conexión A Bases de Datos Preparado Por Ingº Douglas Galvis

This document discusses connecting a PHP application to a MySQL database. It includes code to connect to the "suramerica" database, insert form data into the "contactos" table, and query data from two tables joined on a common "cedula" field. Forms are created to collect and display user, contact, and loan data between the application and database.

Uploaded by

Xury Saez Mejias
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views4 pages

Base de Datos en Phpmyadmin: Programación Dinámica-Conexión A Bases de Datos Preparado Por Ingº Douglas Galvis

This document discusses connecting a PHP application to a MySQL database. It includes code to connect to the "suramerica" database, insert form data into the "contactos" table, and query data from two tables joined on a common "cedula" field. Forms are created to collect and display user, contact, and loan data between the application and database.

Uploaded by

Xury Saez Mejias
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Programación Dinámica- conexión a Bases de datos 1

Preparado por Ingº Douglas Galvis

Dentro de la carpeta www del wampserver crear otra carpeta llamada site

site

adodb

connection

connection.php
Modulo

archivos.htm

archivos.php

Base de Datos en PhpMyadmin

Base de Datos: suramerica


Tabla contactos(user,cedula,nombre,apellido)
Tabla prestamos(user,cedula,status,libroPrestado)

Archivo connection.php

<?php

include('../adodb/adodb.inc.php');
$db = NewADOConnection('mysql');
$db->Connect("127.0.0.1","root","","suramerica");
?>

Archivo formulario.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
Programación Dinámica- conexión a Bases de datos 2
Preparado por Ingº Douglas Galvis

d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0


var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2];
val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail
address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number
between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>

<body>
<div align="center">
<p><strong>Registro de Clientes
</strong></p>
<form action="./formulario1.php" method="post" name="form1"
onSubmit="MM_validateForm('cedula1','','NisNum');return
document.MM_returnValue">
<table width="305" border="1" bgcolor="#CCCCCC">
<tr>
<td width="105"><div
align="right"><strong>Usuario:</strong></div></td>
<td width="184"><div align="left">
<input name="usuario" type="text" id="usuario" size="12"
maxlength="10">
</div></td>
</tr>
<tr>
<td><div align="right"><strong>Cedula:</strong></div></td>
Programación Dinámica- conexión a Bases de datos 3
Preparado por Ingº Douglas Galvis

<td><div align="left">
<input name="cedula1" type="text" id="cedula1" size="12"
maxlength="8">
</div></td>
</tr>
<tr>
<td><div align="right"><strong>Nombres:</strong></div></td>
<td> <input name="nombres" type="text" id="nombres"
size="30" maxlength="25"> </td>
</tr>
<tr>
<td><div align="right"><strong>Apellidos:</strong></div></td>
<td> <input name="apellidos" type="text" id="apellidos"
size="30" maxlength="25"> </td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="reset" name="Submit2" value="Borrar">
<input type="submit" name="Submit" value="Enviar">
</div></td>
</tr>
</table>
</form>
<p><strong>
</strong></p>
</div>
</body>
</html>

Archivo formulario.php<?php

include("../connection/connection.php");
$sql="INSERT INTO contactos(user,cedula,nombre,apellido) VALUES ('".
$_POST["usuario"]."',".$_POST["cedula1"].",'".$_POST["nombres"]."','".
$_POST["apellidos"]."')";
$rs=$db->Execute($sql) OR die($db->ErrorMsg());
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../style/style.css" rel="stylesheet" type="text/css">
</head>

<body>
Programación Dinámica- conexión a Bases de datos 4
Preparado por Ingº Douglas Galvis

<?php
echo "<p class='labelForm'>Datos Registrados satisfactoriamente </p>";
?>
</body>
</html>

Archivo que permite consultar 2 tablas con un campo en común

<?php
include('../adodb/adodb.inc.php');
$DB = NewADOConnection('mysql');
$DB->Connect("127.0.0.1", "root", "", "suramerica");

$rs = $DB->Execute("select * from contactos,prestamos WHERE


contactos.cedula=prestamos.cedula");
?>
<table width="85%" border="1" align="center">
<tr bgcolor="#0000FF" class="labelForm">
<td width="7%"><span class="Estilo3">Usuario</span></td>
<td width="15%"><span class="Estilo3">cedula</span></td>
<td width="41%"><span class="Estilo3">Nombre</span></td>
<td width="12%"><span class="Estilo3">Apellido</span></td>
<td width="12%"><span class="Estilo3">Status</span></td>

</tr>
<?php while (!$rs->EOF ) { ?>
<tr>
<td><?php echo $rs->fields["user"]; ?></td>
<td><?php echo $rs->fields["cedula"]; ?></td>
<td><?php echo $rs->fields["nombre"]; ?></td>
<td><?php echo $rs->fields["apellido"]; ?></td>
<td><?php echo $rs->fields["status"]; ?></td>

</tr>
<?php
$rs->MoveNext();
}
?>
</table>

You might also like