Código PHP:
--
-- Estructura de tabla para la tabla `ubicacion`
--
CREATE TABLE `ubicacion` (
`id` int(20) NOT NULL auto_increment,
`ubica` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
--
-- Volcar la base de datos para la tabla `ubicacion`
--
INSERT INTO `ubicacion` (`id`, `ubica`) VALUES
(1, 'Clorinda'),
(2, 'Pirané'),
(3, 'El Colorado'),
(4, 'Formosa'),
(5, 'Mayorazgo'),
(6, '25 de Mayo'),
(7, 'Casbas');
Código PHP:
<form id="loginForm" name="loginForm" method="post" action="register-exec.php">
<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<th>Nombre </th>
<td><input name="fname" type="text" class="textfield" id="fname" /></td>
</tr>
<tr>
<th>Apellido </th>
<td><input name="lname" type="text" class="textfield" id="lname" /></td>
</tr>
<tr>
<th width="124">Mail</th>
<td width="168"><input name="mail" type="text" class="textfield" id="mail" /></td>
</tr>
<tr>
<th width="124">Ubicacion</th>
<td width="168"><select name="ubicacion">
<option selected="selected">aca deberia traer los datos de la tabla de arriba</option>
</select>
</td>
</tr>
<tr>
<th width="124">Login</th>
<td width="168"><input name="login" type="text" class="textfield" id="login" /></td>
</tr>
<tr>
<th>Password</th>
<td><input name="password" type="password" class="textfield" id="password" /></td>
</tr>
<tr>
<th>Confirmar Password </th>
<td><input name="cpassword" type="password" class="textfield" id="cpassword" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Registrar" /></td>
</tr>
</table>
</form>
Código PHP:
--
-- Estructura de tabla para la tabla `members`
--
CREATE TABLE `members` (
`id` int(11) unsigned NOT NULL auto_increment,
`firstname` varchar(100) default NULL,
`lastname` varchar(100) default NULL,
`mail` varchar(100) NOT NULL,
`login` varchar(100) NOT NULL default '',
`passwd` varchar(32) NOT NULL default '',
`estado` int(10) unsigned NOT NULL default '0',
`permiso` int(50) unsigned NOT NULL default '0',
`rol` int(3) unsigned NOT NULL default '0',
`nivel` int(3) NOT NULL,
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=27 ;
Código PHP:
<?php
//Start session
session_start();
//Include database connection details
require_once('config.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$fname = clean($_POST['fname']);
$lname = clean($_POST['lname']);
$mail = clean($_POST['mail']);
$ubicacion = clean($_POST['ubicacion']);
$login = clean($_POST['login']);
$password = clean($_POST['password']);
$cpassword = clean($_POST['cpassword']);
//Input Validations
if($fname == '') {
$errmsg_arr[] = 'Debe completar el Nombre';
$errflag = true;
}
if($lname == '') {
$errmsg_arr[] = 'Debe completar el Apellido';
$errflag = true;
}
if($mail == '') {
$errmsg_arr[] = 'Complete Mail';
$errflag = true;
}
if($ubicacion == '') {
$errmsg_arr[] = 'Complete Ubicacion';
$errflag = true;
}
if($login == '') {
$errmsg_arr[] = 'Complete Login';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Falta la Password';
$errflag = true;
}
if($cpassword == '') {
$errmsg_arr[] = 'Falta confirmar Password';
$errflag = true;
}
if( strcmp($password, $cpassword) != 0 ) {
$errmsg_arr[] = 'Las Passwords no coinciden';
$errflag = true;
}
//Check for duplicate login ID
if($login != '') {
$qry = "SELECT * FROM members WHERE login='$login'";
$result = mysql_query($qry);
if($result) {
if(mysql_num_rows($result) > 0) {
$errmsg_arr[] = 'Login esta en Uso';
$errflag = true;
}
@mysql_free_result($result);
}
else {
die("Query failed");
}
}
//If there are input validations, redirect back to the registration form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: registro_usuarios.php");
exit();
}
//Create INSERT query
$qry = "INSERT INTO members(firstname, lastname, mail, ubicacion, login, passwd) VALUES('$fname','$lname','$mail','$ubicacion','$login','".md5($_POST['password'])."')";
$result = @mysql_query($qry);
//Check whether the query was successful or not
if($result) {
header("location: registro_exitoso.php");
exit();
}else {
die("Query failed");
}
?>
Alguien puede decirme como poder hacer en el primer php para que me liste en el combo las localidades de mi tabla ubicacion y que estas sean grabadas cuando presiono sobre grabar.
Desde ya muy agradecido de antemano a quien pueda corregirme este script o decirme como hacerlo ya que mucha idea no tengo.
Salu2