Hi mga bossing! Nagpractice practice ko ug php para maghimo ko ug website sa amo shop pero naa man error. Ang ako gi himo kay simple login ug register system ra.. Mao ni ang error:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\shopname\register.php:32) in C:\xampp\htdocs\shopname\register.php on line 33
Unsa diay rason ngano in ana ang error? Ug unsa ang solution?
register.php
Code:
<?php
include "includes/connection.php";
if(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$confirmPassword = $_POST['confirmPassword'];
$email = ($_POST['email']);
if(strlen($username) > 32 || strlen($username) < 3){
echo "<center> Username must contain 3 to 32 characters!";
}else{
$res = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."'");
$num = mysql_num_rows($res);
if($num == 1){
echo "The <b>Username</b> you have chosen is already taken!";
}else{
if(strlen($password) < 5 || strlen($password) > 32){
echo "Your <b>Password</b> must be between 5 and 32 characters long!";
}else{
if($confirmPassword != $password){
echo "The <b>Password</b> supplied didn't match!";
}else{
$res = mysql_query("SELECT * FROM `users` WHERE `email` = '".$email."'");
$num = mysql_num_rows($res);
if($num == 1){
echo "The <b>email</b> supplied is already taken!";
}else{
$res2 = mysql_query("INSERT INTO `users` (`username`, `password`, `email`) VALUES('".$username."','".$password."','".$email."')");
echo "You have succesfully registered!";
header('location: index.php');
}
}
}
}
}
}
?>
<form action="register.php" method="post">
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td>Username: </td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td>Confirm Password: </td>
<td><input type="password" name="confirmPassword" /></td>
</tr>
<tr>
<td>Email: </td>
<td><input type="text" name="email" size="25"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Register" /></td>
</tr>
<tr>
<td colspan="2" align="center"><a href="index.php">Login</a> | <a href="forgot.php">Forgot Pass</a></a></td>
</tr>
</table>
</form>
connection.php
Code:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpassword = '';
$dbname = 'shopname';
$connection = mysql_connect("$dbhost", "$dbuser", "$dbpassword") or die("MySQL Error: " . mysql_error());
mysql_select_db("$dbname", $connection) or die("MySQL Error: " . mysql_error());
?>
I having a problem with this one for a couple of days now.. Bad for a newbie... Anyway it would be great if somebody will help me.