create table
---------------
<?php
$link = mysqli_connect("localhost", "root", "", "php_example");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt create table query execution
$sql = "CREATE TABLE student(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
department VARCHAR(30) NOT NULL,
courses VARCHAR(70) NOT NULL )";
if(mysqli_query($link, $sql)){
echo "Table created successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>---------------------------------------------------------------------------------------------------------------------
dbconfigure
__________
<?php
// Database configuration
$dbHost = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "php_example";
// Create database connection
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
// Check connection
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
?>
______________________________________________________________________________
multi file uploading
______________
<form action="multiple_file_upload.php" method="post" enctype="multipart/form-data">
Select Multiple Image Files to Upload:
<input type="file" name="files[]" multiple >
<input type="submit" name="submit" value="UPLOAD">
</form>
----------------------------------------------------------------------------------------
log in
_____
<?php
session_start();
$con = mysqli_connect('localhost','root','','aone');
$username =$_POST['username'];
$password =$_POST['password'];
$q = "SELECT * FROM `registration` WHERE Username = '$username' && Password ='$password' ";
$run = mysqli_query($con,$q);
$result=mysqli_num_rows($run);
echo $result;
if($result!==0)
{
$_SESSION['user-name']=$username;
header('location:profile.php');
}
else{
echo"error";
}
?>
_________________________________________________________________________________
registration
---------------
<html>
<head>
<title>REGISTRATION | FORM </title>
<head>
<link rel="stylesheet" type="text/css" href="reg.css">
<body>
<!--Table-->
<form action="" method="post">
<div>
<table border="0">
<tr>
<th align="center" colspan="2">Registration Here.</th>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" required="required" /></td><td id="two"><?php echo $ename; ?></td> <!--name-->
</tr>
<tr>
<td>Surname</td>
<td><input type="text" name="sname" required="required" /></td><td id="two"><?php echo $esname; ?></td> <!--sname-->
</tr>
<tr>
<td>Email</td>
<td><input type="email" name="email" required="required" /></td><td id="two"><?php echo $eemail; ?></td> <!--Email-->
</tr>
<tr>
<td>Cell No.</td>
<td><input type="number" name="cell" /></td><td id="two"><?php echo $ecell; ?></td> <!--cell-->
</tr>
<tr>
<td>Create Your Username.</td>
<td id="add"><input type="text" name="user" id="user" required="required" /></td><td id="two"><?php echo $euser; ?></td> <!--Create Your username // user -->
</tr>
<tr>
<td>Create Your Password.</td>
<td><input type="password" name="pass" required="required" /></td><td id="two"><?php echo $epass; ?></td> <!--Password // pass-->
</tr>
<tr>
<td>Confirm Password.</td>
<td><input type="text" name="cpass" /></td><td id="two"><?php echo $ecpass; ?></td> <!--confirm Password // cpass-->
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit" id="submit"/> <!--submit-->
</tr>
</table>
</div>
</form>
</body>
</html>
_________
<?php
$name=$_POST['name'];
$sname=$_POST['sname'];
$email=$_POST['email'];
$cell=$_POST['cell'];
$username=$_POST['user'];
$password=$_POST['pass'];
$con = mysqli_connect('localhost','root','','aone');
$q="INSERT INTO `registration`(`Name`, `Surname`, `Email`, `Cell_no`, `Username`, `Password`) VALUES ('$name','$sname','$email','$cell','$username','$password')";
$run = mysqli_query($con,$q);
$ename=$esname=$eemail=$ecell=$euser=$epass=$ecpass="";
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$sname=$_POST['sname'];
$email=$_POST['email'];
$cell=$_POST['cell'];
$username=$_POST['user'];
$password=$_POST['pass'];
$cpass=$_POST['cpass'];
if(empty($name)){
$ename="Name is empty";
}
else{
$ename="✔";
}
if(empty($sname)){
$esname="Surname is empty";
}
else{
$esname="✔";
}
if(empty($email)){
$eemail="Email is empty";
}
else{
$eemail="✔";
}
if(empty($cell)){
$ecell="Mobile Number is empty";
}
else{
$ecell="✔";
}
if(empty($username)){
$euser="Username is empty";
}
else{
$euser="✔";
}
if(empty($password)){
$epass="Password is empty";
}
else{
$epass="✔";
}
if(empty($password == $cpass)){
$ecpass="Password is not match.";
}
else{
$ecpass="✔";
}
if($run)
{
header('location:http://localhost/a1/registration/successfull.html');
}
else
{
echo"error";
}
}
?>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
---------------
<?php
$link = mysqli_connect("localhost", "root", "", "php_example");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt create table query execution
$sql = "CREATE TABLE student(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(30) NOT NULL,
department VARCHAR(30) NOT NULL,
courses VARCHAR(70) NOT NULL )";
if(mysqli_query($link, $sql)){
echo "Table created successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>---------------------------------------------------------------------------------------------------------------------
dbconfigure
__________
<?php
// Database configuration
$dbHost = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "php_example";
// Create database connection
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
// Check connection
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
?>
______________________________________________________________________________
multi file uploading
______________
<form action="multiple_file_upload.php" method="post" enctype="multipart/form-data">
Select Multiple Image Files to Upload:
<input type="file" name="files[]" multiple >
<input type="submit" name="submit" value="UPLOAD">
</form>
----------------------------------------------------------------------------------------
log in
_____
<?php
session_start();
$con = mysqli_connect('localhost','root','','aone');
$username =$_POST['username'];
$password =$_POST['password'];
$q = "SELECT * FROM `registration` WHERE Username = '$username' && Password ='$password' ";
$run = mysqli_query($con,$q);
$result=mysqli_num_rows($run);
echo $result;
if($result!==0)
{
$_SESSION['user-name']=$username;
header('location:profile.php');
}
else{
echo"error";
}
?>
_________________________________________________________________________________
registration
---------------
<html>
<head>
<title>REGISTRATION | FORM </title>
<head>
<link rel="stylesheet" type="text/css" href="reg.css">
<body>
<!--Table-->
<form action="" method="post">
<div>
<table border="0">
<tr>
<th align="center" colspan="2">Registration Here.</th>
</tr>
<tr>
<td>Name</td>
<td><input type="text" name="name" required="required" /></td><td id="two"><?php echo $ename; ?></td> <!--name-->
</tr>
<tr>
<td>Surname</td>
<td><input type="text" name="sname" required="required" /></td><td id="two"><?php echo $esname; ?></td> <!--sname-->
</tr>
<tr>
<td>Email</td>
<td><input type="email" name="email" required="required" /></td><td id="two"><?php echo $eemail; ?></td> <!--Email-->
</tr>
<tr>
<td>Cell No.</td>
<td><input type="number" name="cell" /></td><td id="two"><?php echo $ecell; ?></td> <!--cell-->
</tr>
<tr>
<td>Create Your Username.</td>
<td id="add"><input type="text" name="user" id="user" required="required" /></td><td id="two"><?php echo $euser; ?></td> <!--Create Your username // user -->
</tr>
<tr>
<td>Create Your Password.</td>
<td><input type="password" name="pass" required="required" /></td><td id="two"><?php echo $epass; ?></td> <!--Password // pass-->
</tr>
<tr>
<td>Confirm Password.</td>
<td><input type="text" name="cpass" /></td><td id="two"><?php echo $ecpass; ?></td> <!--confirm Password // cpass-->
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit" id="submit"/> <!--submit-->
</tr>
</table>
</div>
</form>
</body>
</html>
_________
<?php
$name=$_POST['name'];
$sname=$_POST['sname'];
$email=$_POST['email'];
$cell=$_POST['cell'];
$username=$_POST['user'];
$password=$_POST['pass'];
$con = mysqli_connect('localhost','root','','aone');
$q="INSERT INTO `registration`(`Name`, `Surname`, `Email`, `Cell_no`, `Username`, `Password`) VALUES ('$name','$sname','$email','$cell','$username','$password')";
$run = mysqli_query($con,$q);
$ename=$esname=$eemail=$ecell=$euser=$epass=$ecpass="";
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$sname=$_POST['sname'];
$email=$_POST['email'];
$cell=$_POST['cell'];
$username=$_POST['user'];
$password=$_POST['pass'];
$cpass=$_POST['cpass'];
if(empty($name)){
$ename="Name is empty";
}
else{
$ename="✔";
}
if(empty($sname)){
$esname="Surname is empty";
}
else{
$esname="✔";
}
if(empty($email)){
$eemail="Email is empty";
}
else{
$eemail="✔";
}
if(empty($cell)){
$ecell="Mobile Number is empty";
}
else{
$ecell="✔";
}
if(empty($username)){
$euser="Username is empty";
}
else{
$euser="✔";
}
if(empty($password)){
$epass="Password is empty";
}
else{
$epass="✔";
}
if(empty($password == $cpass)){
$ecpass="Password is not match.";
}
else{
$ecpass="✔";
}
if($run)
{
header('location:http://localhost/a1/registration/successfull.html');
}
else
{
echo"error";
}
}
?>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
<?php
if(isset($_POST['submit'])){
// Include the database configuration file
include_once 'dbConfig.php';
// File upload configuration
$targetDir = "../uploads/";
$allowTypes = array('jpg','png','jpeg','gif');
$statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = '';
if(!empty(array_filter($_FILES['files']['name']))){
foreach($_FILES['files']['name'] as $key=>$val){
// File upload path
$fileName = basename($_FILES['files']['name'][$key]);
$targetFilePath = $targetDir . $fileName;
// Check whether file type is valid
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
if(in_array($fileType, $allowTypes)){
// Upload file to server
if(move_uploaded_file($_FILES["files"]["tmp_name"][$key], $targetFilePath)){
// Image db insert sql
$insertValuesSQL .= "('".$fileName."', NOW()),";
}else{
$errorUpload .= $_FILES['files']['name'][$key].', ';
}
}else{
$errorUploadType .= $_FILES['files']['name'][$key].', ';
}
}
if(!empty($insertValuesSQL)){
$insertValuesSQL = trim($insertValuesSQL,',');
// Insert image file name into database
$insert = $db->query("INSERT INTO images (file_name, uploaded_on) VALUES $insertValuesSQL");
if($insert){
$errorUpload = !empty($errorUpload)?'Upload Error: '.$errorUpload:'';
$errorUploadType = !empty($errorUploadType)?'File Type Error: '.$errorUploadType:'';
$errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType;
$statusMsg = "Files are uploaded successfully.".$errorMsg;
}else{
$statusMsg = "Sorry, there was an error uploading your file.";
}
}
}else{
$statusMsg = 'Please select a file to upload.';
}
// Display status message
echo $statusMsg;
}
?>
---------------------------------------------if(isset($_POST['submit'])){
// Include the database configuration file
include_once 'dbConfig.php';
// File upload configuration
$targetDir = "../uploads/";
$allowTypes = array('jpg','png','jpeg','gif');
$statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = '';
if(!empty(array_filter($_FILES['files']['name']))){
foreach($_FILES['files']['name'] as $key=>$val){
// File upload path
$fileName = basename($_FILES['files']['name'][$key]);
$targetFilePath = $targetDir . $fileName;
// Check whether file type is valid
$fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
if(in_array($fileType, $allowTypes)){
// Upload file to server
if(move_uploaded_file($_FILES["files"]["tmp_name"][$key], $targetFilePath)){
// Image db insert sql
$insertValuesSQL .= "('".$fileName."', NOW()),";
}else{
$errorUpload .= $_FILES['files']['name'][$key].', ';
}
}else{
$errorUploadType .= $_FILES['files']['name'][$key].', ';
}
}
if(!empty($insertValuesSQL)){
$insertValuesSQL = trim($insertValuesSQL,',');
// Insert image file name into database
$insert = $db->query("INSERT INTO images (file_name, uploaded_on) VALUES $insertValuesSQL");
if($insert){
$errorUpload = !empty($errorUpload)?'Upload Error: '.$errorUpload:'';
$errorUploadType = !empty($errorUploadType)?'File Type Error: '.$errorUploadType:'';
$errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType;
$statusMsg = "Files are uploaded successfully.".$errorMsg;
}else{
$statusMsg = "Sorry, there was an error uploading your file.";
}
}
}else{
$statusMsg = 'Please select a file to upload.';
}
// Display status message
echo $statusMsg;
}
?>
Comments
Post a Comment