NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

https://www.w3schools.com/php/php_ref_array.asp

http://sgenc.bilkent.edu.tr/ctis256/CTIS256-Week3.pdf


editing.php

<?php

include('check.php');


if(isset($_POST['Submit']))
{
$exist = mysqli_query($con, "select name from tuition where name='".$_POST['name']."' AND id<>$_GET[id]");
$result= mysqli_num_rows($exist);

if($result > 0)
{
echo " name already exists";
}
else
{

if($_FILES["upload_img"]["name"]!='')
{
unlink('upload/'.$_POST["hidImg"]);
$pic = $_FILES["upload_img"]["name"];
$ext = end(explode('.', $pic));
$upload_img = $_POST['name'].'.'.$ext;
move_uploaded_file($_FILES["upload_img"]["tmp_name"], 'upload/'.$upload_img);
} else {
$upload_img = $_POST["hidImg"];
}

$updt = "update tuition set
name = '".$_POST['name']."',
gender = '".$_POST['gender']."',
email_id = '".$_POST['email_id']."',
phone_no = '".$_POST['phone_no']."',
subjects = '".implode(',',$_POST['subjects'])."',
website = '".$_POST['website']."',
upload_img = '".$upload_img."'
where id = '".$_GET['id']."'";

if(mysqli_query($con, $updt)) {
echo "Data Inserted";
header('Location: listing.php');
} else {
echo "Error" . mysqli_error($con);
}
}
}

$qry= "select name, gender, email_id, phone_no, subjects, website, upload_img from tuition where id=$_GET[id]";
$result= mysqli_query($con, $qry);
$row= mysqli_fetch_array($result);

$subjects= explode(',',$row['subjects']);


?>

<form action="" method="POST" enctype="multipart/form-data">
<fieldset style= "width:100%; text-align:center;">
<!--<p id="msg"></p>-->
<b>Name</b>
<input type="text" name="name" id="name" value="<?php echo $row["name"]?>"><br><br>

<b>Gender</b>
<input type="radio" name="gender" id="gender" value="1" <?php echo $row['gender'] === '1' ? 'checked="checked"':'' ?>/>Male
<input type="radio" name="gender" id="gender" value="2" <?php echo $row['gender'] === '2' ? 'checked="checked"':'' ?>/>Female<br><br>

<b>Email Id</b>
<input type="text" name="email_id" id="email_id" value="<?php echo $row["email_id"]?>"><br><br>

<b>Contact No.</b>
<input type="int=15" name="phone_no" id="phone_no" value="<?php echo $row["phone_no"]?>"><br><br>

<b>Subjects</b>
<input type="checkbox" name="subjects[]" value="1" <?php if(in_array("1",$subjects)) { echo "checked='checked'";} ?>/>Physics</option>
<input type="checkbox" name="subjects[]" value="2" <?php if(in_array("2",$subjects)) { echo "checked='checked'";} ?>/>Chemistry</option>
<input type="checkbox" name="subjects[]" value="3" <?php if(in_array("3",$subjects)) { echo "checked='checked'";} ?>/>Biology</option>
<input type="checkbox" name="subjects[]" value="4" <?php if(in_array("4",$subjects)) { echo "checked='checked'";} ?>/>Maths</option><br><br><br>

<b>Website</b>
<input type="text" name="website" id="website" value="<?php echo $row["website"]?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<b>Upload Image</b>
<input type="file" name="upload_img" id="upload_img">
<input type="hidden" name="hidImg" value="<?php echo $row["upload_img"]?>">
<br>
<img src="upload/<?php echo $row["upload_img"]?>" width="150" height="150">
<br><br>

<input type="submit" name="Submit" id="btnSubmit" value="Submit"><br><br>

</fieldset>
</form>

<script src="jquery.min.js"></script>
<script>

$(function(){
$('#btnSubmit').click(function(){
var mailChk =/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
var fileChk = /(.gif|.GIF|.jpg|.JPG|.jpeg|.JPEG|.png|.PNG)$/i;
var url = /^(http[s]?://){0,1}(www.){0,1}[a-zA-Z0-9.-]+.[a-zA-Z]{2,5}[.]{0,1}/;
var mobile = /^[0-9 ]+$/;

if ($('#name').val() == '') {
alert("Enter your name!");
return false;
}if ($('#email_id').val() == '') {
alert("Enter email!");
return false;
}if(!mailChk.test($("#email_id").val())){
alert('Use valid email');
return false;
}if ($('#phone_no').val() == '') {
alert("Enter Mobile no!");
return false;
}if(!mobile.test($("#phone_no").val())){
alert('Invalid mobile no.');
return false;
}if ($('input[name="subjects[]"]:checked').length == 0) {
alert("Please choose any subject");
return false;
}if ($('#website').val() == '') {
alert("Enter web url!");
return false;
}if(!url.test($("#website").val())){
alert('Invalid web url.');
return false;
}if($("#upload_img").val()!='' && !fileChk.test($("#upload_img").val())){
alert('Only .gif|.GIF|.jpg|.JPG|.jpeg|.JPEG|.png|.PNG files are allowed!');
return false;
}
});
});

</script>


listing.php

<!DOCTYPE html>
<html>
<head>
<style>

th,td{
border: 1px solid red;
padding: 5x;
}
th,td{
text-align: center;
}
th{
background-color: grey;
color: white;
}

</style>
</head>

<table style="width:50%">
<thead>
<caption>Class Registration</caption>
<tr>
<th>Name</th>
<th>Gender</th>
<th>E-mail Id</th>
<th>Contact No.</th>
<th>Subjects</th>
<th>Website</th>
<th>Uploaded Image</th>
<th>Action</th>
<th>Delete</th>
</tr>
</thead>

<tbody>

<?php
include('check.php');

$sql= "select id, name, gender, email_id, phone_no, subjects, website, upload_img from tuition";
$result= mysqli_query($con, $sql);
//mysqli_num_rows($result);
if(mysqli_num_rows($result) > 0){
while($row= mysqli_fetch_array($result))
{

$sub = (explode(",",$row['subjects']));
$ac='';
if(count($sub) > 0)
{
foreach($sub as $dx){
if($dx == "1"){ $ac.= "Physics, ";}
elseif($dx == "2"){ $ac.= "Chemistry, ";}
elseif($dx == "3"){ $ac.= "Biology, ";}
elseif($dx == "4"){ $ac.= "Maths, ";}
}
$ac=rtrim($ac,', ');
}
?>

<tr>
<td><?php echo $row["name"]?></td>
<td><?php if ($row["gender"] == "1"){ echo "Male";}
elseif ($row["gender"] == "2"){ echo "Female";}
?></td>
<td><?php echo $row["email_id"]?></td>
<td><?php echo $row["phone_no"]?></td>
<td><?php echo $ac; ?></td>
<td><?php echo $row["website"]?></td>
<td><img src="upload/<?php echo $row["upload_img"]?>" width="50" height="40"></td>
<td><a href="editing.php?id=<?php echo $row['id']?>"><img src="images/edit.png" width="20" height="16" border="0" alt="DEF"/></a></td>
<td><a href="deleting.php?id=<?php echo $row['id']?>"><img src="images/delete.png" width="25" height="20" border="0" alt=""></a></td>
</tr>

<?php
}
}
else{
echo "Retry";
}
?>
</tbody>
</table>
</html>

index.php

<?php
include('check.php');

if(isset($_POST['Submit'])){
if(count($_POST['subjects'] > 0)){
$var='';
foreach($_POST['subjects'] as $aj){
$var .=$aj.',';
}
$var=rtrim($var,',');
}

$exist = mysqli_query($con, "select name from tuition where name='".$_POST['name']."'");
$result= mysqli_num_rows($exist);

if($result > 0)
{
echo " name already exists";
}
else
{
unlink('upload/'.$_POST["hidImg"]);
$pic = $_FILES["upload_img"]["name"];
$ext = end(explode('.', $pic));
$upload_img = $_POST['name'].'.'.$ext;
move_uploaded_file($_FILES["upload_img"]["tmp_name"], 'upload/'.$upload_img);

$insr= "insert into tuition set
name = '".$_POST['name']."',
gender = '".$_POST['gender']."',
email_id = '".$_POST['email_id']."',
phone_no = '".$_POST['phone_no']."',
subjects = '".$var."',
website = '".$upload_img."',
upload_img = '".$upload_img."'";

if(mysqli_query($con, $insr)){
echo "data inserted";
}
else{
echo "Error" . mysqli_error($con);
}
}


/* if($_FILES['upload_img']['name'])
{
if(!$_FILES]'upload_img']['error'])
{
$new_name = strtolower($FILES['upload_img']['tmp_name']);
if($_FILES['upload_img']['size'] > (2048000))
{
$valid_file = false;
$message = 'Your file size is large';
}

if($valid_file)
{
move_uploaded_file($_FILES['upload_img']['tmp_name'], 'images/'.$new_name);
$message = 'File accepted';
}
}

else
{
$message = 'Error:'.$_FILES['upload_img']['error'];
}
}

$_FILES['upload_img']['name'];
$_FILES['upload_img']['size'];
$_FILES['upload_img']['type'];
$_FILES['upload_img']['tmp_name'];*/

if(isset($_FILES["upload_img"]) && $_FILES['upload_img']["error"] == 0){
$allowed = array("jpg" => "image/jpg", "jpeg" => "image/jpeg", "png" =>"image/png");
$filename = $_FILES['upload_img']['name'];
$filetype = $_FILES['upload_img']['type'];
$filesize = $_FILES['upload_img']['size'];

$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!array_key_exists($ext, $allowed)) die("Error: Please select a correct file format");

$maxsize = 2 * 1024 * 1024;
if($filesize > $maxsize)
die("Error: File size must be within 2Mb");

if(in_array($filetype, $allowed)){
if(file_exists("upload/" . $_FILES["upload_img"]["name"])){
echo $_FILES["upload_img"]["name"] . " already exists.";
}
else{
move_uploaded_file($_FILES["upload_img"]["tmp_name"], "upload/" . $_FILES["upload_img"]["name"]);
echo "Your file was uploaded successfully.";
}
}else{
echo "Error: There was a problem uploading your file. Please try again.";
}
}
else{
echo "Error: " . $_FILES["upload_img"]["error"];
}
}
?>

<div style="width:1100px;">
<form action="" method="POST" enctype="multipart/form-data">
<fieldset style= "width:100%; text-align:center;">

<b>Name</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="name" id="name"/><br><br>

<b>Gender</b>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="gender" id="gender" value="1"/>Male&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="gender" id="gender" value="2"/>Female<br><br>

<b>Email Id</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="email_id" id="email_id"/><br><br>

<b>Contact No.</b>&nbsp;
<input type="int=15" name="phone_no" id="phone_no"/><br><br>

<b>Subjects</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="subjects[]" value="1"/>Physics</option>
<input type="checkbox" name="subjects[]" value="2"/>Chemistry</option>
<input type="checkbox" name="subjects[]" value="3"/>Biology</option>
<input type="checkbox" name="subjects[]" value="4"/>Maths</option><br><br><br>

<b>Website</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="website" id="website"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<b>Uploaded Image</b>
<input type="file" name="upload_img" id="upload_img"/>
<input type="hidden" name="hidImg">

<br><br>

<input type="submit" name="Submit" id="btnSubmit" value="Submit" value="Submit"/><br><br>


</fieldset>
</form>
</div>

<script src="jquery.min.js"></script>
<script>

$(function(){
$('#btnSubmit').click(function(){
var mailChk =/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
var fileChk = /(.gif|.GIF|.jpg|.JPG|.jpeg|.JPEG|.png|.PNG)$/i;
var url = /^(http[s]?://){0,1}(www.){0,1}[a-zA-Z0-9.-]+.[a-zA-Z]{2,5}[.]{0,1}/;
var mobile = /^[0-9 ]+$/;

if ($('#name').val() == '') {
alert("Enter your name!");
return false;
}if ($('#email_id').val() == '') {
alert("Enter email!");
return false;
}if(!mailChk.test($("#email_id").val())){
alert('Use valid email');
return false;
}if ($('#phone_no').val() == '') {
alert("Enter Mobile no!");
return false;
}if(!mobile.test($("#phone_no").val())){
alert('Invalid mobile no.');
return false;
}if ($('input[name="subjects[]"]:checked').length == 0) {
alert("Please choose any subject");
return false;
}if ($('#website').val() == '') {
alert("Enter web url!");
return false;
}if(!url.test($("#website").val())){
alert('Invalid web url.');
return false;
}if($("#upload_img").val()!='' && !fileChk.test($("#upload_img").val())){
alert('Only .gif|.GIF|.jpg|.JPG|.jpeg|.JPEG|.png|.PNG files are allowed!');
return false;
}
});
});

</script>
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.