Monday 8 February 2016

Add class=“active” to active page using PHP

Add class=“active” to active page using PHP:

<ul id="mainnav">
    <li class="<?php if ($first_part=="") {echo "active"; } else  {echo "noactive";}?>"><a href="#">Home</a></li>
    <li class="<?php if ($first_part=="tutorials") {echo "active"; } else  {echo "noactive";}?>"><a href="#">Tutorials</a></li>
    <li class="<?php if ($first_part=="resources") {echo "active"; } else  {echo "noactive";}?>"><a href="#">Resources</a></li>
    <li class="<?php if ($first_part=="library") {echo "active"; } else  {echo "noactive";}?>"><a href="#">Library</a></li>
    <li class="<?php if ($first_part=="our-projects") {echo "active"; } else  {echo "noactive";}?>"><a href="#">Our Projects</a></li>
    <li class="<?php if ($first_part=="community") {echo "active"; } else  {echo "noactive";}?>"><a href="#">Community</a></li>
</ul>
<?php 
$directoryURI = $_SERVER['REQUEST_URI'];
$path = parse_url($directoryURI, PHP_URL_PATH);
$components = explode('/', $path);
$first_part = $components[1];
?>

Tuesday 2 February 2016

Replace the ' from the content


Hi

Any one Can Assist me in this problem.. I have dynamic page, Where I can type and save and edit it is working fine.. But when I copy past any other data from other website site it is giving the below mention error.

Note: When I copy two or three paragraph from other website it is having this error.


Solved: This line is used to replace the ' from the content updated by the user else it will show error while updating the page
Code:  $servicesdetails1 = str_replace("'","\'", $servicesdetails1  );





<?php
if(isset($_POST['update12'])){
$update_id = $_GET['edit_form1'];
    $servicesname1 = $_POST['title'];
    $servicesdetails1 = $_POST['content'];
    $servicesdetails1 = str_replace("'","\'", $servicesdetails1  );
    $servicesimage1= $_FILES['image']['name'];
    $image_tmp= $_FILES['image']['tmp_name'];
if( $servicesname1=='' or $servicesdetails1=='' ){
echo "<script>alert('Any of the fields is empty')</script>";
exit();
}
else {
move_uploaded_file($image_tmp,"../images/$servicesimage1");
$update_query = "update possystem set servicesname='$servicesname1', servicesdetails='$servicesdetails1',servicesimage='$servicesimage1' where id='$update_id'";
if(mysqli_query($conn, $update_query)){






/*echo "<script>alert('Post has been updated')</script>";
*/ echo "<script>window.open('view_possystem.php','_self')</script>";
}
}
}}
?>