Click here to Skip to main content
15,893,668 members

data retrieving in php mysql

karthikh87 asked:

Open original thread
Hi PHP Developers..
I wanted to retrieve data from table called enquiry.
and in 1st page by name userform.php i have below code with $refno = ""; defined at the top of the page with in php tag:

XML
<form name="form1" method="post" action="fetchdata.php">
        <table width="auto" border="0" cellpadding="3" cellspacing="1" align="center" bgcolor="#FFFFFF">
        <tr>
            <td width="78">Ticket No.</td>
            <td width="6">:</td>
            <td width="78" class="float_left">
            <input name="refno" type="text" value="<?php echo $refno; ?>"/></td>
        </tr>
        </table>
        <input type='submit' value="Submit">
        </form>



and i have fetchdata.php page where i wanted to retrieve data and display in a table format so i did code as below:
XML
<?php
        $dbhost = "localhost";
        $dbuser = "root";
        $dbpass = "";
        $conn = mysql_connect($dbhost, $dbuser, $dbpass);
        $refno = "";
        if(! $conn )
        {
        die('Could not connect: ' . mysql_error());
        }

        $strquery = "select * from enquiry where refno='$refno'";
        $result = mysql_query($strquery);

        ?>
        <table>
        <tr>
            <th>Results for Refno entry</th>
        </tr>
        </table>
        <table>
        <tr>
            <th>refno</th>
            <th>date</th>
            <th>agentname</th>
            <th>zcno</th>
            <th>callerid</th>
        </tr>
        <?php

        while($data = mysql_fetch_array($result))
        {
            $refno = $data["refno"];
            $date = $data["date"];
            $agentname = $data["agentname"];
            $zcno = $data["zcno"];
            $callerid = $data["callerid"];

            ?>


        <tr>
            <td><?php echo $refno; ?></td>
            <td><?php echo $date; ?></td>
            <td><?php echo $agentname; ?></td>
            <td><?php echo $zcno; ?></td>
            <td><?php echo $callerid; ?></td>
        </tr>

            <?php
        }
        echo("</table><br /><br />");


and i am getting error as:
Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampp\htdocs\newcrm\fetchdata.php on line 99
refno date agentname zcno callerid

Please request you to help me getting code for retrieving data and it would be very helpful if i get code in simple form as i think i have did in very complex form.

Thanks in advance and happy to be a part of this forum as i get good help and also others questions help me grow from this forum.
Tags: PHP, MySQL

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900