[Script] Panel de sugerencias en Php+SQL

Bien, aquí teneis 3 breves scripts en PHP y SQL para que podais tener todos vuestro panel de sugerencias o formulario de sugerencias, también puede aplicarse en un formulario de registro o cosas así :3

Aquí teneis un breve ejemplo de cómo sería:

Visita la pagina de muestra

E aquí los scritps:

Index.php:

<!doctype html public «-//W3C//DTD HTML 4.0 //EN»>
<html>
<head>
<title>Formulario de sugerencias</title>
</head>
<body>
<div align=»center»>
<h1>Insertar un registro</h1>
<br>
<FORM METHOD=»POST» ACTION=»insertar.php»>
Nombre<br>
<INPUT TYPE=»TEXT» NAME=»nombre»><br>
Apellidos<br>
<INPUT TYPE=»TEXT» NAME=»apellidos»><br>
Email<br>
<INPUT TYPE=»TEXT» NAME=»email»><br>
Sugerencia<br>
<textarea NAME=»sugerencia»></textarea><br>
<INPUT TYPE=»SUBMIT» value=»Insertar»>
</FORM>
</div>
</body>
</html>

insertar.php:

<!doctype html public «-//W3C//DTD HTML 4.0 //EN»>
<html>
<head>
<title>¡Sugerencias aplicadas!</title>
</head>
<body>
<?php

//Definimos los caracteres

$nombre = $_POST[‘nombre’];
$apellidos = $_POST[‘apellidos’];
$email = $_POST[‘email’];
$sugerencia = $_POST[‘sugerencia’];
//Conexion con la base
mysql_connect(«localhost»,»ichisito_prueba»,»prueba1234″);

mysql_select_db(«ichisito_prueba»);

$sql = «INSERT INTO sugestions (nombre, apellidos, email, sugerencia) «;

$sql .= «VALUES (‘$nombre’, ‘$apellidos’, ‘$email’, ‘$sugerencia’)»;

mysql_query($sql);
?>
<h1><div align=»center»>Registro Insertado</div></h1>
<div align=»center»><a href=»pagina.php»>Visualizar el contenido de la base</a></div>
</body>
</html>

pagina.php:

<html>
<head>
<title>Tablón de sugerencias</title>
</head>

<body>
<div style=»width:500px»>
<?php
define(‘MAX_REC_PER_PAGE’, 10);
$db = mysql_connect(«localhost», «ichisito_prueba», «prueba1234») or die(«Couldn’t connect to db!»);
mysql_select_db(«ichisito_prueba») or die(«Couldn’t select db!»);
$rs = mysql_query(«SELECT COUNT(*) FROM sugestions») or die(«Count query error!»);
list($total) = mysql_fetch_row($rs);
$total_pages = ceil($total / MAX_REC_PER_PAGE);
$page = intval(@$_GET[«page»]);
if (0 == $page){
$page = 1;
}
$start = MAX_REC_PER_PAGE * ($page – 1);
$max = MAX_REC_PER_PAGE;
$rs = mysql_query(«SELECT sugerencia, nombre, apellidos, email FROM sugestions ORDER BY email ASC LIMIT $start, $max») or die(«Employee query error!»);
?>

<table border=»1″ width=»159%» cellspadding=»5″>
<tr>
<th>Sugerencia</th>
<th width=»21%»>Nombre</th>
<th> apellidos</th>
<th>email</th>
</tr>

<?php
while (list($sugerencia, $nombre, $apellidos, $email) = mysql_fetch_row($rs)) {
?>
<tr>
<td width=»79%»><?= htmlspecialchars($sugerencia) ?></td>
<td><?= htmlspecialchars($nombre) ?></td>
<td><?= htmlspecialchars($apellidos) ?></td>
<td><?= htmlspecialchars($email) ?></td>
</tr>
<?php
}
?>
</table>

<table border=»0″ align=»center»>
<tr>
<td>Goto Page:</td>
<?php
for ($i = 1; $i <= $total_pages; $i++) {
$txt = $i;
if ($page != $i)
$txt = «<a href=»» . $_SERVER[«PHP_SELF»] . «?page=$i»>$txt</a>»;
?>
<td align=»center»><?= $txt ?></td>
<?php
}
?>
</tr>
</table>
<hr>
</div>
</body>

</html>

sugestions.sql:

SET FOREIGN_KEY_CHECKS=0;
— —————————-
— Table structure for `sugestions`
— —————————-
DROP TABLE IF EXISTS `sugestions`;
CREATE TABLE `sugestions` (
`nombre` varchar(20) default NULL,
`apellidos` varchar(20) default NULL,
`email` varchar(20) NOT NULL default »,
`sugerencia` varchar(50) NOT NULL,
PRIMARY KEY  (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Y hasta aquí llegó el Script / Tutorial

Espero que os haya gustado.

Nos vemos en el próximo post 🙂

También te puede interesar...

Artículos populares

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.