Boş kayıtları web sayfasının her yükte eklenir

1 Cevap php

Ben kayıt sayfası yaşıyorum. sayfa yüklendiğinde, her şey o ilk varsayılan boş kutularının değerleri eklemek için çalışır. Lütfen yardım edin. Benim kod takılır

register.template.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RBlog - For the Consumers - By the Sellers</title>
<?php include("dbclass/register_class.php");?>
</head>
<body>
<?php include("includes/header.php"); ?>
    <div class="afterpicer_total">
    <?php include("includes/menu.php"); ?>
    <div class="wrapper">
            <div class="cont">
                <?php include("includes/left_menu.php"); ?>
                <div class="reg_cont">
                    <form name="add_user" method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">

                        <div class="reg_label">Name</div>
                        <div class="reg_tbox"><input type="text" size="32" name="name" class="reg_tbox_style" ></input></div><br/>
                        <div class="reg_label">Email ID</div>
                        <div class="reg_tbox"><input type="text" size="32" name="email" class="reg_tbox_style"></input></div><br/>
                        <div class="reg_label" >Confirm Email ID</div>
                        <div class="reg_tbox"><input type="text" size="32" name="cemail" class="reg_tbox_style"></input></div><br/>
                        <div class="reg_label" >Password</div>
                        <div class="reg_tbox"><input type="text" size="32" name="pass" class="reg_tbox_style"></input></div><br/>
                        <div class="reg_label" >Confirm Password</div>
                        <div class="reg_tbox"><input type="text" size="32" name="cpass" class="reg_tbox_style"></input></div><br/>
                        <div class="reg_label" >Mobile No</div>
                        <div class="reg_tbox"><input type="text" size="32" name="mobile" class="reg_tbox_style"></input></div><br/>
                        <?

                            $adduser=new Users();
    			$adduser->addDB();
                         ?>
                        <div class="reg_tbox"><input type="submit" value="Register" class="reg_but_style"style="margin-left:155px;"></input></div>


                    </form>

                </div>
           </div>
           <div class="adspace"> Advertisement Space</div>
        </div>
    </div>

</body>
</html>

register_class.php

<?php
ob_start();

    include("common/class.Database.php");
    include("common/varDeclare.php");

class Users extends Database
{
    var $fields_val = array();
    var $fields_value = array();
    var $state_name = array();
    var $db;
    function addDB()
    {	

    	try{
    		$reg_date			=date("Y-m-d G:i:s");

    		$username 			=$_POST[name];
    		$email				=$_POST[email];
    		$password 			=$_POST[pass];
    		$mobile 			=$_POST[mobile];


                        $user_query = "insert into register set email = '".$email."', pwd = '".$password."', mobile = '".$mobile."', reg_date = '".$now."'";
    		$insertUser=$this->do_query($user_query);


    		$retVal=true;

    			if(!$insertUser){
    			  $this->errMsg = REG_FAILED;
    			  $retVal = false;
    			}		
    		return $retVal;
    	}
    	catch(Exception $e)
    	{
    		echo 'Caught exception: ',  $e->getMessage(), "\n";
    	}
    }

//  ---- End of addDB()------				

}
////////End of class/////////////

1 Cevap

In register.template.php, form sunulmuş sadece addDB() yürüten bir koşullu deyim takılı değil çünkü boş değerleri her zaman eklenir. Bunu değiştirerek bu sorunu çözebilirsiniz

$adduser=new Users();
$adduser->addDB();

karşı

if ( $_SERVER['REQUEST_METHOD'] === 'POST' ) {
    $adduser=new Users();
    $adduser->addDB();
}

Also, you really should escape all of your $_POST values with mysql_real_escape_string if you plan on inserting them inkarşı a database that way.