Professional Documents
Culture Documents
Ejecutar un Update
<html><head><title>MySQL Query in PHP</title></head>
<body bgcolor="lightblue">
<font size='+1' face='arial'>
<?php
print "Opening the connection to the database server<br>";
$link = mysql_connect("localhost", "root", "");
print "Selecting the 'northwind' database<br>";
mysql_select_db("northwind");
$query="UPDATE Shippers SET phone='(777) 430-2346'
WHERE CompanyName = 'Federal Shipping'";
$result= mysql_query($query);
$rows_affected=mysql_affected_rows($link); /* numbers of rows
affected by the most recently executed query */
echo "You have updated $rows_affected rows.<br>";
Programacin II Unidad 8 Bases de Datos - Pgina N: 194
if ($result){
print "Query successful!<br>";
}
else{
die("Query failed.". mysql_error());
}
print "Closing the connection<br>";
mysql_close( $link );
?>
</body>
</html>
Recuperar registros
<html><head><title>MySQL Fetch a Row</title></head>
<body bgcolor="lightblue">
<font size='+1' face='arial'>
<?php
print "Opening the connection to the database server<br>";
$link = mysql_connect("localhost", "root", "");
print "Selecting the 'northwind' database<br>";
mysql_select_db("northwind");
$query="SELECT CompanyName, Phone from Shippers";
$result_set= mysql_query($query);
if ($result_set){
print "Fetch the first row of data.<br>";
$record= mysql_fetch_row($result_set);
// print_r($record);
foreach ($record as $value){
print "<em>$value </em>"; // print the row
}
print "<br>";
}
else{ die("Query failed.". mysql_error());
}
print "Closing the connection<br>";
mysql_close( $link );
?>
Programacin II Unidad 8 Bases de Datos - Pgina N: 195
</body>
</html>
Cantidad de registros
<?php
mysql_connect("localhost", "root", "");
mysql_select_db( "northwind" );
print "Executing SQL...<br>";
$result_set = mysql_query( "SELECT ShipName FROM orders");
$num_rows = mysql_num_rows( $result_set );
print "<b>There are a total of $num_rows ship names
in the \"orders\" table.";
?>
Galera de Arte
Programacin II Unidad 8 Bases de Datos - Pgina N: 196
contact_us.php
<?php
extract($_REQUEST);
if( isset($submit) ) {
$status = "";
$success = true;
$message = "";
foreach( $_REQUEST as $key=>$value ) {
if( $value=="" ) {
$status .= "Please enter your $key.<br>";
$success = false;
}
$message .= "$key\t=\t$value\r\n";
}
if ( $success ) {
mail("manager@thecanvasgallery.com", "Request for contact", $message, "From: $email" );
}
}
?>
<html>
<body>
<h1>Request for contact</h1>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="get">
<table>
<? if( !$success ) { ?>
<tr><td colspan="2"><font color="red"><?=$status?><br></font></td></tr>
<? } else { ?>
<tr><td colspan="2"><font color="blue">Your message has been sent. Thank you!<br></font></td></tr>
<? } ?>
<tr><td>Name</td><td><input type="text" name="name"/></td></tr>
<tr><td>Email</td><td><input type="text" name="email"/></td></tr>
<tr><td>Phone</td><td><input type="text" name="phone"/></td></tr>
<tr><td colspan="2"><textarea rows="5" name="message"></textarea></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="Submit"/></td></tr>
</table>
</form>
</body>
</html>
admin_art_edit.php
<?php
extract($_REQUEST);
mysql_connect("localhost", "root", "password")
mysql_select_db("test") or die(mysql_error());
or die(mysql_error());
if( isset($submit) ) {
$status = "";
if( $title=="" ) {
$status = "Please enter the art title.<br>";
} else {
// Connect to the database and insert the new artist
if( isset( $id) && $id!="" ) {
$sql = "UPDATE Art SET title='$title', " .
"price='$price',
description='$description',
image='$image',
artist_id='$artist_id'" .
"WHERE id='$id'";
} else {
$sql = "INSERT INTO Art (title, price, description, image, artist_id ) ".
"VALUES ('$title', '$price', '$description', '$image', '$artist_id' )";
}
mysql_query( $sql )
or die(mysql_error());
admin_artist_insert.php
<?php
extract($_REQUEST);
if( isset($submit) ) {
$status = "";
if( $name=="" ) {
$status = "Please enter the artist's name.<br>";
} else {
// Connect to the database and insert the new artist
$sql = "INSERT INTO Artist (name, email, phone, bio)" .
Programacin II Unidad 8 Bases de Datos - Pgina N: 199
or
die(mysql_error());
mysql_select_db("test")
or die(mysql_error());
mysql_query( $sql )
$status = "SUCCESSFULLY inserted $name";
or die(mysql_error());
}
}
?>
<? include("admin_header.php") ?>
<h1>Artist Insert Screen</h1>
<form action="<?=$_SERVER['PHP_SELF']?>" method="get">
<table>
<? if (isset($status)) {?>
<tr><td colspan="2"><b><?=$status?></b><br><br></td></tr>
<? } ?>
<tr><td>Name</td><td><input type="text" name="name"/></td></tr>
<tr><td>Email</td><td><input type="text" name="email"/></td></tr>
<tr><td>Phone</td><td><input type="text" name="phone"/></td></tr>
<tr><td>Bio</td><td><textarea rows="15" cols="60" name="bio"></textarea></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="Submit"/></td></tr>
</table>
</form>
<? include("admin_footer.php") ?>
admin_artist_edit.php
<?php
extract($_REQUEST);
mysql_connect("localhost", "root", "password")
mysql_select_db("test")
or die(mysql_error());
or die(mysql_error());
if( isset($submit) ) {
$status = "";
if( $name=="" ) {
$status = "Please enter the artist's name.<br>";
} else {
// Connect to the database and insert the new artist
Programacin II Unidad 8 Bases de Datos - Pgina N: 200
or die(mysql_error());
artist_detail.php
<?php
extract($_REQUEST);
mysql_connect("localhost", "root", "password")
mysql_select_db("test")
or die(mysql_error());
or die(mysql_error());
admin_header.php
<?php
session_start();
// Check if the user is logged in
if( !isset($_SESSION['authorized']) || $_SESSION['authorized'] != 'yes' ) {
Programacin II Unidad 8 Bases de Datos - Pgina N: 202
footer.php
<br><br>
<table width="100%" bgcolor="#000000">
<tr>
<td class="orange" width="33%"><div align="left">1200 9th Ave, San
Francisco</div></td>
<td
class="orange"
width="33%"><div
align="right">www.TheCanvasGallery.com</div></td>
<td class="orange" width="34%"><div align="center">Phone (415)5040060</div></td>
</tr>
</table><br><br>
</font></td>
</tr>
</table>
</html>
index.php
<?php
// Connect to the database and insert the new artist
$sql = "SELECT * FROM Artist ORDER BY name";
mysql_connect("localhost", "root", "password")
or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
Programacin II Unidad 8 Bases de Datos - Pgina N: 203
admin_login.php
<?php
extract($_REQUEST);
if( isset($login) && $login=="admin" &&
isset($password) && $password="guess" ) {
session_start();
$_SESSION['authorized'] = 'yes';
header( "Location: admin_artist_list.php" );
exit();
}
Programacin II Unidad 8 Bases de Datos - Pgina N: 204
?>
<html>
<head><title>Art Gallery Administration</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body align="center">
<img src="images/CanvasLogo-plain.gif"><br>
<h1>Art Gallery Administration</h1>
<center>
<h1>Please Login</h1>
<small>(Use 'admin' and 'guess' for login and password)<br><br></small>
<form>
<table>
<tr><td>Login:</td><td><input type="text" name="login"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password"></td></tr>
<tr><td> </td><td><input type="submit" value="Login"></td></tr>
</table>
</form>
</center>
</html>
header.php
<html>
<head>
<title>The Canvas Gallery, San Francisco Art Gallery, Music Club, Bar, and Restaurant, Open Mic, Poetry,
Film</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table cellSpacing=0 cellPadding=0 align=center border=0 borderColor="#CCCCCC" width="563">
<tr>
<td><br><IMG src="images/header.jpg" border="0">
<div align="left">
[<a href="index.php">HOME</a>]
[<a href="contact.php">Contact Us</a>]
[<a href="admin_artist_list.php">Administration</a>]
</div>
</td>
</tr>
<tr>
<td width="100%"><font face="Verdana, Arial, Helvetica, sans-serif"><br>
admin_art_list.php
<?php
// Connect to the database and insert the new artist
$sql = "SELECT Art.id, Art.title, Art.price, Artist.name FROM Art Art, Artist Artist " .
"WHERE Artist.id=Art.artist_id ORDER BY Artist.name";
mysql_connect("localhost", "root", "password")
or die(mysql_error());
mysql_select_db("test")
or die(mysql_error());
$recordset = mysql_query( $sql )
or die(mysql_error());
?>
<? include("admin_header.php") ?>
<h1>Art List</h1>
<table cellpadding="5">
<th>Art</th><th>Artist</th><th>Price</th>
<?
while( $row=mysql_fetch_assoc($recordset) ) {
print '<tr><td><a href="admin_art_edit.php?id='. $row["id"]. '">' .$row["title"] .'</a></td>' .
"<td>". $row["name"] ."</td><td><div align=right>$".
number_format($row["price"],2) ."</div></td></tr>\n";
}
?>
</table>
<? include("admin_footer.php") ?>
admin_footer.php
<br><hr>
</div>
</body>
</html>
admin_artist_list.php
<?php
// Connect to the database and insert the new artist
mysql_connect("localhost", "root", "password")
mysql_select_db("test")
or die(mysql_error());
or die(mysql_error());
extract($_REQUEST);
if( isset($action) && $action="delete" ) {
$sql = "DELETE FROM Artist WHERE id='$id'";
mysql_query( $sql )
or die(mysql_error());
}
$sql = "SELECT * FROM Artist ORDER BY name";
$recordset = mysql_query( $sql )
or die(mysql_error());
?>
<? include("admin_header.php") ?>
<h1>Artist List</h1>
<table cellpadding="5">
<th>Artist</th><th>Phone</th><th>Email</th><th>Action</th>
<?
while( $row=mysql_fetch_assoc($recordset) ) {
print '<tr><td><a href="admin_artist_edit.php?id='. $row["id"]. '">' .$row["name"] .'</a></td>' .
"<td>". $row["phone"] ."</td><td>". $row["email"] ."</td>".
'<td><a
href="admin_artist_list.php?action=delete&id='.
$row["id"]."\">Delete</a></td></tr>\n";
}
?>
</table>
<? include("admin_footer.php") ?>
contact.php
<?php
extract($_REQUEST);
if(isset($submit)) {
$body = "\r\nContact Requested:\r\n\r\n $Name\r\n $Phone\r\n $Email\r\n $Message\r\n";
mail( "public@marakana.com", "Contact Form", $body, "From: form@TheCanvasGallery.com" );
mail( $Email, "Contact Form", $body, "From: form@TheCanvasGallery.com" );
$status = '<br><strong><font color="red">Your message has been sent. Thank
you!</font><br><br>';
}
?>
<? include("header.php") ?>
<h1>Contact Us</h1>
Programacin II Unidad 8 Bases de Datos - Pgina N: 207
<?=$status?>
<p> Please fill our your contact information and we will contact you within 24 hours. </p>
<form>
<table cellpadding="5">
<tr><td>Name</td><td><input type="text" name="Name"></td></tr>
<tr><td>Phone</td><td><input type="text" name="Phone"></td></tr>
<tr><td>Email</td><td><input type="text" name="Email"></td></tr>
<tr><td>Message</td><td><textarea name="Message" rows="5"></textarea></td></tr>
<tr><td> </td><td><input type="submit" name="submit" value="Send"></td></tr>
</table>
</form>
<? include("footer.php") ?>
Empleados
Ej. Emp_Add_Row.html
<html>
<head>
<title>Formulario de Ingreso de Empleados</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p> </p>
<form name="ABMEmp" method="post" action="Emp_add_row.php">
<table width="287" border="0" align="center" cellpadding="3">
<tr bgcolor="#FFFFFF">
<td colspan="2">
<div align="center"><b>Introduzca los datos del empleado</b></div>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="107">
<div align="right">Cdigo </div>
</td>
<td width="162">
<input type="text" name="Empno" size="5">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="107">
Programacin II Unidad 8 Bases de Datos - Pgina N: 208
<div align="right">Nombre</div>
</td>
<td width="162">
<input type="text" name="Ename" size="25">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="107">
<div align="right">Puesto</div>
</td>
<td width="162">
<input type="text" name="Job" size="25">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="107">
<div align="right">Jefe</div>
</td>
<td width="162">
<input type="text" name="Mgr" size="5">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="107">
<div align="right">Fecha Ing.</div>
</td>
<td width="162">
<input type="text" name="Hiredate" size="15">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="107">
<div align="right">Sueldo</div>
</td>
<td width="162">
<input type="text" name="Sal" size="15">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="107">
<div align="right">Comisin</div>
</td>
<td width="162">
<input type="text" name="Comm" size="15">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="107">
<div align="right">Departamento</div>
Programacin II Unidad 8 Bases de Datos - Pgina N: 209
</td>
<td width="162">
<input type="text" name="Deptno" size="5">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td colspan="2">
<div align="center">
<input type="submit" name="Submit" value="Enviar">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
Ej. Emp_Add_Row.php
<html>
<head>
<title>Alta de Empleados</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p> </p>
<?php
extract($_REQUEST);
$con = mysql_connect("localhost","root","")
or die("No se ha podido establecer la conexin con el servidor!");
$resp = mysql_select_db("practica")
or die("No se ha podido seleccionar la base de datos!");
$sqlquery = "INSERT INTO Emp VALUES(". $Empno .",'". $Ename . "','".
$Job . "'," . $Mgr . ",'" . $Hiredate . "'," . $Sal . "," . $Comm . "," . $Deptno . ")";
$queryresult = mysql_query($sqlquery) or die("No se puede ejecutar la sentencia insert!");
echo "<table border=1 align=center width=500>";
echo " <tr> ";
echo " <td> ";
echo " Cdigo";
echo " </td>";
echo " <td>".$Empno. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo "
Nombre";
echo " </td>";
echo " <td >".$Ename. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo "
Puesto";
echo " </td>";
echo " <td>".$Job. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo " Jefe";
echo " </td>";
echo " <td>".$Mgr. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo "
Fecha Ing";
echo " </td>";
echo " <td>".$Hiredate. "</td>";
Programacin II Unidad 8 Bases de Datos - Pgina N: 211
Ej. Emp_db_browser.php
<html>
<head>
<title>Explorador de registros de Empleados</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
extract($_REQUEST);
$con = mysql_connect("localhost","root","")
or die("No se ha podido establecer la conexin con el servidor!");
$resp = mysql_select_db("practica")
or die("No se ha podido seleccionar la base de datos!");
$consultasql = "SELECT * from emp";
$resultadosql = mysql_query($consultasql);
Programacin II Unidad 8 Bases de Datos - Pgina N: 213
$nro_registros = mysql_num_rows($resultadosql);
print "Su consulta devuelve $nro_registros registros <br>\n";
echo "<table width=900 border=1 align=center>";
echo " <tr>";
for ($i=0; $i < mysql_num_fields($resultadosql); $i++)
{
$longitud = mysql_field_len($resultadosql, $i);
echo " <td width=$longitud> <center><b>".
mysql_field_name($resultadosql,$i) ."</b></center></td>\n";
}
echo " <td width=100> <center><b>Accin</b></center></td>\n";
echo " </tr>\n";
while ($fila=mysql_fetch_array($resultadosql))
{
echo " <tr>\n";
echo " <td>".$fila["EMPNO"]."</td>\n";
echo " <td>".$fila["ENAME"]."</td>\n";
echo " <td>".$fila["JOB"]."</td>\n";
echo " <td>".$fila["MGR"]."</td>\n";
echo " <td>".$fila["HIREDATE"]."</td>\n";
echo " <td>".$fila["SAL"]."</td>\n";
echo " <td>".$fila["COMM"]."</td>\n";
echo " <td>".$fila["DEPTNO"]."</td>\n";
echo <td><A
href=\"Emp_display.php?Empno=".$fila["EMPNO"]."\">Editar</a></td>\n";
echo " </tr>\n";
}
echo "</table>\n";
mysql_close( $con );
?>
</body>
</html>
Ej. Emp_display.php
<html>
<head>
<title>Formulario de actualizacin de empleados</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="maildata" method="post" action="Emp_changes.php">
<table width="250" border="1" align="center">
<?php
extract($_REQUEST);
$con = mysql_connect("localhost","root","")
or die("No se ha podido establecer la conexin con el servidor!");
$resp = mysql_select_db("practica")
or die("No se ha podido seleccionar la base de datos!");
$consultasql = "SELECT * from emp where empno=" .$Empno;
Programacin II Unidad 8 Bases de Datos - Pgina N: 215
$resultadosql = mysql_query($consultasql);
if($row=mysql_fetch_array($resultadosql))
{
echo "<tr> ";
echo " <td> Cdigo </td>";
echo " <td width=\"150\"> ". $row["EMPNO"] . " </td>";
echo " <td> <input type=\"hidden\" Name=\"Empno\"
value=\"".$row["EMPNO"]."\" ></td>";
echo "</tr>";
echo "<tr> ";
echo " <td> Nombre </td>";
echo " <td>";
echo " <input type=\"text\" Name=\"Ename\"
value=\"".$row["ENAME"]."\" >";
echo " </td> ";
echo "</tr>";
echo " <tr> ";
echo " <td> Puesto </td>";
echo " <td> ";
echo " <input type=\"text\" Name=\"Job\"
value=\"".$row["JOB"]."\" >";
echo " </td>";
echo "</tr>";
echo " <tr> ";
echo " <td> Jefe </td>";
echo " <td> ";
echo " <input type=\"text\" Name=\"Mgr\"
value=\"".$row["MGR"]."\" >";
echo " </td>";
echo "</tr>";
echo " <tr> ";
echo " <td> Fecha Ing </td>";
echo " <td> ";
echo " <input type=\"text\" Name=\"Hiredate\"
value=\"".$row["HIREDATE"]."\" >";
echo " </td>";
echo "</tr>";
echo " <tr> ";
echo " <td> Sueldo </td>";
echo " <td> ";
echo " <input type=\"text\" Name=\"Sal\"
value=\"".$row["SAL"]."\" >";
echo " </td>";
echo "</tr>";
echo " <tr> ";
echo " <td> Comisin </td>";
echo " <td> ";
Programacin II Unidad 8 Bases de Datos - Pgina N: 216
Ej. Emp_changes.php
<html>
<head>
<title>Modificacin de Empleados</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p> </p>
<?php
extract($_REQUEST);
$con = mysql_connect("localhost","root","")
or die("No se ha podido establecer la conexin con el servidor!");
$resp = mysql_select_db("practica")
or die("No se ha podido seleccionar la base de datos!");
$consultasql = "UPDATE emp SET ename=\"" . $Ename . "\", job=\"" . $Job . "\" , mgr=" .
$Mgr .
Programacin II Unidad 8 Bases de Datos - Pgina N: 218
", hiredate=\"". $Hiredate . "\", sal=" . $Sal . ", comm=" . $Comm . ", deptno=" . $Deptno .
" where empno=".$Empno;
echo $consultasql . "<br>\n";
$result = mysql_query($consultasql)
or die("No es posible realizar la consulta SQL");
echo "El registro se ha actualizado con xito.";
?>
</body>
</html>
conectar.php
<?php
//En el filezilla:
//Servidor: t24m06.labs.escuelaurquiza.edu.ar
//Usuario: ftp_t24m06
//Contrasea: la misma del papel
//Guardarlo en el directorio web
//Programa para listar.
//Se ejecuta desde el explorer:
//http://t24m06.labs.escuelaurquiza.edu.ar/listado.php
//$conexion = mysql_connect("localhost","dbu_t24m06","mcn87wa");
$conexion = mysql_connect("localhost","root","");
//Seleccionar una base de datos MySQL
//$labase = mysql_select_db("db_t24m06",$conexion);
$labase = mysql_select_db("practica",$conexion);
?>
listado.php
<?php
include 'conectar.php';
//Enviar una consulta MySQL
//http://ar2.php.net/manual/es/function.mysql-query.php
$result = mysql_query("select DEPTNO Numero, DNAME Nombre, LOC Localidad from dept");
if (!$result) {
//Cierra la conexin de MySQL
//http://ar2.php.net/manual/es/function.mysql-close.php
mysql_close();
die("no se obtuvieron datos");
}
//Obtiene el nmero de campos en un resultado
//http://ar2.php.net/manual/es/function.mysql-num-fields.php
$cant_campos = mysql_num_fields($result);
print "<table border='1'><tr>";
//Cabecera de la tabla
Programacin II Unidad 8 Bases de Datos - Pgina N: 220
for ($i=0;$i<$cant_campos;$i++){
$un_campo = mysql_fetch_field($result);
print "<td>{$un_campo->name}</td>";
}
print "</tr>";
print "<tr>";
//Filas de la tabla
while($fila = mysql_fetch_row($result))
{
print "<tr>";
foreach ($fila as $campo )
print "<td>$campo</td>";
print "</tr>";
}
print "</table>";
//Libera la memoria del resultado
//ar2.php.net/manual/es/function.mysql-free-result.php
mysql_free_result($result);
//Cierra la conexin de MySQL
//http://ar2.php.net/manual/es/function.mysql-close.php
mysql_close();
?>
alta.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="alta.php" method="post" name="formulario" target="_parent" id="formulario">
<table width="354" border="1">
<tr>
<td width="115" align="right">Numero:</td>
<td width="223"><input name="txt_deptno" type="text" id="txt_deptno"></td>
</tr>
<tr>
<td align="right">Nombre:</td>
<td><input type="text" name="txt_dname" id="txt_dname"></td>
</tr>
<tr>
<td align="right">Localidad:</td>
<td><input type="text" name="txt_loc" id="txt_loc"></td>
</tr>
</table>
<p>
<input type="submit" name="btn_enviar" id="btn_enviar" value="Enviar">
</p>
</form>
</body>
Programacin II Unidad 8 Bases de Datos - Pgina N: 222
</html>
alta.php
<?php
extract($_REQUEST);
include 'conectar.php';
//Arma la instruccin SQL
$campos = "deptno, dname, loc";
$valores = $txt_deptno . "," . "'" . $txt_dname . "','" . $txt_loc . "'";
$sqlinsert = "insert into dept (" . $campos . ") values (" . $valores . ")";
//Enviar una consulta MySQL
//http://ar2.php.net/manual/es/function.mysql-query.php
mysql_query($sqlinsert);
print "SQL ejecutado: " .$sqlinsert . "<br>";
print "Registros agregados: " . mysql_affected_rows();
//Cierra la conexin de MySQL
//http://ar2.php.net/manual/es/function.mysql-close.php
mysql_close();
?>
modificar.html
Programacin II Unidad 8 Bases de Datos - Pgina N: 224
modificar.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
Programacin II Unidad 8 Bases de Datos - Pgina N: 225
<body>
<?php
extract($_REQUEST);
include 'conectar.php';
//Enviar una consulta MySQL
//http://ar2.php.net/manual/es/function.mysql-query.php
$result = mysql_query("select * from dept where deptno=$txt_deptno") or die("No se ejecut");
//Recupera una fila de resultado como un array asociativo, un array numrico o como ambos
//http://ar2.php.net/manual/es/function.mysql-fetch-array.php
$result_array=mysql_fetch_array($result);
?>
<form action="modificar2.php" method="post" name="formulario" target="_parent" id="formulario">
<input name="deptno" type="hidden" value="<?php print $txt_deptno ?>"/>
<table width="354" border="1">
<tr>
<td width="115" align="right">Nombre:</td>
<td width="223"><input name="txt_dname" type="text" id="txt_dname" value="<?php print
$result_array['DNAME'] ?>"></td>
</tr>
<tr>
<td align="right">Localidad:</td>
<td><input type="text" name="txt_loc" id="txt_loc" value="<?php print $result_array['LOC'] ?>"></td>
</tr>
</table>
<p>
<input type="submit" name="btn_enviar" id="btn_enviar" value="Enviar">
</p>
<?php
//Libera la memoria del resultado
//ar2.php.net/manual/es/function.mysql-free-result.php
mysql_free_result($result);
//Cierra la conexin de MySQL
//http://ar2.php.net/manual/es/function.mysql-close.php
mysql_close();
?>
</form>
</body>
</html>
Programacin II Unidad 8 Bases de Datos - Pgina N: 226
modificar2.php
<?php
extract($_REQUEST);
include 'conectar.php';
//Arma la instruccin SQL
$sqlupdate = "update dept set "
. "DNAME='" . $txt_dname
. "',LOC='" . $txt_loc
. "' where DEPTNO=" . $deptno;
//Enviar una consulta MySQL
//http://ar2.php.net/manual/es/function.mysql-query.php
mysql_query($sqlupdate);
print "SQL ejecutado: " . $sqlupdate . "<br>";
print "Registros agregados: " . mysql_affected_rows();
//Cierra la conexin de MySQL
//http://ar2.php.net/manual/es/function.mysql-close.php
mysql_close();
?>
baja.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
Programacin II Unidad 8 Bases de Datos - Pgina N: 229
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="baja.php" method="post" name="formulario" target="_parent" id="formulario">
<table width="354" border="1">
<tr>
<td width="115" align="right">Numero:</td>
<td width="223"><input name="txt_deptno" type="text" id="txt_deptno"></td>
</tr>
</table>
<p>
<input type="submit" name="btn_enviar" id="btn_enviar" value="Enviar">
</p>
</form>
</body>
</html>
baja.php
<?php
extract($_REQUEST);
if ($txt_deptno != ""){
include 'conectar.php';
$sqldelete = "delete from dept where deptno=$txt_deptno";
//Enviar una consulta MySQL
//http://ar2.php.net/manual/es/function.mysql-query.php
mysql_query($sqldelete);
print $sqldelete . "<br>";
print "Registros eliminados: " . mysql_affected_rows();
//Cierra la conexin de MySQL
//http://ar2.php.net/manual/es/function.mysql-close.php
mysql_close();
}
?>