Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: examresult  (Read 4879 times)

0 Members and 1 Guest are viewing this topic.

gowthamprabhus

    Topic Starter


    Greenhorn

    • Experience: Familiar
    • OS: Windows 7
    examresult
    « on: July 24, 2013, 05:27:30 PM »
    Hi all..

    I am trying to search a data from the database and trying to display( similar to that of displaying exam result, one will enter his registration number, he will be showed his results)

    Pls help me how to do this.

    I have a Wamp server with database

    i have to search using column name called rollno

    want to display colums called dob, name , email, phone no . All datas i have in database


    Pls help me :(

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: examresult
    « Reply #1 on: July 24, 2013, 07:33:42 PM »
    Is this homework?
    Are you using MySQL ?
    Have you used it before?
    Have you seen this:
    http://www.youtube.com/watch?v=DqEdTWjSnAQ

    gowthamprabhus

      Topic Starter


      Greenhorn

      • Experience: Familiar
      • OS: Windows 7
      Re: examresult
      « Reply #2 on: July 24, 2013, 08:13:09 PM »
      I have wamp server and database already.

      i have used search.php

      its code as follows

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <?php

      if(isset($_POST['submit'])) {
         $srollno = $_POST['srollno'];
         
         $sql1 = mysql_query("SELECT srollno FROM tbl_slamrec WHERE srollno = $srollno");
         $row1 = mysql_num_rows($sql1);
         
         if($row1 == 0) {
            echo 'Error, ID does not exist';
         } else {
            header('Location: show_result.php?srollno='.$srollno);
         }   
      }
      ?>

      <html>
      <head>
      <title>Search</title>
      </head>
      <body>

      <form action="search.php" method="post">
      <input name="srollno" type="text" id="srollno" />
      <input type="submit" name="submit" value="search" />
      </form>
      </body>
      </html>


      and show_result.php

      its code

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <?php


      $srollno = $_GET['srollno'];

      $sql1 = mysql_query("SELECT * FROM tbl_slamrec WHERE srollno = $srollno");
      $row1 = mysql_fetch_array($sql1);
      $rme = $row1['name'];
      $mailme = $row1['marks'];
      ?>

      <html>
      <head>
      <title>Show Results</title>
      </head>
      <body>

      <?php
      echo 'Name = '.$rme.'

      Marks = '.$mailme;
      ?>

      </body>
      </html>




      but i am getting an error

      Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\result\search.php on line 8

      whatt should I do now?

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: examresult
      « Reply #3 on: July 24, 2013, 09:18:33 PM »
      sorry, but I can not help you on this one.
      But, I thin k yhou ought to make some comments about whkat the following line means.
       
      Quote
      $row1 = mysql_num_rows($sql1);
      Placing comment in our code can help both others and yourself. Six months from now you might forget what it means. In particular, what is $sql1 -Is it a string or a scalar or a Boolean? Something else?

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: examresult
      « Reply #4 on: July 24, 2013, 09:32:14 PM »
      You do not use mysql_connect() to connect to a database, so mysql_query() returns false, and that result get's passed into mysql_num_rows which expects a resource rather than a boolean and you get the error you are receiving.



      But, I thin k yhou ought to make some comments about whkat the following line means.
       Placing comment in our code can help both others and yourself. Six months from now you might forget what it means. In particular, what is $sql1 -Is it a string or a scalar or a Boolean? Something else?
      It's common in the older PHP database functions. the variable is created as the result from mysql_query. This is normally a loosely typed value that is only used as a 'cookie' for other functions, such as mysql_num_rows. In this case mysql_query() is returning FALSE to indicate failure because the code hasn't opened a database connection.
      I was trying to dereference Null Pointers before it was cool.

      gowthamprabhus

        Topic Starter


        Greenhorn

        • Experience: Familiar
        • OS: Windows 7
        Re: examresult
        « Reply #5 on: July 25, 2013, 06:01:46 AM »
        What should I do now to make the code to work?

        camerongray



          Expert
        • Thanked: 306
          • Yes
          • Cameron Gray - The Random Rambings of a Computer Geek
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Mac OS
        Re: examresult
        « Reply #6 on: July 27, 2013, 11:13:12 AM »
        You need to call mysql_connect() before you start working with the database to connect to the database server.  Documentation on this function can be found here: http://php.net/manual/en/function.mysql-connect.php

        This function is deprecated so while it will work fine for now, if you plan on building any large applications you should look into using MySQLi as detailed here: http://www.php.net/manual/en/book.mysqli.php

        You should also get into the habit of escaping any user provided values (e.g. $_GET, $_POST) before adding them into your queries, otherwise you are wide open for SQL Injection

        gowthamprabhus

          Topic Starter


          Greenhorn

          • Experience: Familiar
          • OS: Windows 7
          Re: examresult
          « Reply #7 on: July 27, 2013, 05:49:37 PM »
          Thank you sir,

          But I dono exactly how to modify the line.

          Can anyone please modify and give me that line?

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: examresult
          « Reply #8 on: July 27, 2013, 07:07:05 PM »
          Is this homework?

          I'm thinking the answer to this question is "yes".
          I was trying to dereference Null Pointers before it was cool.

          gowthamprabhus

            Topic Starter


            Greenhorn

            • Experience: Familiar
            • OS: Windows 7
            Re: examresult
            « Reply #9 on: July 27, 2013, 07:10:01 PM »
            Dear All Repliers,

            I am basically from Electrical Engineering Background. I have interest in webdesigning, so I am learning this,. ,

            Who from Electrical Engineering Gives Web designing as a homework?

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: examresult
            « Reply #10 on: July 27, 2013, 08:18:51 PM »
            Dear All Repliers,

            I am basically from Electrical Engineering Background. I have interest in webdesigning, so I am learning this,. ,

            Who from Electrical Engineering Gives Web designing as a homework?
            I am basically Santa Claus, I have an interesting in Programming and IT, so I often assist in a volunteer fashion on this forum.

            Who from the North Pole gives MySQL advice?

            Point being, you didn't negate anything that was claimed. You can make any number of wild claims. Replace "Electrical Engineering" with "Oval Office" and you see the problem. Even so, it's quite possible to verify what you are saying, rudimentarily, through a Google search. However, from what I found, you already claim to know PHP, and I find it difficult to imagine a case where somebody could "know" PHP but not know how to use mysql.

            We have already provided you the means to help yourself. If you want somebody else to write the code for you, you should hire somebody else to do so; otherwise, you will have to invest in learning what you are doing. You cannot "hire" volunteers and ask for one line of code at a time.

            You need to connect to the database. Look up what you are learning and using. Learn how it works. learn WHY you need to use db_connect(), and how you would do so. Otherwise, me, or anybody else telling you what line to write wouldn't help you, because you won't know what you need it. (And I don't know where you database server is, whether it's localhost, how your webhost has it configured, what the database name is, or any of those things, which would be needed to create the appropriate db_connect() call.)

            If this is for a Freelance project I worry for the client.
            I was trying to dereference Null Pointers before it was cool.

            gowthamprabhus

              Topic Starter


              Greenhorn

              • Experience: Familiar
              • OS: Windows 7
              Re: examresult
              « Reply #11 on: July 27, 2013, 08:29:00 PM »
              Thank you for your Reply @ B C Programmer