You are on page 1of 6

I.

<html>

CSS + JavaScript

<head> <link rel="stylesheet" href="style.css"> <script type="text/javascript"> function changeColor(){ var element=document.getElementById('upper'); if (element.style.color.match("blue")) { element.style.color="red"; } else { element.style.color="blue"; } } function changeBg(){ var element=document.getElementById('capital'); if(element.style.backgroundColor.match("gray")) { element.style.backgroundColor="pink"; } else { element.style.backgroundColor="gray"; } document.getElementById('lower').style.backgroundColor="green"; document.body.style.backgroundColor="red"; }

</script>

</head> <body> <a href="#">Click this link!</a> <p id="upper">This is a simple paragraph for testing upper case letter .</p> <p id="capital">This is a simple paragraph for testing capital letter .</p> <p id="lower">This is a simple paragraph for testing lower case letter .</p> <input type="button" value="changeBg" onclick="changeBg();"> <input type="button" value="changeColor" onclick="changeColor();">

</body> </html>

a:link,a:visited{ text-decoration: overline; color: green; } a:hover,a:active{ text-decoration: none; color: yellow; } #upper{ text-transform: uppercase; } #capital{ text-transform: capitalize; } #lower{ text-transform: lowercase;

} II. <html> <head> <script type="text/javascript"> function showResult(str){ var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState==4 & xmlhttp.status==200){ document.getElementById('result').innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET","ajaxresult.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <div> <input type='text' name='searchfor' class='text' onkeyup='showResult(this.value);' autofocus/> <input type='submit' value='Search' /> </div> <div id="result"></div> </body> </html> Ajax

III. PHP(registration form) 1. sign_up.php <form action="sign_up_process.php" method="POST"> <input type="text" name="fname" placeholder="first name" autocomplete="off"><br> <input type="text" name="lname" placeholder="last name" autocomplete="off"><br> <input type="text" name="username" placeholder="user name" autocomplete="off"><br> <input type="text" name="email" placeholder="email" autocomplete="off"><br> <input type="password" name="password" placeholder="password"><br> <input type="password" name="confirm_password" placeholder="confirm password"><br> <input type="submit" name="submit" value="Sign Up"> </form> 2. sign_up-process.php <?php $localhost='localhost'; $username='sambath'; $password='sb606440'; $dbname='camboevent';

$mysql=mysql_connect($localhost,$username,$password) or die(mysql_error()); $db=mysql_select_db($dbname,$mysql) or die(mysql_error());

$username=$_POST['username']; $fname=$_POST['fname']; $lname=$_POST['lname']; $email=$_POST['email']; $password=$_POST['password'];

if($db){ $sql="INSERT INTO users(first_name,last_name,username,email,password) VALUES(

'$fname','$lname','$username','$email','$password')"; $query=mysql_query($sql); if($query){ echo 'Thank you for registration!'; } else{ echo 'Please check your info again!!!'.mysql_error(); } } else{ echo 'fail'; } ?> 3. log_in.php <div id="login_form"> <form action="login_process.php" method="POST"> <input type="text" name="username" placeholder="user name" autocomplete="off"><br> <input type="password" name="password" placeholder="password"><br> <input type="submit" name="submit" value="Sign In"> </form> </div> 4. login_process.php <?php $localhost='localhost'; $username='sambath'; $password='sb606440'; $dbname='camboevent';

$mysql=mysql_connect($localhost,$username,$password) or die(mysql_error()); $db=mysql_select_db($dbname,$mysql) or die(mysql_error());

$username=$_POST['username']; $password=$_POST['password'];

if($db){ $sql="SELECT * FROM users WHERE username='$username' AND password='$password'";

$query=mysql_query($sql); if(mysql_num_rows($query)!=1){ echo 'please fill your info!'; } else{ echo 'login success!';

} } else{ echo 'fail'; }

?>

You might also like