NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

ajax_case.php

<?php
include("check.php");
$action = $_POST['action'];
switch($action)
{
case "insert":
//Name duplicate check
$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
{
//image upload
$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);

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

if(mysqli_query($con, $insr)){
echo "data inserted";
//header('Location: listing.php');
}
else{
echo "Error" . mysqli_error($con);
}
}
break;

case "edit":

$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
{
$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']."'
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']);

break;

case "del":
$del= "delete from tuition where id ='".$_POST['id']."'";

if(mysqli_query($con, $del))
{
$sql= "select id, name, gender, email_id, phone_no, subjects, website, upload_img from tuition";
$result= mysqli_query($con, $sql);

if(mysqli_num_rows($result) > 0){
$var='';
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,', ');
if ($row["gender"] == "1"){
$g = "Male";
}
elseif ($row["gender"] == "2"){
$g = "Female";
}
}
$var .= '<tr>';
$var .= '<td>'.$row['name'].'</td>';
$var .= '<td>'.$g.'</td>';
$var .= '<td>'.$row['email_id'].'</td>';
$var .= '<td>'.$row['phone_no'].'</td>';
$var .= '<td>'.$ac.'</td>';
$var .= '<td>'.$row['website'].'</td>';
$var .= '<td><img src="upload/'.$row['upload_img'].'" width="50" height="40"></td>';
$var .= '<td><a href="editing.php?id='.$row['id'].'"><img src="images/edit.png" width="20" height="16" border="0" alt="DEF"/></a><a href="javascript:del('.$row['id'].')"><img src="images/delete.png" width="25" height="20" border="0" alt=""></a></td>';
$var .= '</tr>';
}
}
echo $var;
}
else
{
echo 'Something wrong in delete';
}
break;


}
?>


ajax_index.php

<?php
include("check.php");
?>
<html>
<head>
<script src="jquery.min.js"></script>
<script type="text/javascript">



$(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;
}
var datapost = 'action=insert&'+$('#form').serialize();
$.ajax({
type : "POST",
url : "ajax_q.php",
data: datapost,
success:function(data){
console.log("success");
console.log(data);
}
});
});
});

</script>
</head>
<body>

<div style="width:1100px;">
<div id="msg"></div>
<form action="" method="POST" id="form" 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"/>

<br><br>

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


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


</body>
</html>


ajax_edit.php

<?php
include("check.php");
?>
<html>
<head>
<script src="jquery.min.js"></script>
<script type="text/javascript">

$(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;*/
}
});
});

$(function(){
$('btnSubmit').click(function(){
var datapost = 'action=edit&'+$('#form').serialize();
$.ajax({
type : "POST",
url: "ajax_q.php",
data: datapost,
success:function(data){
console.log("success");
console.log(data);
}
)};
)};
});
</script>
</head>
</body>

<div style="width:1100px;">
<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;<br><br>

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

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

</body>
</html>


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>
<script src="jquery.min.js"></script>
<script type="text/javascript">
function del(ID)
{
var datapost = 'action=del&id='+ID;
$.ajax({
type : "POST",
url: "ajax_q.php",
data: datapost,
success:function(data){
//alert(data);
$("#list").html(data);
}
});
};
</script>
</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>

</tr>
</thead>

<tbody id="list">

<?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>
<a href="javascript:del(<?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>
     
 
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.