Author Archive

Login a user using PHP & MySQL

January 3rd, 2011

Login user using php & mysql
This code is not yet completed but it is usable.

<?php
$user = $_POST['txtusername'];
$pass = $_POST['txtpassword'];
$login = $_POST['btnlogin'];

$dbhost = "localhost";
$dbuser = "iicuser";
$dbpass ="123456";
$dbname = "iicdatabase";

$cnn = mysql_connect($dbhost,$dbuser,$dbpass);
$sldb = mysql_select_db($dbname,$cnn);
if(isset($login)){
if(!$user){
echo "Please Input Your Username";
}
else{
$check_username = mysql_query("SELECT username FROM tbladmin WHERE username='".$user."'");
if(!mysql_num_rows($check_username)){
if(!$pass){
echo "Please Input Your Password";
}
else{
$check_password = mysql_query("SELECT password FROM tbladmin WHERE password='".$pass."'");
if(mysql_num_rows($check_password) && mysql_num_rows($check_username)){
echo "Well Done";
}
else{
echo "You might wrong username or password.";
}
}
}
}

}
?>
<!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>Login with database</title>
</head>
<form action="#" method="post">
Username:<input type="text" name="txtusername" /><br />
Password:<input type="text" name="txtpassword" /><br />
<input type="submit" name="btnlogin" value="Login" />
</form>
<body>
</body>
</html>

Basic PHP with MySQL Database

December 14th, 2010

IIC University of  technology
evening class: B205
file name: dbstudent.php
host: localhost
username: iicdatabase
password: 123456
Note: please un-comment for use some code.

<?php
$host   = "localhost";
$dbuser = "iicphp";
$dbpass = "123456";
$dbname = "iicdatabase";
$connect =  mysql_connect($host,$dbuser,$dbpass);
$dbselect = mysql_select_db($dbname,$connect);
/*$insert = mysql_query("INSERT INTO tblstudent (studname,gender,class) VALUES ('Bopha','Male','B2-05')",$connect);
if($insert){
echo "Insert Completed";
}
else{
echo "Insert Incompleted";
}*/
$delete = mysql_query("DELETE FROM tblstudent WHERE studid='1'",$connect);
if(!$delete){
echo "Could not Delete Record";
}
else{
echo "Record had been deleted";
}
/*$update = mysql_query("UPDATE tblstudent SET gender='Male' WHERE studid='1'",$connect);
if($update){
echo "Update Completed";
}
else{
echo "Update Incompleted";
}*/
/*if(!$connect){
echo "Databae is not Connected";
}
else{
echo "Database is Connected";
if(!dbselect){
echo "Database is not Selected";
}
else {
echo "Database is Selected";
}
}*/
?>

PHP Send Mail

December 2nd, 2010
<?php
if(isset($_POST['btnsend'])){
$mail_to = $_POST['email'];
$mail_from = "From:info@novpiseth.co.cc";
$mail_subject = $_POST['sub'];
$mail_message = $_POST['txtmessage'];

mail($mail_to,$mail_subject,$mail_message,$mail_from);
}
?>
<!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>Untitled Document</title>
</head>
<form action="#" method="post">
Email:<input type="text" name="email" /><br />
Subject:<input type="text" name="sub" /><br />
Message:<textarea cols="10" rows="3" name="txtmessage"></textarea><br />
<input type="submit" name="btnsend" value="Send" />
</form>
<body>
</body>
</html>

php function using include

November 16th, 2010

IIC University of Technology Evening Class (B205)
filename: func.php
formfunc.php

formfunc.php

<?php
include("func.php");
if(isset($_GET['btncal'])){
echo "My Add is". add($_GET['txtx'],$_GET['txty']);
echo "<br>";
echo "My Sub is". sub($_GET['txtx'],$_GET['txty']);
}

?>
<!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>Untitled Document</title>
</head>
<form method="get">
X:<input  type="text" name="txtx" />
Y:<input  type="text" name="txty" />
<input type="submit" name="btncal" />
</form>
<body>
</body>
</html>

func.php

<?php
function add($x,$y){
$total = $x + $y;
return $total;
}
function sub($x,$y){
$sub = $x - $y;
return $sub;
}
?>
WP2Social Auto Publish Powered By : XYZScripts.com