Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: PHP error

  1. #1

    Default PHP error


    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.

  2. #2

  3. #3
    I think that some of the messages won't be displayed to the user since they'll be redirected anyway because of the location header. That's what the error is trying to tell you.

    Code:
    echo "You have succesfully registered!";
    header('location: index.php');

  4. #4
    thanks xiao! now it's working..

    what's the reason diay naay warning ang page?

  5. #5
    @ZaF: no probz... your welcome.

    if sure ang TS nga walay whitespace then I'm sure dili na maka-solve imong links nga gi-post

    i-post lng nako ug balik kay gi-delete sa admin nga seloso

    PHP Code:
    <?php 
        session_start
    ();
        
    ob_start();
        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) < || 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');
                                
    ob_end_flush();
                                exit;
                            }
                        }
                    }
                }
            }
        }        
    ?>
    <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>

  6. #6
    iklaro lng nako ang changes...
    mag butang ka ug
    Code:
    ob_start();
    sa start.
    tapos after sa header('Location: index.php'); kay mag butang ka ug
    Code:
    ob_end_flush();
    exit;

  7. #7

  8. #8
    problem already solved. that link will not solve the problem even if you'll try it.

  9. #9
    Actually, the information inside the link is correct and helpful.

    ob_start() solves the problem by starting output buffering. This means that any output won't be sent until it has reached the ob_end_flush() file. You could also replace the line:
    Code:
    header('location: index.php');
    into a javascript redirect, as what most websites do.

  10. #10
    Quote Originally Posted by doomsweek View Post
    Actually, the information inside the link is correct and helpful.

    ob_start() solves the problem by starting output buffering. This means that any output won't be sent until it has reached the ob_end_flush() file. You could also replace the line:
    Code:
    header('location: index.php');
    into a javascript redirect, as what most websites do.
    sakto, ms nindot ang javascript na redirect script.. mao ni gamit nko perme.

  11.    Advertisement

Page 1 of 2 12 LastLast

Similar Threads

 
  1. Form to Email Php error
    By roiancuares in forum Websites & Multimedia
    Replies: 4
    Last Post: 05-10-2013, 05:31 PM
  2. help php error sending email via localhost
    By roiancuares in forum Websites & Multimedia
    Replies: 5
    Last Post: 03-07-2013, 10:50 PM
  3. need help: php error
    By snowleopard in forum Programming
    Replies: 4
    Last Post: 11-26-2011, 08:06 AM
  4. Need help... PHP Error
    By dezheavensent in forum Programming
    Replies: 6
    Last Post: 06-19-2009, 12:29 PM
  5. Replies: 2
    Last Post: 09-11-2008, 10:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top