
problema conexion a base de datos postgresql con php
Publicado por Luis Felipe (14 intervenciones) el 10/03/2016 22:32:07
Hola amigos
Estoy trabajando en una pagina web ya hice el formulario de registro y el codigo php para conectarlo a la base de datos en postgresql pero tengo un error
Warning: pg_query() expects parameter 1 to be resource, string given in C:\xampp\htdocs\solucioneshts\validar_registro.php on line 25
Warning: pg_last_error() expects parameter 1 to be resource, string given in C:\xampp\htdocs\solucioneshts\validar_registro.php on line 25
quisiera ayuda ya que me esta costando el desarrollo de esta tarea
ESTE ES EL CODIGO DEL FORMULARIO
ESTE ES EL CODIGO DE LA CONEXION POR PHP A LA BASE DE DATOS
Y ESTE ES EL CODIGO PHP PARA INGRESAR LOS DATOS DEL FORMULARIO A LA BASE DE DATOS
NO SE SI EN LA PARTE DEL FORMULARIO QUE DICE EMPRESA CARGO Y TIPO DE DOCUMENO ESTE TOMANDO ESOS DATOS O NO
DE ANTE MANO AGRADEZCO A TODOS POR LA AYUDA
Estoy trabajando en una pagina web ya hice el formulario de registro y el codigo php para conectarlo a la base de datos en postgresql pero tengo un error
Warning: pg_query() expects parameter 1 to be resource, string given in C:\xampp\htdocs\solucioneshts\validar_registro.php on line 25
Warning: pg_last_error() expects parameter 1 to be resource, string given in C:\xampp\htdocs\solucioneshts\validar_registro.php on line 25
quisiera ayuda ya que me esta costando el desarrollo de esta tarea
ESTE ES EL CODIGO DEL FORMULARIO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<form method="post" action="validar_registro.php" >
<fieldset>
<legend style="font-size: 15pt" align="center"><b>Registro de Usuarios</b></legend>
<div class="extra-space-l"></div>
<div class="extra-space-l"></div>
<div class="form-group">
<div class="col-sm-4">
<div class="form-group">
<label style="font-size: 14pt"><b>Tipo de documento:</b></label>
<td>
<select name="tipo_id">
<option value="1" selected="selected">CC</option>
<option value="2">RUT</option>
<option value="3">NIT</option>
<option value="6">TI</option>
<option value="7">CE</option>
<option value="8">PA</option>
</select>
</td>
</div>
<div class="form-group">
<label style="font-size: 14pt"><b>Documento</b></label>
<br />
<br />
<input type="text" name="documento" class="form-control" placeholder="Ingresa tu número de documento" />
</div>
<div class="form-group">
<label style="font-size: 14pt"><b>Nombres</b></label>
<br />
<br />
<input type="text" name="nombre" class="form-control" placeholder="Ingresa tu nombre" />
</div>
<div class="form-group">
<label style="font-size: 14pt"><b>Apellidos</b></label>
<br />
<br />
<input type="text" name="apellido" class="form-control" placeholder="Ingresa tus apellidos" />
</div>
<div class="form-group">
<label style="font-size: 14pt"><b>Correo</b></label>
<br />
<br />
<input type="text" name="correos" class="form-control" placeholder="Ingresa tu correo" />
</div>
<div class="form-group">
<label style="font-size: 14pt"><b>Fecha de nacimiento:</b></label>
<br />
<br />
<input type="date" name="fecha_nac" class="form-control"/>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<br />
<label style="font-size: 14pt"><b>Empresa: </b></label>
<td>
<select name="empresa">
<option value="hts" selected="selected">HTS</option>
<option value="comparta">Comparta</option>
<option value="rys">R&S </option>
</select>
</td>
</div>
<br />
<div class="form-group">
<label style="font-size: 14pt"><b>Cargo: </b></label>
<td>
<select name="cargo">
<option value="soporte" selected="selected">Soporte</option>
<option value="recobros">Recobros</option>
<option value="auxiliar">Auxiliar</option>
<option value="coordinador_administrativo">Coord. Administrativo</option>
<option value="gerente">Gerente</option>
</select>
</td>
</div>
<br />
<div class="form-group">
<label style="font-size: 14pt"><b>Celular</b></label>
<br />
<br />
<input type="text" name="celuar" class="form-control" placeholder="Ingresa tu número de celular" />
</div>
<div class="form-group">
<label style="font-size: 14pt"><b>Nombre de Usuario</b></label>
<br />
<br />
<input type="text" name="username" class="form-control" placeholder="Ingresa tu nombre de usuario" />
</div>
<div class="form-group">
<label style="font-size: 14pt"><b>Password</b></label>
<br />
<br />
<input type="password" name="contrasena" class="form-control" placeholder="Ingresa contraseña" />
</div>
<div class="form-group">
<label style="font-size: 14pt"><b>Repite Password</b></label>
<br />
<br />
<input type="password" name="conf_contrasena" class="form-control" placeholder="Ingresa de nuevo tu contraseña" />
</div>
</div>
</div>
<br />
<div class="col-sm-4">
<input class="btn btn-primary" type="submit" name="regis" value="Registrarse"/><br /><br />
<a href="login.php" class="btn btn-warning" role="button">¿Ya tienes una cuenta?</a><br /><br />
<a href="#" class="btn btn-danger" role="button">¿Olvido su Contraseña?</a>
</div>
</fieldset>
</form>
ESTE ES EL CODIGO DE LA CONEXION POR PHP A LA BASE DE DATOS
1
2
3
4
<?php
$conexion = " host='localhost' port='5432' dbname='solucioneshts' user='postgres' password='felipe3012' ";
?>
Y ESTE ES EL CODIGO PHP PARA INGRESAR LOS DATOS DEL FORMULARIO A LA BASE DE DATOS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
include 'conexion.php';
function alert($text, $func){
echo "<script type='text/javascript'>alert('$text');$func();</script>";
}
if(isset($_POST['regis'])){
$id = '';
$tipo_id = $_POST['tipo_id'];
$documento = $_POST['documento'];
$nombre = $_POST['nombre'];
$apellido = $_POST['apellido'];
$mail = $_POST['correos'];
$fecha_nac = $_POST['fecha_nac'];
$empresa = $_POST['empresa'];
$cargo = $_POST['cargo'];
$celuar = $_POST['celuar'];
$username = $_POST['username'];
$contrasena = $_POST['contrasena'];
$conf_contrasena = $_POST['conf_contrasena'];
if($contrasena==$conf_contrasena){
$registro = pg_query($conexion,"INSERT INTO usuario (idusuario, tipo_id, documento, nombre, apellido, correo, fecha_nacimiento, empresa, cargo, celular, username, contrasena) VALUES('$id','$tipo_id','$documento','$nombre','$apellido','$mail','fecha_nac','empresa','cargo','celular','$username','$contrasena')") or die(pg_last_error($conexion));
header("Location: registro_usuarios.php?correct=1.php");
}else{
header("Location: registro_usuarios.php?error=1.php");
}
}
?>
NO SE SI EN LA PARTE DEL FORMULARIO QUE DICE EMPRESA CARGO Y TIPO DE DOCUMENO ESTE TOMANDO ESOS DATOS O NO
DE ANTE MANO AGRADEZCO A TODOS POR LA AYUDA
Valora esta pregunta


1