Full Post Page

Latest Full Posts

Advanced Crud pagination Search in mysql php

Category: Latest Source Code & Written by Admin On March-15-2024 17:45:45

<?php $severname="localhost"; $username="root"; $password=""; $dbname="test"; $conn=mysqli_connect($severname, $username,$password,$dbname)or die('connection failed'); // Delete Record if(@$_GET['del_uid']!=''){ $insQuery = "DELETE FROM crud_table1 WHERE crud_id='".@$_GET['del_uid']."'"; $runQuery = mysqli_query($conn,$insQuery); header("Location: index.php");} if(isset($_POST['crud_id'])){ // Insert Query if(isset($_FILES["uploadfile"]["name"])){ // print_r($_FILES); die(); $filename=$_FILES["uploadfile"]["name"]; $temname=$_FILES["uploadfile"]["tmp_name"]; $folder="upload/".$filename; move_uploaded_file($temname,$folder); if($_POST['crud_id']==''){ $insQuery = "INSERT INTO crud_table1 (full_name, mobile_no, email_id, gender, category, address, photo)VALUES ('".@$_POST['fname']."', '".@$_POST['phone']."','".@$_POST['email']."','".@$_POST['gender']."','".@$_POST['category']."','".@$_POST['address']."','".@$folder."'"; $runQuery = mysqli_query($conn,$insQuery);} } // Update Query if($_POST['crud_id']!=''){ $folder=@$_POST["uploadoldfile"]; if($_FILES["uploadfile"]["name"]!=""){ $filename=$_FILES["uploadfile"]["name"]; $temname= $_FILES["uploadfile"]["tmp_name"]; $folder="upload/".$filename; move_uploaded_file($temname,$folder); } $upsql = "UPDATE crud_table1 SET full_name = '".@$_POST['fname']."',mobile_no = '".@$_POST['phone']."',email_id = '".@$_POST['email']."', gender = '".@$_POST['gender']."',category = '".@$_POST['category']."',address = '".@$_POST['address']."' , photo = '".@$folder."' WHERE crud_id = '".@$_POST['crud_id']."'"; $runupsql = mysqli_query($conn,$upsql);} header("Location: index.php"); } // Fetch Data of Update Record Id if(@$_GET['uid']!=''){ $editQuery = "SELECT * FROM crud_table1 where crud_id='".@$_GET['uid']."' order by crud_id"; $editData = mysqli_query($conn,$editQuery); $editData = mysqli_fetch_assoc($editData);}?> <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="style.css" type="text/css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> </head> <body> <h2>Advanced Crud pagination Search </h2> <form method="POST" enctype="multipart/form-data"> <input type="hidden" name="crud_id" id="crud_id" value="<?php echo @$_GET['uid'] ?>"><br> <label for="fname">Full name:</label> <input type="text" id="fname" name="fname" required value="<?php echo @$editData['full_name'] ?>"><br><br> <label for="email">Email ID:</label> <input type="email" id="email" name="email" required value="<?php echo @$editData['email_id'] ?>"><br><br> <label for="phone">Phone No.:</label> <input type="text" id="phone" name="phone" required value="<?php echo @$editData['mobile_no'] ?>"><br><br> <label for="gender">Gender:</label> <input type="radio" id="male" name="gender" value="Male" <?php if("Male"==@$editData['gender']) echo 'checked="checked"'?>>Male <input type="radio" id="female" name="gender" value="Female" <?php if("Female"==@$editData['gender']) echo 'checked="checked"'?>>FeMale <br><br> <label for="category">Category:</label> <select name="category" id="category" required> <option value="">--Select--</option> <option value="General" <?php if("General"==@$editData['category']) echo 'selected="selected"'?>>General</option> <option value="OBC" <?php if("OBC"==@$editData['category']) echo 'selected="selected"'?>>OBC</option> <option value="ST" <?php if("ST"==@$editData['category']) echo 'selected="selected"'?>>ST</option> </select><br> <label for="address">Address:</label> <textarea name="address" id="address"><?php echo @$editData['address'] ?></textarea><br><br> <label for="file">Photo:</label> <input type="file" id="file" name="uploadfile" value=""><br> <input type="hidden" id="file" name="uploadoldfile" value=""> <input type="submit"> </form><br> <?php /* Calculate Offset Code */ $limit = 3; if(isset($_GET['page'])){ $page = $_GET['page']; }else{ $page = 1; } $offset = ($page - 1) * $limit; $where=''; if(@$_GET['qry']!='') $where = " where full_name like '%".@$_GET['qry']."%' or category like '%".@$_GET['qry']."%' or gender like '%".@$_GET['qry']."%' "; $selectQuery = "SELECT * FROM crud_table1 {$where} order by crud_id DESC LIMIT {$offset},{$limit}"; $runQuery = mysqli_query($conn,$selectQuery);?> <form method="GET"> <input type="text" name="qry" id="qry" placeholder="search" value="<?php echo @$_GET['qry'] ?>"><input type="submit"></form> <br> <table style="width: 100%;" border="1"> <tr> <th>Sr.No.</th> <th>Customer Name</th> <th>Mobile No.</th> <th>Email Id</th> <th>Gender</th> <th>Category</th> <th>Address</th> <th>IMAGE</th> <th>Action</th> </tr> <?php $abc=1; foreach ($runQuery as $key => $value) { ?> <tr> <td><?php echo $abc++; ?></td> <td><?php echo $value['full_name']; ?></td> <td><?php echo $value['mobile_no']; ?></td> <td><?php echo $value['email_id']; ?></td> <td><?php echo $value['gender']; ?></td> <td><?php echo $value['category']; ?></td> <td><?php echo $value['address']; ?></td> <td><img src="<?php echo $value['photo'] ?>" width="60px" height="60px" alt=""></td> <td><a href="index.php?uid=<?php echo $value['crud_id']; ?>" style="background: green;padding: 5px;color: white;">Update</a> <a href="index.php?del_uid=<?php echo $value['crud_id']; ?>" onclick="return getDelteNotf()" style="background: red;padding: 5px;color: white;">Delete</a></td> </tr> <?php } ?> </table> <?php // show pagination $sql1 = "SELECT * FROM crud_table1"; $result1 = mysqli_query($conn, $sql1) or die("Query Failed."); if(mysqli_num_rows($result1) > 0){ $total_records = mysqli_num_rows($result1); // $limit=3; $total_page = ceil($total_records / $limit); //for give upper value echo '<ul class="pagination admin-pagination">'; if($page > 1){ echo '<li><a href="index.php?page='.($page - 1).'">Prev</a></li>'; } for($i = 1; $i <= $total_page; $i++){ if($i == $page){ $active = "active"; }else{ $active = ""; } echo '<li class="'.$active.'"><a href="index.php?page='.$i.'">'.$i.'</a></li>'; } if($total_page > $page){ echo '<li><a href="index.php?page='.($page + 1).'">Next</a></li>'; } echo '</ul>'; }?> <script> function getDelteNotf(){ var cnfrm = confirm("Are You Sure Do You Want to delete this record"); return cnfrm;} </script></body></html>

Comments

samir

March-15-2024 18:36:18

Thanks for source code


Happy

March-27-2024 11:24:33

Thanks for this


Share your thoughts about this post

Why Choose Us:

Experienced Instructors: Our team of experienced instructors are passionate about coding and dedicated to helping you succeed. With years of industry experience and a knack for teaching, they'll guide you every step of the way. Beginner-Friendly Content: Don't worry if you're new to coding. Our tutorials are designed with beginners in mind, starting from the fundamentals and gradually building up to more advanced topics. Updated Content: Coding is a rapidly evolving field, and we're committed to keeping our content up-to-date with the latest trends, technologies, and best practices. Community Support: Learning to code is more fun and effective when you're part of a supportive community. Join our online community forums to connect with fellow learners, share insights, and collaborate on projects. Get Started Today: Ready to kickstart your coding journey? Subscribe to [Rupesh-Tech] on YouTube and start learning today! Don't forget to hit the bell icon to receive notifications whenever we upload new tutorials or go live with Q&A sessions. Remember, coding opens up a world of endless possibilities. Whether you're dreaming of becoming a software developer, launching your own startup, or simply exploring a new hobby, [Rupesh-Tech] is here to help you turn your coding aspirations into reality. Let's code together and unleash your full potential! Feel free to customize the content to better suit Rupesh-tech channel's branding and audience.



Recent Posts

IMAGE CRUD PHP MYSQL

September-04-2024 09:18:37


complete php project mysql

August-11-2024 11:31:12


LARAVEL 11 crud step by step

August-02-2024 23:22:25