Jump to content

uppalakishore

Members
  • Posts

    19
  • Joined

  • Last visited

Posts posted by uppalakishore

  1. Thank u @ trq and l0gic...
    But i slightly confused...
     



    I found a link http://michael.theirwinfamily.net/articles/csshtml/protecting-images-using-php-and-htaccess

     

    I added the following .ht access files to Image directory and to main directory
     
    .htaccess in main folder:

    
    
    
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} ^$
    RewriteCond %{SCRIPT_FILENAME} image\.php
    RewriteRule (.*) image.php?onlyHappensFromHTACCESS=denied [QSA,L]
    

    .htaccess in Images folder:

    
    #Prevent directory listing
    Options -Indexes
    #Prevent images from being viewed
    <Files *>
      deny from all
    </Files>
    

    image.php:



     
    <?php
    if (!isset($_GET['onlyHappensFromHTACCESS'])) {
       $_GET['f'] = "./Images/" . $_GET['f'];                            //my folder name="Images";
        $type = getFileType($_GET['f']);
        if (acceptableType($type)) {
            if (goodTiming()) {
                header("Content-type: $type");
             echo file_get_contents($_GET['f']);
                exit;
            }
        }
        header('HTTP/1.1 403 Forbidden');
        exit;
    }
    function getFileType($file) {
      if (function_exists("mime_content_type"))
        return mime_content_type($file);
      else if (function_exists("finfo_open")) {
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $type = finfo_file($finfo, $file);
        finfo_close($finfo);
        return $type;
      }
      else {
        $types = array(
          'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png',
          'gif' => 'image/gif', 'bmp' => 'image/bmp'
        );
        $ext = substr($file, strrpos($file, '.') + 1);
        if (key_exists($ext, $types)) return $types[$ext];
        return "unknown";
      }
    }
    function acceptableType($type) {
        $array = array("image/jpeg", "image/jpg", "image/png", "image/png", "image/gif");
        if (in_array($type, $array))
            return true;
        return false;
    }
    function goodTiming() {
        $n = time();
        session_start();
        if ($n - $_SESSION['lastcheck'] > 2 )
            return false;
        return true;
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
      <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
      <title>Image Denied</title>
      <style type="text/css" media="screen">
        body {
            background-color: #ccc;
            font-family: Helvetica, Arial;
        }
        #wrapper {
            margin: 30px auto;
            background-color: #ffffff;
            -moz-border-radius: 15px;
            -webkit-border-radius: 15px;
            border-radius: 15px;
            width: 800px;
            padding: 20px;
        }
      </style>
    </head>
    <div id="wrapper">
      <h3>Access Denied!</h3>
      You have tried to access an image, but due to security reasons, you cannot view the image.
      If you wish to use the image you requested, please contact me.
    </div>
    </html>



    index1.php:


     
    <?php session_start(); $_SESSION['lastcheck'] = time(); ?>
    <html>
    <head>
        <title>Page Title</title>
        <style type="text/css">
            .image {
                overflow: hidden;
                position: relative;
                float: left;
            }
            .image .cover, .image .cover img {
                position: absolute;
                top: 0px;
                left: 0px;
                width: 100%;
                height: 100%;
            }
        </style>
    </head>
    <body>
        <div class="image">
            <img src="image.php?f=f3.jpg" alt="Image" />
            <div class="cover"><img src="Transparent.gif" alt=""  /></div>
        </div>
    </body>
    </html>
    



    I got the output as Transparent.gifTransparent.gif"Image"(Means alt will be loaded)...
    when i right click on it,and select View Image "Transparent.gif" will be displaying normally.
     
    I can't understant what is the problem here...
    Transparent.gif
  2. The above code is working fine in case of a particular image like

    freak_test.php?image=f3.jpg (The code is saved in a page "freak_test.php")

    In case of,

    <img src="freak_test.php?image=f3.jpg" width=200 height=300 />

    It will not displaying the image

    And when Right click on the image and click "View Image" it displays the following error

     

    Deprecated: Function eregi() is deprecated in F:\xampp\htdocs\photo_gallery\User_data\User_details\freak_test.php

     

    any Suggestions?

  3. @ haku....


    I tried and rename the directory as "Images" but i found it displaying the image path as it is and it will randomize the images in the directory when i refresh the page...

     

    What i want is I want to hide the location/path of the image...

    sum where i got some code i will try it...

     


     

    
    <?php
    
     
      $imagedir = "Images/" ;
    
      $validprefixes = array (
        "http://localhost/photo_gallery/index.com",
        "localhost/photo_gallery/"
      ) ;
    
     
      $homepage = "index.php" ;
    
      function isreferrerokay ( $referrer, $validprefixes )
      {
        $validreferrer = 0 ;
        $authreferrer  = current( $validprefixes );
        while ($authreferrer) {
          if (eregi( "^https?://$authreferrer/", $referrer )) {
            $validreferrer = 1 ;
            break ;
          }
          $authreferrer = next( $validprefixes );
        }
        return $validreferrer ;
      }
    
      //----------------------- main program -----------------------
    
      $image = $_GET['image'] ;
      $referrer = getenv( "HTTP_REFERER" );
    
      if (isset($_GET['image'])) {
    
        if (empty($referrer) ||
          isreferrerokay( $referrer, $validprefixes )) {
    
          $imagepath = $imagedir . $image ;
    
          $imageinfo = getimagesize( $imagepath );
          if ($imageinfo[2] == 1) {
            $imagetype = "gif" ;
          }
          elseif ($imageinfo[2] == 2) {
            $imagetype = "jpeg" ;
          }
          elseif ($imageinfo[2] == 3) {
            $imagetype = "png" ;
          }
          else {
            header( "HTTP/1.0 404 Not Found" );
            exit ;
          }
    
          header( "Content-type: image/$imagetype" );
          @readfile( $imagepath );
    
        }
        else {
    
          if (isset($email)) {
            mail( $email, "Bandwidth Theft Alert",
               "WARNING:\n\n$referrer\ntried to access\n$image\n",
               "From: CHImageGuard <$email>" );
          }
          header( "HTTP/1.0 404 Not Found" );
        }
      }
      else {
        header( "Location: $homepage" );
      }
    
    ?>
     
    
  4. First of All Thanks For Reading...

     

    I Want to hide Image/File path, mainly i want to hide the "image path" there by Logged in users only see the images.

     

    1) My Problem is When a user Logged in and opend his personal photos, the image path will be "http://localhost/photo_gallery/User_data/Personal_photos/username/kicku.jpg" .

     

    2)But when i entered the path in the browser  without login the images keep displaying...

     

    3)So i want to hide the image path for security purpose...

     

    Any help, Appreciable...

     

     

  5. Thanks For ur Reply @

    Christian F...


    I Solved it...as follows:

     

    
    $mail=new PHPMailer();
    
    $mail->IsSMTP();                   //Important b'coz by this stmt we sent mail using smtp
    $mail->SMTPAuth = true;       // enable SMTP authentication
    $mail->SMTPSecure = "ssl";  // sets the prefix to the servier
    $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
    $mail->Port = 465; // set the SMTP port for the GMAIL server
    $mail->Username = "yourmail@gmail.com"; // GMAIL username
    $mail->Password = "your mail password"; // GMAIL password
    
    $mail->FromName = "PhotoGallery:Admin";
    $mail->From = "from address@gmail.com";
    $mail->AddAddress($to,$to_name);
    $mail->Subject = $subject;
    
    $mail->Body ="body of the message";
    $result=$mail->Send();
        return $result;

     

     

     

     

     

  6. When i run the following code,it will shows the error...


    Mail error: The following From address failed: uppalakishore@hotmail.com : Called Mail() without being connected


    <?php
    require_once("./Includes/PHPMailer/class.phpmailer.php");
    //	require_once("./Includes/PHPMailer/class.smtp.php");
    define('GUSER', 'myname@gmail.com'); // GMail username
    define('GPWD', 'mypassword'); // GMail password
    function smtpmailer($to, $from, $from_name, $subject, $body) { 
    	global $error;
    	$mail = new PHPMailer();  // create a new object
    	$mail->IsSMTP(); // enable SMTP
    	$mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    	$mail->SMTPAuth = true;  // authentication enabled
    	$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    	$mail->Host = 'smtp.gmail.com';
    	$mail->Port = 465; 
    	$mail->Username = GUSER;  
    	$mail->Password = GPWD;           
    	$mail->SetFrom($from, $from_name);
    	$mail->Subject = $subject;
    	$mail->Body = $body;
    	$mail->AddAddress($to);
    	if(!$mail->Send()) {
    		$error = 'Mail error: '.$mail->ErrorInfo; 
    		return false;
    	} else {
    		$error = 'Message sent!';
    		return true;
    	}
    }
    if (smtpmailer('myname@gmail.com', 'uppalakishore@hotmail.com', 'PHotoGallery', 'test mail message', 'Hello World!')) {
    	// do something
    }
    if (!empty($error)) echo $error;
    ?>
    

     

    Thanks in Advance For Watching...

  7. Thank You Christian F...

     

    I had simple client and server socket programs, the client sends a message to server, then the server reverses the string(sent by client) and send it to server.

    Client.php

    [bR]

    <?php
    $host = "127.0.0.1";
    $port = 80;
    
    [color=#ff0000][b]$message ="Hello world";[/b][/color]
    echo "<br>\nMessage To server :".$message."\n";
    // create socket
    $socket = socket_create(AF_INET, SOCK_STREAM, 0) or
    die("Could not create socket\n");
    if($socket)echo "<br>Client Socket Created\n";
    //
    //// connect to server
    $result = socket_connect($socket, $host, $port) or
    die("Could not connect to server\n");
    if($result)echo "<br>Socket Connected to Server : $host on Port : $port\n";
    //
    //while(1){
    // send string to server
    echo "<br>Sending Data to the Server...\n";
    sleep(1);
    socket_write($socket, $message, strlen($message)) or
    die("Could not send data to server\n");
    //
    // get server response
    echo "<br>Getting Responce From the Server...\n";
    sleep(1);
    $result = socket_read ($socket, 1024) or die("Could
    //not read server response\n");
    echo "Reply From Server :".$result;
    //}
    // close socket
    socket_close($socket);
    
    ?>
    

     

    Server.php

    [bR]

    <?php
    // set some variables
    $host = "127.0.0.1";
    $port = 80;
    // don't timeout!
    set_time_limit(0);
    // create socket
    $socket = socket_create(AF_INET, SOCK_STREAM, 0) or
    die("Could not create socket\n");
    if($socket)echo "<br>Socket Created\n";
    // bind socket to port
    $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
    if($result)echo "<br>Socket Binded\n";
    // start listening for connections
    $result = socket_listen($socket, 3) or die("Could not
    set up socket listener\n");
    if($result)echo "<br>Socket Listening Connections....\n";
    // accept incoming connections
    // spawn another socket to handle communication
    $spawn = socket_accept($socket) or die("Could not
    accept incoming connection\n");
    if($spawn)echo "<br>Socket Accepted Incoming Connections...\n";
    //while(1){
    // read client input
    echo "<br>\nReading Input...\n";
    sleep(1);
    $input = socket_read($spawn, 2048) or die("Could not
    read input\n");
    
    // clean up input string
    $input = trim($input);
    echo "<br>Client Message : ".$input;
    // reverse client input and send back
    $output = strrev($input) . "\n";
    echo "<br>\nResponce...\n";
    sleep(1);
    socket_write($spawn, $output, strlen ($output)) or
    die("Could not write output\n");
    //}
    // close sockets
    socket_close($spawn);
    socket_close($socket);
    ?>
    

     

    The program is executed, the problem is i want to enter that message into database using server program...I can't get any idea how to do that...

     

    Thanks in Advance...

  8. Suppose i had a Registration Form with multiple fileds(like first name,last name etc).And i want to enter the entered values into MySql using Sockets...

     

    I need the example showing inserting data into Mysql using sockets.Bcoz i learned something about php sockets but i don't have the basic idea how to implement them...Even i tried so many examples but i tired of having so many complexities like socket_bind,socket_accept,socket_listen errors...

     

    THANKS IN ADVANCE...

  9. CTRL + Q to Enable/Disable GoPhoto.it

    I think, the Problem might be here:


    session_start();
    if (isset($_POST['disciplines'])) $_SESSION['dis']=$_POST['disciplines'];


     

    [code]
    <html>
    <body>
     <a href="home.php" align="left" style="text-decoration:none;font:verdana;color:red;padding: 5px;margin-left:40px;"><button class="btn" onclick="javascript:location.href='home.php'" class="btn" style="font-weight: bold;">Home Page</button></a>
     <button class="btn" onclick="history.go(-1);return true;">Go Back</button>
    
     <?php
    //					 // Make sure that PATH_INFO is set, and not ORIG_PATH_INFO as some hosts seem to use.
    //					 if (isset ($_SERVER['ORIG_PATH_INFO']) && $_SERVER['ORIG_PATH_INFO'] != $_SERVER['PHP_SELF']) {
    //					 $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
    //					 }
    //
    //					 // Security measure, to avoid XSS exploit.
    //					 if (!empty ($_SERVER['PATH_INFO']) && strrpos ($_SERVER['PHP_SELF'], $_SERVER['PATH_INFO'])) {
    //
    //
    //
    //					 $_SERVER['PHP_SELF'] = substr ($_SERVER['PHP_SELF'], 0, -(strlen ($_SERVER['PATH_INFO'])));
    //					 }
    
    session_start();
     if (isset($_POST['disciplines'])) $_SESSION['dis']=$_POST['disciplines'];
    				 include('db_connect.php');
    				 // how many rows to show per page
    				 $rowsPerPage = 4;
    				 // by default we show first page
    				 $pageNum = 1;
    				 // if $_GET['page'] defined, use it as page number
    				 if(isset($_GET['page']))
    				 {
    					 $pageNum = $_GET['page'];
    				 }
    				 // counting the offset,example we want 5 rows per page,offset=(1-1)*5=0(means 0 to 5 rows on first page,(2-1)*5=5(5 to 5 on second page)
    				 $offset = ($pageNum - 1) * $rowsPerPage;
    				 $result=mysql_query("select * from student_master where Disciplines='" . mysql_real_escape_string($_SESSION['dis']) . "' LIMIT $offset,$rowsPerPage") or die('Error : '. mysql_error());
    				 $result2=mysql_query("select count(*) from student_master where Disciplines='".mysql_real_escape_string($_SESSION['dis'])."'");
    					 echo "<table align='right'><tr><td><fieldset border='1' class='fieldmoz'>Total ".mysql_real_escape_string($_SESSION['dis'])." Students = <font color='red' ><b>".mysql_result($result2,0)."</fieldset></b></font></td></tr></table>
    							 <center><h2 align='center' class='spl_heading'><font color=green>".mysql_real_escape_string($_SESSION['dis'])."</font> Students Details : </h2></center>
    								 <table width='70%' cellpadding='2' cellspacing='2' border='1' align='center'>
    							 <tr class='fade_bg' align='center'>
    							 <td class='spl_bgcolor'>Enrollment No</td>
    							 <td>Name</td>
    
    							 <td>Discipline</td>
    
    							 <td>Year</td>
    
    							 <td>Photo</td>
    							 </tr>";
    					 while($row=mysql_fetch_row($result))
    					 {
    						 echo " <tr class='sp_table_row'>
    								 <td class='span' width='16%' align='center'><a class='underline' href='all_click_details.php?En_no=$row[0]'>$row[0]</a></td>
    								 <td width='20%'>$row[1]</td>
    
    								 <td align='center' width='10%'>$row[4]</td>
    
    								 <td width='10%' align='center'>$row[7]</td>
    
    								 <td width='6%' align='center'><img src='upload/$row[9]' alt='$row[1]' title='$row[1]' align='center' style='-moz-border-radius:4px;' class='magnify' data-magnifyduration='800' width='90' height='110'></td>
    
    						 </tr>";
    					 }
    						 echo "<tfoot><tr><td colspan=10><marquee behavior='alternate' scrollamount='3' align='center' class='yellow'>Click on Image to Enlarge & Resize</marquee></td></tr></tfoot>
    							 </table><br>
    							 ";
    
    							 // how many rows we have in database
    							 $result1=mysql_query("select count(Disciplines) from student_master where Disciplines='".mysql_real_escape_string($_SESSION['dis'])."'");
    							 $row=mysql_fetch_row($result1);
    							 $numrows=$row[0];
    						 // how many pages we have when using paging?
    						 $maxPage = ceil($numrows/$rowsPerPage);
    						 // print the link to access each page
    						 $self = $_SERVER['PHP_SELF'];
    						 $nav = '';
    						 for($page = 1; $page <= $maxPage; $page++)
    						 {
    							 if ($page == $pageNum)
    							 {
    								 $nav .= " <span class='bgc'><b> $page </span> |</b>"; // no need to create a link to current page
    							 }
    							 else
    							 {
    								 $nav .= " <a href=\"$self?page=$page\">$page</a> <b>|</b>";
    							 }
    						 }
    						 // ... still more code coming
    						 if ($pageNum > 1)
    						 {
    							 $page = $pageNum - 1;
    							 $prev = " <a href=\"$self?page=$page\">[Prev]</a> <b>|</b>";
    							 $first = " <a href=\"$self?page=1\">[First Page]</a>";
    						 }
    						 else
    						 {
    							 $prev = ' '; // we're on page one, don't print previous link
    							 $first = ' '; // nor the first page link
    						 }
    						 if ($pageNum < $maxPage)
    						 {
    							 $page = $pageNum + 1;
    							 $next = " <a href=\"$self?page=$page\">[Next]</a> <b>|</b>";
    							 $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a>";
    						 }
    						 else
    						 {
    							 $next = ' '; // we're on the last page, don't print next link
    							 $last = ' '; // nor the last page link
    						 }
    						 // print the navigation link
    						 echo "<div class='pager'><center>".$first . $prev . $nav . $next . $last."</center></div>";
    						 echo "<center><br><button onclick='javascript:window.print()' value=''class='btn' style='width:100;height:25;'>Print</button></center>";
    						 // and close the database connection
    						 mysql_close();
    
    					 ?>
    </body>
    </html>
    

     


    When i run the above code it will give correct results in one system,when i run it on my laptop it won't produce the same result....i think there might be an error in passing SESSION VARIABLES to the next page.(B'Coz when i click on next page it will display empty page with table headers ony...

    I can't understand whether it is coding problem or my Laptop OS Problem(b'coz it will run correctly on other system)....

  10. I tried the following code by applying SESSION (Some times working properly) but i got the Error,Means it will executed in one system and it won't work in other system


     

    session_start();
    if (isset($_POST['disciplines'])) $_SESSION['dis']=$_POST['disciplines'];
    include('db_connect.php');
    $rowsPerPage =4;
    
    // by default we show first page
    $pageNum = 1;
    
    // if $_GET['page'] defined, use it as page number
    if(isset($_GET['page']))
    {
    $pageNum = $_GET['page'];
    }
    
    // counting the offset
    $offset = ($pageNum - 1) * $rowsPerPage;
    
    $result=mysql_query("select * from student_master where Disciplines='" . mysql_real_escape_string($_SESSION['dis']) . "' LIMIT $offset,$rowsPerPage");
    if(mysql_num_rows($result)>0)
    {
    echo "
    ".mysql_real_escape_string($_SESSION['dis'])." Students Details :
    
    
    
    
    
    
    
    
    
    
    
    
    ";
    while($row=mysql_fetch_row($result))
    {
    echo "
    
    
    
    
    
    
    
    
    
    
    ";
    
    }
    echo "
    
    Enrollment No    Name    Father's Nname    Address    Discipline    Semester    Year    Email    Mobile Number    Photo
    $row[0]    $row[1]    $row[2]    $row[3]    $row[4]    $row[5]    $row[7]    $row[6]    $row[8]    Upload Image
    Click on Image to Enlarge & Resize
    
    
    
    ";
    // how many rows we have in database
    $query = "SELECT COUNT(En_no) AS numrows FROM student_master where Disciplines='".mysql_real_escape_string($_SESSION['dis'])."'";
    $result1 = mysql_query($query) or die('Error, query failed');
    $row = mysql_fetch_array($result1, MYSQL_ASSOC);
    $numrows = $row['numrows'];
    
    // how many pages we have when using paging?
    $maxPage = ceil($numrows/$rowsPerPage);
    
    // print the link to access each page
    $self = $_SERVER['PHP_SELF'];
    $nav = '';
    
    for($page = 1; $page <= $maxPage; $page++)
    {
    if ($page == $pageNum)
    {
    $nav .= "  $page  "; // no need to create a link to current page
    }
    else
    {
    $nav .= " $page ";
    }
    }
    
    // ... still more code coming
    if ($pageNum > 1)
    {
    $page = $pageNum - 1;
    $prev = " [Prev] ";
    
    $first = " [First Page]";
    }
    else
    {
    $prev = ' '; // we're on page one, don't print previous link
    $first = ' '; // nor the first page link
    }
    
    if ($pageNum < $maxPage)
    {
    $page = $pageNum + 1;
    $next = " [Next] ";
    
    $last = " [Last Page]";
    }
    else
    {
    $next = ' '; // we're on the last page, don't print next link
    $last = ' '; // nor the last page link
    }
    
    // print the navigation link
    echo "
    ".$first . $prev . $nav . $next . $last."
    ";
    echo "
    To search again,Click here . . .
    ";
    }
    else
    {
    echo "
    Error Occured. Try Again . . .
    
    ";
    }
    
    
    ?>


     

    When i Run the above code i got that the error was in the following line....

     


     

    "select * from student_master where Disciplines='" . mysql_real_escape_string($_SESSION['dis']) . "' LIMIT $offset,$rowsPerPage"

     

    And Thanks In Advance...

  11. I'm sory  :shy: to say this...i don't know how to avoid $_SERVER['PHP_SELF'],and it is linked with Overall pages.....

     


    // print the link to access each page
                            $self = $_SERVER['PHP_SELF'];
                            $nav  = '';
    
                            for($page = 1; $page <= $maxPage; $page++)
                            {
                            if ($page == $pageNum)
                            {
                                $nav .= "  <span class='bgc'><b> $page </b></span> "; // no need to create a link to current page
                            }
                            else
                            {
                                $nav .= "  <a href=\"$self?page=$page\">$page</a> ";
                            }
                            }
    
                            // ... still more code coming
                            if ($pageNum > 1)
                            {
                            $page  = $pageNum - 1;
                            $prev  = "  <a href=\"$self?page=$page\">[Prev]</a> ";
    
                            $first = "  <a href=\"$self?page=1\">[First Page]</a>";
                            }
                            else
                            {
                            $prev  = ' '; // we're on page one, don't print previous link
                            $first = ' '; // nor the first page link
                            }
    
                            if ($pageNum < $maxPage)
                            {
                            $page = $pageNum + 1;
                            $next = "  <a href=\"$self?page=$page\">[Next]</a> ";
    
                            $last = "  <a href=\"$self?page=$maxPage\">[Last Page]</a>";
                            }
                            else
                            {
                            $next = ' '; // we're on the last page, don't print next link
                            $last = ' '; // nor the last page link
                            }
    
                            // print the navigation link
                            echo "<div class='pager'><center>".$first  .  $prev  .  $nav  .  $next  .  $last."</center></div>";
    


     

    Will Please tell me how :confused: to do it......There by pagination will work fine......////////First page works fine but when i click on next page nothing will come.....

     

    when i use session_start(), it shows error headers already sent...

     


    Thanks For Your Reply....


     

  12. Actually i'm New here...

     

    And i think the error might be here(following):

     

    ////////////// Main Query to get Students belongs to a Particular Department(discipline) /////////

                            $dis=$_POST['disciplines'];

                            @session_start();

                            $_SESSION['dis']=$_POST['disciplines'];

                            $result=mysql_query("select * from student_master where Disciplines='".$_SESSION['dis']."' LIMIT $offset,$rowsPerPage");

                            if(mysql_num_rows($result)>0)

                            {

                                      //print some table headings

                                      while($row=mysql_fetch_row($result))

                                      {

                                          //print some table rows

                                      }

                                        // how many rows we have in database to print for PAGINATION

                                    include('db_connect.php');  //to establish database connection

                                    $query  = "select COUNT(Disciplines) AS numrows FROM student_master where Disciplines='".$_SESSION['dis']."'";

                                    $result2  = mysql_query($query) or die('Error, query failed');

                                    $row  = mysql_fetch_array($result2,MYSQL_ASSOC);

                                    $numrows = $row['numrows'];

     

                                  //place some pagination links

                              }

                              else

                              {

                                  echo "Error Occurd"

                                }

     

     

    When i run the program first page working fine...when i click on next page it will show msg "Error Occurd"(which is showd in blue color as a else stmt)...i think it may be a session variable problem but i don't know how to rectify it...

    THANKS FOR UR REPLY

  13. I want to display 4 records per page by using pagination on clicking "showdetails2.php"...Everything will be working fine but when i click on next page...it shows error.....

     

     

    Simply what i want is i want to display 4 records per page(menas 4 students of each department)

     

    ///////////////////////////////////////////////

     

     

     

    <?php

                            include('db_connect.php');

                            $rowsPerPage =4;

     

                            // by default we show first page

                            $pageNum = 1;

     

                            // if $_GET['page'] defined, use it as page number

                            if(isset($_GET['page']))

                            {

                                $pageNum = $_GET['page'];

                            }

     

                            // counting the offset

                            $offset = ($pageNum - 1) * $rowsPerPage;

                            @session_start();

                            $_SESSION['dis']=$_POST['disciplines'];

                            $result=mysql_query("select * from student_master where Disciplines='".$_SESSION['dis']."' LIMIT $offset,$rowsPerPage ");

                            if(mysql_num_rows($result)>0)

                            {

                                echo "

                                        <h2 align='center' class='spl_heading'><font color=green>".$_SESSION['dis']."</font> Students Details : </h2>

                                        <table width='98%' cellpadding='2' cellspacing='2' border='1' align='center'>

                                        <tr class='fade_bg' align='center'>

                                        <td class='spl_bgcolor'>Enrollment No</td>

                                        <td>Name</td>

                                        <td>Father's Nname</td>

                                        <td>Address</td>

                                        <td>Discipline</td>

                                        <td>Semester</td>

                                        <td>Year</td>

                                        <td>Email</td>

                                        <td>Mobile Number</td>

                                        <td>Photo</td></tr>";

                                while($row=mysql_fetch_row($result))

                                {

                                    echo "  <tr class='sp_table_row'>

                                            <td class='spl_bgcolor'style='color:fcc;' width='16%' align='center'>$row[0]</td>

                                            <td width='30%'>$row[1]</td>

                                            <td width='25%'>$row[2]</td>

                                            <td width='25%'>$row[3]</td>

                                            <td width='10%'>$row[4]</td>

                                            <td width='15%'>$row[5]</td>

                                            <td width='10%'>$row[7]</td>

                                            <td width='35%'>$row[6]</td>

                                            <td width='20%'>$row[8]</td>

                                            <td><img src='upload/$row[9]' alt='Upload Image' align='center' style='-moz-border-radius:4px;' class='magnify' data-magnifyduration='800' width=80 height=110></td>

                                        </tr>";

     

                                }

                                    echo "<tfoot><tr><td  colspan=10><marquee behavior='alternate' scrollamount='3' class='yellow'>Click on Image to Enlarge & Resize</marquee></td></tr></tfoot>

     

                                        </table><br>

                                        ";

                                                // how many rows we have in database

                            $query  = "SELECT COUNT(En_no) AS numrows FROM student_master where                                                                                    Disciplines='".$_SESSION['dis']."'";

                            $result1  = mysql_query($query) or die('Error, query failed');

                            $row    = mysql_fetch_array($result1, MYSQL_ASSOC);

                            $numrows = $row['numrows'];

     

                            // how many pages we have when using paging?

                            $maxPage = ceil($numrows/$rowsPerPage);

     

                            // print the link to access each page

                            $self = $_SERVER['PHP_SELF'];

                            $nav  = '';

     

                            for($page = 1; $page <= $maxPage; $page++)

                            {

                            if ($page == $pageNum)

                            {

                                $nav .= "  <span class='bgc'><b> $page </b></span> "; // no need to create a link to current page

                            }

                            else

                            {

                                $nav .= "  <a href=\"$self?page=$page\">$page</a> ";

                            }

                            }

     

                            // ... still more code coming

                            if ($pageNum > 1)

                            {

                            $page  = $pageNum - 1;

                            $prev  = "  <a href=\"$self?page=$page\">[Prev]</a> ";

     

                            $first = "  <a href=\"$self?page=1\">[First Page]</a>";

                            }

                            else

                            {

                            $prev  = ' '; // we're on page one, don't print previous link

                            $first = ' '; // nor the first page link

                            }

     

                            if ($pageNum < $maxPage)

                            {

                            $page = $pageNum + 1;

                            $next = "  <a href=\"$self?page=$page\">[Next]</a> ";

     

                            $last = "  <a href=\"$self?page=$maxPage\">[Last Page]</a>";

                            }

                            else

                            {

                            $next = ' '; // we're on the last page, don't print next link

                            $last = ' '; // nor the last page link

                            }

     

                            // print the navigation link

                            echo "<div class='pager'><center>".$first  .  $prev  .  $nav  .  $next  .  $last."</center></div>";

                                    echo "<center>To search again,Click <a href='search_decipline.php' class='btn'><blink><b>here</b></blink></a> . . .</center>";

                            }

                            else

                            {

                                echo "<br><center>Error Occured. <a href='search_decipline.php' class='btn'><blink>Try Again</blink></a> . . . </center>";

                            }

            ?>

     

     

     

    Solve it For me And THANKS IN ADVANCE :o.... :o

    19038_.php

    19039_.php

×
×
  • 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.