Estoy haciendo un proyecto y mi codigo del formulario seria:
Código PHP:
<form id="registro" name="registro" method="post" action="includes/add_record.php">
<p>Nombre de Usuario
<label for="username"></label>
<input name="username" type="text" id="username" maxlength="10" />
</p>
<p>Email
<label for="email"></label>
<input name="email" type="text" id="email" maxlength="30" />
</p>
<p>Contraseña
<label for="password"></label>
<input name="password" type="text" id="password" maxlength="19" />
</p>
<p>
<input type="submit" name="button" id="button" value="Enviar" />
</p>
</form>
add_record.php sin el include seria este:
Código PHP:
<?php
//datos DB
$dbhost="localhost";
$dbuser="red77_aprendices";
$dbpassword="T]asasas%8V9?";
$dbname="red77_aprendiceslong";
//conecto a la DB
$connection = mysql_connect($dbhost, $dbuser, $dbpassword);
//conecto y selecciono la DB
mysql_select_db($dbname, $connection);
//Guardo los datos del formulario en variables
$username=$_POST['username'];
$email=$_POST['email'];
$password=$_POST['password'];
//Sentencia sql que voy a ejecutar
$sql = "INSERT INTO `users`(`id`, `username`, `email`, `password`) VALUES ('','$username','$email','$password')";
//Ejecuto la sentencia
$execute = mysql_query($sql);
header("location: ../registro.php");
?>
Asi me ejecuta normalmente y agrega el registro a la DB pero al poner include se me daña todo :c
con el include:
add_record.php
Código PHP:
<?php
include("includes/connection_db.php");
$username=$_POST['username'];
$email=$_POST['email'];
$password=$_POST['password'];
//Sentencia sql que voy a ejecutar
$sql = "INSERT INTO `users`(`id`, `username`, `email`, `password`) VALUES ('','$username','$email','$password')";
//Ejecuto la sentencia
$execute = mysql_query($sql);
header(registro.html);
?>
connection_db.php
Código PHP:
<?php
//datos DB
$dbhost="localhost";
$dbuser="red77_aprendices";
$dbpassword="T]asasas%8V9?";
$dbname="red77_aprendiceslong";
//conecto a la DB
$connection = mysql_connect($dbhost, $dbuser, $dbpassword);
//conecto y selecciono la DB
mysql_select_db($dbname, $connection);
?>
al ejecutar el formulario me da el siguiente error:
Código:
Warning: include(includes/connection_db.php) [function.include]: failed to open stream: No such file or directory in /home/red77/public_html/betaaprendiceslong/includes/add_record.php on line 2
Warning: include(includes/connection_db.php) [function.include]: failed to open stream: No such file or directory in /home/red77/public_html/betaaprendiceslong/includes/add_record.php on line 2
Warning: include() [function.include]: Failed opening 'includes/connection_db.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/red77/public_html/betaaprendiceslong/includes/add_record.php on line 2
Warning: mysql_query() [function.mysql-query]: Access denied for user 'red77'@'localhost' (using password: NO) in /home/red77/public_html/betaaprendiceslong/includes/add_record.php on line 9
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/red77/public_html/betaaprendiceslong/includes/add_record.php on line 9
Warning: Cannot modify header information - headers already sent by (output started at /home/red77/public_html/betaaprendiceslong/includes/add_record.php:2) in /home/red77/public_html/betaaprendiceslong/includes/add_record.php on line 10