Jump to content

jadprash

New Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by jadprash

  1. I have posted three files one is .htaccess, search.php and header.php. Inside header.php I have a form that redirects to search.php. Basically, I am trying to make SEO friendly URL my current URL displays as example.com/blog/search.php?keyword=a expected result should be example.com/blog/search/a and example.com/blog/search.php?keyword=a&page=2 expected result should be example.com/blog/search/a/page/2. I have tried changing the .htaccess file and location in search.php but it doesn't work any solution, please. htaccess file RewriteRule ^search/([^/.]+)/page/([^/.]+)?$ search.php?keyword=$1&pn=$2 [L] header.php <?php if (isset($_GET['keyword'])) { $keyword = $_GET['keyword']; } else { $keyword = ""; } ?> <form class="d-flex" method="GET" action="search.php"> <input type="search" placeholder="Search" value="<?php echo $keyword; ?>" name="keyword" maxlength="70" autocomplete="off" required class="form-control me-sm-2"> <button class="btn btn-secondary my-2 my-sm-0" type="submit"><i class="fa fa-search" aria-hidden="true"></i></button> </form> search.php <? session_start(); include 'header.php'; //include 'config.php'; //pagination $keyword = $_GET['keyword']; if (empty($keyword)) { header("location: index.php"); } else{header("location: search/".$keyword); } if (!isset($_GET['page'])) { $page = 1; } else { $page = $_GET['page']; } $limit = 2; $offset = ($page - 1) * $limit; //pagination ends $sql = "SELECT * FROM blog LEFT JOIN categories ON blog.category=categories.cat_id LEFT JOIN users ON blog.author_id=users.user_id WHERE blog_title LIKE :keyword or blog_body LIKE :keyword ORDER BY published_date DESC LIMIT $offset,$limit"; $stmt = $conn->prepare($sql); $stmt->bindValue(':keyword', '%' . $keyword . '%', PDO::PARAM_STR); $stmt->execute(); $res = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> <div class="container mt-2"> <h3>Search result for:<span class="text-primary"><?php echo $keyword ?></span></h3> <div class="row"> <div class="col-lg-8"> <hr> <?php if ($res) { foreach ($res as $result) { ?> <div class="card shadow"> <div class="card-body d-flex blog_flex"> <div class="flex-part1"> <a href="../../blog/sp/<?php echo $result['blog_id']; ?>"> <img src="<?php echo base_url('admin/upload/').$result['blog_image']; ?>"> </a> </div> <div class="flex-grow-1 flex-part2"> <a href="single_post.php?id=<?php echo $result['blog_id']; ?>" id="title"><?php echo ucfirst($result['blog_title']); ?></a> <p> <a href="" id="body"> <?php echo strip_tags(substr($result['blog_body'], 0, 200)) . '...'; ?> </a> <span><br> <a href="../../../blog/sp/<?php echo $result['blog_id']; ?>" class="btn btn-sm btn-outline-primary">Continue Reading </a></span> </p> <ul> <li class="me-2"><a href=""> <span> <i class="fa fa-pencil-square-o" aria-hidden="true"></i></span><?php echo $result['username'] . '... '; ?></a> </li> <li class="me-2"> <a href=""> <span><i class="fa fa-calendar-o" aria-hidden="true"></i></span> <?php echo date("d-m-y", strtotime($result["published_date"])) . '... '; ?> </a> </li> <li> <a href="category.php?id=<?php echo $result['cat_id']; ?>" class="text-primary"> <span><i class="fa fa-tag" aria-hidden="true"></i></span> <?php echo $result['cat_name']; ?> </a> </li> </ul> </div> </div> </div> <?php } } else { echo "<h5 class='text-danger'>No record Found</h5>"; } ?> <!-- Pagination begins --> <?php $pagination = "SELECT * FROM blog WHERE blog_title LIKE :keyword or blog_body LIKE :keyword"; $run_q = $conn->prepare($pagination); $run_q->bindValue(':keyword', '%' . $keyword . '%', PDO::PARAM_STR); $run_q->execute(); $arr = $run_q->fetchAll(PDO::FETCH_ASSOC); $total_post = count($arr); $pages = ceil($total_post / $limit); if ($total_post > $limit) { ?> <ul class="pagination pt-2 pb-5"> <?php for ($i = 1; $i <= $pages; $i++) { ?> <li class="page-item <?php echo ($i == $page) ? $active = "active" : ""; ?>"> <a href="search.php?keyword=<?php echo $keyword ?>&page=<?php echo $i ?>" class="page-link"><?php echo $i ?></a> </li><?php } ?> </ul> <?php } ?> </div> <?php include 'sidebar.php'; ?> </div> </div> <?php include 'footer.php'; ?>
  2. **script.js** $(function(){ $('.form').on('submit', function(e){ e.preventDefault(); $form = $(this); submitForm($form); }); $('.register').on('submit', function(e){ e.preventDefault(); $reg = $('.register'); registerForm($reg); }); }); function submitForm($form){ $footer = $form.parent('.modal-body').next('.modal-footer'); $footer.html('<img src="public/images/ajax-loader.gif">'); $.ajax({ url: $form.attr('action'), method: $form.attr('method'), data: $form.serialize(), success: function(response){ response = $.parseJSON(response); if(response.success){ if(!response.signout){ setTimeout(function(){ $footer.html( response.message ); window.location = response.url; },5000); } $footer.html( response.message ); } else if(response.error){ $footer.html( response.message ); } console.log(response); } }); } function registerForm($form){ $footer = $form.parent('.modal-body').next('.modal-footer'); $footer.html('<img src="public/images/ajax-loader.gif">'); var data = new FormData(this.form); $.ajax({ url: $form.attr('action'), method: $form.attr('method'), data: data, processData: false, contentType: false, success: function(response){ response = $.parseJSON(response); if(response.success){ if(!response.signout){ setTimeout(function(){ $footer.html( response.message ); window.location = response.url; },5000); } $footer.html( response.message ); } else if(response.error){ $footer.html( response.message ); } console.log(response) } }); } **auth.php** <?php require_once 'includes/init.php'; $status = $user->login($_POST, $db); if( $status === 'success'){ echo json_encode([ 'success'=> 'success', 'message'=> '<p class="alert alert-success">Authenticated successfully!</p>', 'url' => 'profile.php', ]); } else if( $status === 'missing_fields'){ echo json_encode([ 'error'=> 'error', 'message'=> '<p class="alert alert-danger">All fields mandatory!</p>', ]); } else if( $status === 'error'){ echo json_encode([ 'error'=> 'error', 'message'=> '<p class="alert alert-danger">Incorrect email or password!</p>' ]); } **signup.php** <?php require_once 'includes/init.php'; $status = $user->signup($_POST, $db); if( $status === 'success'){ echo json_encode([ 'success'=> 'success', 'message'=> '<p class="alert alert-success">You are signed up successfully!</p>', //'url' => 'index.php', 'signout' => 1, ]); }else if( $status === 'missing_fields'){ echo json_encode([ 'error'=> 'error', 'message'=> '<p class="alert alert-danger">All fields mandatory!</p>', ]); }else if( $status === 'invalid format'){ echo json_encode([ 'error'=> 'error', 'message'=> '<p class="alert alert-danger">Only jpg,jpeg,pngfiles allowed!</p>', ]); }else if( $status === 'error'){ echo json_encode([ 'error'=> 'error', 'message'=> '<p class="alert alert-danger">Failed to sign you up!</p>' ]); } ?> **user.php** class User{ public function login($user, $db){ if(empty($user['email']) OR empty($user['password'])){ return 'missing_fields'; } $sql = "SELECT * FROM `users` WHERE `email`=?"; $statement = $db->prepare($sql); if( is_object($statement) ){ $statement->bindParam(1, $user['email'], PDO::PARAM_STR); $statement->execute(); if($row = $statement->fetch(PDO::FETCH_OBJ)){ // you the database and verify if the password and email match or not if(password_verify($user['password'], $row->password)){ $_SESSION['logged_in'] = [ 'id' => $row->id, 'name' => $row->name, ]; return 'success'; } } } I have the below files...which has two form login and register(haven't posted the form part) forms are action to auth.php and signup.php respectively and validate through user.php, everything works perfectly on login. However, when I register the user with name and image the success message get on the URL page, not on the modal-footer div I want to update the message in footer DOM, which is div modal-footer. I am using two different functions in script.js one has a data value of $.form.serialize, which handles the login part and Formdata handles the registration part....please guide to update the success message on the modal-footer div......Thanks.
  3. Even if I remove the message it will go to the sign up. php page. Sign.php validated the form and should display the messages inside the model-footer div....
  4. $(function(){ $('.form').on('submit', function(e){ e.preventDefault(); $form = $(this); submitForm($form); $reg = $('register'); registerForm($reg); }); $('#forgot-password').on('click', function( e ){ e.preventDefault(); $('#login').modal('hide'); }); }); function submitForm($form){ $footer = $form.parent('.modal-body').next('.modal-footer'); $footer.html('<img src="public/images/ajax-loader.gif">'); $.ajax({ url: $form.attr('action'), method: $form.attr('method'), data: $form.serialize(), success: function(response){ response = $.parseJSON(response); if(response.success){ if(!response.signout){ setTimeout(function(){ $footer.html( response.message ); window.location = response.url; },5000); } $footer.html( response.message ); } else if(response.error){ $footer.html( response.message ); } console.log(response) } }); } function registerForm($form){ $footer = $form.parent('.modal-body').next('.modal-footer'); $footer.html('<img src="public/images/ajax-loader.gif">'); var data = new FormData('register'); $.ajax({ url: $form.attr('action'), data: data, type: "POST", processData: false, contentType: false, success: function(response){ response = $.parseJSON(response); if(response.success){ if(!response.signout){ setTimeout(function(){ $footer.html( response.message ); window.location = response.url; },5000); } $footer.html( response.message ); } else if(response.error){ $footer.html( response.message ); } console.log(response) } }); } I have the above jQuery file, which ajaxify two form login and signup through function submitForm and registerForm. Both the function works properly. However registerForm doesn't ajaxify the success message on model-footer div, which is below form, the message get displayed on url page signup.php. am I accesing the form properly in register function.......please guide....Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.