  | 
              
	              
	                
  
    
	 
        สอบถามหน่อยครับ มือใหม่ ส่งค่าวันที่ไป และรับค่ามามันว่างเปล่า กับ clear ค่า textbox     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                ติด 2 คำถามครับ  
1.  ส่งค่าวันที่ไม่ไปอ่ะครับ  
2. ถ้าเช็ค user มีอยู่แล้วในระบบ ให้เคลียร์ textbox ยังไงไครับ  
 
register.php 
 
Code (PHP) 
<html>
<head>
<title>Registration Form</title>
<meta http-equiv="Content-Language" content="th"> 	
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
	
	function checkUserName(usercheck)
	{
		$('#usercheck').html('<img src="images/ajax-loader.gif" />');
		$.post("checkuser.php", {user_name: usercheck} , function(data)
			{			
				   if (data != '' || data != undefined || data != null) 
				   {				   
					  $('#usercheck').html(data);	
				   }
			  });
	}
	function checkEmail(emailcheck)
	{
		$('#emailcheck').html('<img src="images/ajax-loader.gif" />');
		$.post("checkemail.php", {user_email: emailcheck} , function(data)
			{			
				   if (data != '' || data != undefined || data != null) 
				   {				   
					  $('#emailcheck').html(data);	
				   }
			  });
	}
	function formCheck() 
	{
		//viewplayer = form name , dateinput = name of text . status = name of option
		if (document.register.inputname.value == "") 
		{	
			alert("--input name--"); 
			return false;
		}
		else if (document.register.inputsurname.value == "") 
		{
			alert("--input surname--"); 
			return false;
		}
		else if (document.register.inputphone.value == "") 
		{
			alert("--input phonenumber--"); 
			return false;
		}
		else if (document.register.inputemail.value == "") 
		{
			alert("--input email--"); 
			return false;
		}
		else if (document.register.username.value == "") 
		{
			alert("--input username--"); 
			return false;
		}
		else if(document.register.inputpassword.value == "") 
		{
			alert("--input password--"); 
			return false;
		}
	}
	function validateEmail(sEmail) 
	{
	  var reEmail = /^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/;
	  if(!sEmail.match(reEmail)) {
		alert("Invalid email address need [email protected]");
		return false;
	  }
	  return true;
	}
	function validpassword(sPassword) 
	{
	 if (sPassword.length < 4) 
	 {	
		alert("--require > 4 character--"); 
		return false;
	  }
	  return true;
	}
	function validname(sName) 
	{
	 if (sName.length < 3) 
	 {	
		alert("--name require > 3 character--"); 
		return false;
	  }
	  return true;
	}
	function validsurname(sSurname) 
	{
	 if (sSurname.length < 3) 
	 {	
		alert("--surname require > 3 character--"); 
		return false;
	  }
	  return true;
	}
	function validmobilephone(sPhonenumber) 
	{
	 if (sPhonenumber.length < 10) 
	 {	
		alert("--mobile phone has 10 digit pleas reinput-"); 
		return false;
	  }
	  return true;
	}
	function displayDate() 
	{
		var now = new Date();
		var day = ("0" + now.getDate()).slice(-2);
		var month = ("0" + (now.getMonth() + 1)).slice(-2);
		var today = now.getFullYear() + "-" + (month) + "-" + (day);
		document.getElementById("dateinput").value = today;
	}
</script>	
</head>
<?php  
	//call database config file
	include('config.php');
	include_once('libraries.php'); // contains the database function
?>
<body onload="displayDate();">
<?php	
	$id = $_GET["thisid"];
	if(isset($_POST['submit'])) 
	{
		//get value from submit 
		$name = $_POST['inputname']; 
		$surname = $_POST['inputsurname']; 
		$mobilephone  = $_POST['inputmobilephone']; 
		$email  = $_POST['inputemail'];
		$dateinputa  = $_POST['dateinput']; 
		$username  = $_POST['inputusername']; 
		$password  = $_POST['inputpassword'];
		echo "show data name =>".$name."<br>";
		echo "show data surname =>".$surname."<br>";
		echo "show data mobilephone =>".$mobilephone."<br>";
		echo "show data email =>".$email."<br>";
		echo "show data dateinput =>".$dateinputa."<br>";
		echo "show data username =>".$username."<br>";
		echo "show data password =>".$password."<br>";
	}
	else{  
	?> 
	
	<form id='register' name="register" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" onSubmit="return formCheck();">
		<table >
			<tr>
				<td>
				<div style=" padding:20px 0px;"><h2>Registration Form</h2></div>
				</td>
			</tr>
			<tr>
				<td>
					Name
				</td>
				<td>
					<input name="inputname" type="text" id="inputname" maxlength=10 onblur="validname(this.value);"> 
				</td>
			</tr>
			<tr>
				<td>
					SurName
				</td>
				<td>
					<input name="inputsurname" type="text" id="inputsurname" maxlength=30 onblur="validsurname(this.value);">
				</td>
			</tr>
			<tr>
				<td>
					Mobile Phone
				</td>
				<td>
					<input name="inputmobilephone" type="number" id="inputmobilephone" maxlength=10 onblur="validmobilephone(this.value);" />
				</td>
			</tr>
			<tr>
				<td>
					Email
				</td>
				<td>
					<!--
					<input name="inputemail" type="text" id="inputemail"  maxlength=40 onblur="validateEmail(this.value);" />
					-->
					<input type="text" name="inputemail" id="inputemail" onblur="checkEmail(this.value)" /> 
					<span id="emailcheck"></span>
				</td>
				<td class="status"></td>
				<span id="sEmail"></span>
			</tr>
				<td>
					Register Date
				</td>
				<td>
					<input type="date" id="dateinput" readonly>
				</td>
			<tr>
				<td>
					Username
				</td>
				<td>
					<input type="text" name="inputusername" id="inputusername" onblur="checkUserName(this.value)" /> 
					<span id="usercheck"></span>
				</td>	
			</tr>
			<tr>
				<td>
					Password
				</td>
				<td>
					<input name="inputpassword" type="password" id="inputpassword" onblur="validpassword(this.value);">
				</td>
			</tr>
			<tr align ="right">
				<td colspan=2><input name="submit" type="submit" value="register"></td>
			</tr>
			</table>	
		</form>		
<?php
} 
?>
</body>
</html>
 
 
  
checkuser.php  
Code (PHP) 
<?php  
		include('config.php');
		include_once('libraries.php'); // contains the database function
		
		// from  {user_name: usercheck} 
		if(isset($_POST["user_name"]))
		{
			$conn = dbconnect(); 
			$inputusername = $_POST['user_name'];
			
			if(strlen($inputusername) < 3 || strlen($inputusername) > 15)
			{
				echo '<span class="error">Username must be 6 to 15 characters</span>';
			}
			else
			{
				$sqlcheck = "select * from login where username =";
				$sqlcheck = $sqlcheck."'".$inputusername."'";
				$result = mysql_query($sqlcheck,$conn);
				$objresult = mysql_fetch_array($result);
				if(!$objresult)
				{
					echo '<span class="success">Username is available.</span>';
					mysql_close();
				}
				else
				{
					// user already exist
					echo '<span class="error">Username already exists.</span>';
					mysql_close();
					exit;
					
				}		
			}
		}
	
?>
 
 
  Tag : PHP, JavaScript, CakePHP               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2016-02-06 22:45:44 | 
                      By :
                          kimnue | 
                      View :
                          944 | 
                      Reply :
                          3 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                   
เลือกปุ่มให้ตรงกับภาษาที่ใช้ เอาครอบโค๊ดไว้ครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2016-02-07 03:00:21 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 เช็คข้อมูลซ้ำครับ 
 
Code (PHP) 
<?php
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer WHERE CustomerID = '".$_POST["txtCustomerID"]."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if($objResult)
{
		echo "CustomerID already exist.";
}
else
{
	$strSQL = "";
	$strSQL = "INSERT INTO customer ";
	$strSQL .="(CustomerID,Name,Email,CountryCode,Budget,Used) ";
	$strSQL .="VALUES ";
	$strSQL .="('".$_POST["txtCustomerID"]."','".$_POST["txtName"]."','".$_POST["txtEmail"]."' ";
	$strSQL .=",'".$_POST["txtCountryCode"]."','".$_POST["txtBudget"]."','".$_POST["txtUsed"]."') ";
	$objQuery = mysql_query($strSQL);
	if($objQuery)
	{
		echo "Save Done.";
	}
	else
	{
		echo "Error Save [".$strSQL."]";
	}
	}
mysql_close($objConnect);
?>
 
 
PHP MySQL Check Already Exists Add/Insert Record 
                        
               
               | 
             
            
              
			  			  
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2016-02-07 15:32:11 | 
                        By :
                            mr.win | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |