Returns Undefined Instead Of Value - php

I have a page that is supposed to display some data fetched by AJAX from a database, but instead it displays an error message.
The page that shows the data:
<html>
<head>
<style type="text/css">
a {
text-decoration:none;
}
</style>
<script type="text/javascript">
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getinfo.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
mysql_connect("localhost","username","password");
mysql_select_db("databasename");
//$niftystocks=array();
$sq="SELECT TPNTCode FROM `niftystock`";
$r=mysql_query($sq);
$i=0;
while ($ro=mysql_fetch_array($r)) {
//array_push($niftystocks,$row['TPNTCode']);
$tpnt=$ro['TPNTCode'];
$sql="SELECT * FROM `nsepricequotes_latest` where TickerPlantCode = '$tpnt' ";
$rs=mysql_query($sql);
$row=mysql_fetch_array($rs);
if ($i == 0)
echo "--" . $row['DateTime'] . "--";
$sy=$row['Symbol'];
echo "<span id='txtHint'></span><a href='#'><span onmouseover='showUser()'>$sy</span>: " . $row['LastTradedPrice'] . " (" . $row['PercentChange'] . ")</a>";
if($row['PercentChange'] >= 0)
echo " <img src='http://mastertrade.in/master/ticker/images/arrow-up.gif' border='0' > | ";
else
echo " <img src='http://mastertrade.in/master/ticker/images/arrow-down.gif' border='0' > | ";
$i++;
}
?>
getinfo.php:
<?php
$q=$_GET['q'];
echo $q;
$con = mysql_connect('localhost', 'username', 'password');
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("databasename", $con);
$sql1="Select OpenPrice,HighPrice,LowPrice from nsepricequotes_latest WHERE Symbol like '".$q."' ";
while($row1= mysql_fetch_array($sql1)) {
$openprice=$row1['OpenPrice'];
$highprice=$row1['HighPrice'];
$lowprice=$row1['LowPrice'];
$tpnt=$row1['TickerPlantCode'];
}
$sql="SELECT * FROM 52wkhighlow WHERE nFTCode = '$tpnt'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$wkhigh=$row['BSE52WkHighVal'];
$wklow=$row['BSE52wlLowval'];
}
?>
<html>
<body>
<table>
<tr>
<td>Open Price</td><td><?php echo $openprice; ?></td>
<td>High Price</td><td><?php echo $highprice; ?></td>
<td>Low Price</td><td><?php echo $lowprice;?></td>
<td>52 Week High</td><td><?php echo $wkhigh;?></td>
<td>52 Week Low</td><td><?php echo $wklow;?></td>
</tr>
</table>
</body>
</html>
I'm getting this error:
-undefined Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mastertr/public_html/master/ticker/getinfo.php on line 11

because you didn't run your $sql1 query
set this :
$sql1="Select OpenPrice, HighPrice, LowPrice from nsepricequotes_latest
WHERE Symbol like '". mysql_real_escape_string($q)."' ";
$result_1 = mysql_query( $sql1 );
then start :
while( $row = mysql_fetch_array($result_1) )
instead of :
while( $row = mysql_fetch_array($sql1) )

You forgot to run mysql_query()
$sql1="Select OpenPrice,HighPrice,LowPrice from nsepricequotes_latest WHERE Symbol like '".$q."' ";
while($row1= mysql_fetch_array($sql1))
should be something like
$sql1="Select OpenPrice,HighPrice,LowPrice from nsepricequotes_latest WHERE Symbol like '".$q."' ";
$res = mysql_query($sql1);
while($row1= mysql_fetch_array($res))

In your mouseover there's the following:
showUser()
Note that undefined and "" is not the same.
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
The above doesn't work because str is undefined and not an empty string.
Either do this:
showUser("")
Or do this:
if (str == undefined)

Related

how to display the two different columns from the selected year

I do not know how will I display the position and names of the officers from year selected by the user.
Edit:
I used ajax now, but I'm still having a problem. When I click the combobox and select a year, the officers still don't show up. Only the table with the header Position and Name that shows up, but no data from my database under those columns.
getyear.php
<?php
$q = strval($_GET['q']);
$con = mysqli_connect('localhost','root','','test');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM officers WHERE year = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>Position</th>
<th>Name</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['position'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
main.php
<form>
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$sql = "SELECT DISTINCT year FROM officers ORDER BY year DESC";
$result = mysql_query($sql);
/* assign an onchange event handler */
echo "<select name='year' onchange='showofficers(this.value)'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['year'] ."'>" . $row['year'];
}
echo "</select> <br>";
?>
<div id="txtHint">
</div>
</form>
<script>
/* event handler ~ no ajax function shown */
function showofficers(str){
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET","getyear.php?q="+str,true);
xmlhttp.send();
}
}
</script>
some pseudo-code o give you an idea of how you could achieve the desired goal.
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$sql = "SELECT DISTINCT year FROM officers ORDER BY year DESC";
$result = mysql_query($sql);
/* assign an onchange event handler */
echo "<select name='year' onchange='showofficers(this.value)'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['year'] ."'>" . $row['year'];
}
echo "</select> <br>";
?>
<script>
/* event handler ~ no ajax function shown */
function showofficers( value ){
/*
use ajax to send a request that fetches the officers details
based upon the year selected. Preferred method=POST for ajax query
*/
alert( 'send '+value+' via ajax, build the sql query and use the ajax callback to generate the new html content' );
}
</script>
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' ){
/* Intercept and process ajax request */
/* the year is POSTed by ajax */
$year = $_POST['year'];
$sql='select * from table where year='.$year;
$res=$db->query( $sql );
if( $res ){
/* process recordset and send back response */
}
}
?>

sql response with ajax filter not working

My first contact with ajax. I have modify this tutorial. However sql response is always not showing any record.
I made var_dump of $result, but only got bool(false).
Where I made mistake? Is any better way of making dynamic filters?
My function, simple table:
function showRoadMap() {
$conn.... //cut connection with database
$q = $_GET['q'];
$sql = "SELECT * FROM roadmap WHERE status={$q}";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo '
<table class="showGrid">
<tr>
<td>Name</td>
<td>Status</td>
</tr>';
while($row = $result->fetch_assoc()) {
echo '<tr><td>'.$row['name'].'</a></td>
<td>'.$row['status'].'</td></tr>';
}
echo '</table>';
}
else
echo 'No record found';
}
}
My php file:
<script>
function showFilter(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","roadmapShow.php?q="+str,true);
xmlhttp.send();
}
}
</script>
<form>
<select name="status" onchange="showFilter(this.value)">
<option value="">Select a status:</option>
<option value="proposal">proposal</option>
<option value="approved">approved</option>
<option value="done">done</option>
<option value="refuse">refuse</option>
</select>
</form>
<div id="txtHint"></div>
and the last file: roadMapShow.php
<?php showRoadMap(); ?>
Get rid of third file or setup proper include and parameter passing. I fixed your code in two files. There is no change in "My php file", and the other two is combined below:
roadmapShow.php:
<?php
$q = $_GET['q'];
function showRoadMap($q) {
$conn.... //cut connection with database
$sql = "SELECT * FROM roadmap WHERE status={$q}";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo '
<table class="showGrid">
<tr>
<td>Name</td>
<td>Status</td>
</tr>';
while($row = $result->fetch_assoc()) {
echo '<tr><td>'.$row['name'].'</a></td>
<td>'.$row['status'].'</td></tr>';
}
echo '</table>';
}
else
echo 'No record found';
}
showRoadMap($q);
?>
Try doing like this
function showRoadMap($query) {
$conn.... //cut connection with database
$q = $query;
$sql = "SELECT * FROM roadmap WHERE status={$q}";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo '
<table class="showGrid">
<tr>
<td>Name</td>
<td>Status</td>
</tr>';
while($row = $result->fetch_assoc()) {
echo '<tr><td>'.$row['name'].'</a></td>
<td>'.$row['status'].'</td></tr>';
}
echo '</table>';
}
else
echo 'No record found';
}
and in roadmapshow.php
<?php
$q = $_GET['q'];
showRoadMap($q); ?>

Drop down list to select a table and an additional drop down list to filter

I want to use 2 drop down lists on the same page, one of them to select the table from the Db and the other to filter the selected table. I think this is very basic but I am new in PHP and SQL. I have no problem to use a submit to filter the table by group but I don't know where assign to $table variable the $_POST['tables'] value.
Here is the relevant part of my code, :
$table=table_name;
if(isset($_POST['tables'])) {
$table=$_POST['tables'];
}
//filtering by group
if(true===isset($_POST['value'])) {
if($_POST['value'] == 'All') {
// query to get all records
$query = "SELECT * FROM $table";
} else {
// filter groups
$value=$_POST['value'];
$query = "SELECT * FROM $table WHERE Grupo='$value'";
}
} else {
// the first time the page is loaded
$query = "SELECT * FROM $table ORDER BY Grupo ASC";
}
$sql = mysqli_query($con,$query);
index.php
<html>
<head>
<script>
function sortResult(str)
{
var e = document.getElementById("firstDrop");
var str1 = e.options[e.selectedIndex].value;
var e = document.getElementById("secondDrop");
var str = e.options[e.selectedIndex].value;
if (str=="")
{
document.getElementById("result").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("result").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","results.php?q="+str+"&t="+str1,true);
xmlhttp.send();
}
</script>
</head>
<body>
<!--database name-->
<select name="tablename" id="firstDrop">
<option selected='selected' value="yourdatabasename1">DB1</option>
<option value="yourdatabasename2">DB2</option>
</select>
<!--sort by what-->
<select name="sortby" id="secondDrop">
<option selected='selected' value="slno">slno</option>
<option value="name">name</option>
<option value="author">author</option>
</select>
<button id="sub" onclick="sortResult()">CLICK</button>
<br><br>
<div id="result"><b>Results will be listed here.</b></div>
</body>
</html>
results.php
<?php
$q = $_GET['q'];
$t = $_GET['t'];
$con = mysqli_connect('localhost','yourusername','password','database');
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"database");
$sql="SELECT * FROM ".$t." ORDER BY ".$q;
$result = mysqli_query($con,$sql);
echo "<table border='1'>
<tr>
<th>Name</th>
<th>Author</th>
<th>ID</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" .$row['name']. "</td>";
echo "<td>" .$row['author'] ."</td>";
echo "<td>" .$row['slno']. "</td>";
echo "</tr>";
}
echo "</table>";
echo $t;
mysqli_close($con);
?>
modify accordingly.
you have a typo...
if(isset($_POST['tables'])) {
$tabla=$_POST['tables'];
}
change to
if(isset($_POST['tables'])) {
$table=$_POST['tables'];
}
Correct your query syntax--
$query = "SELECT * FROM $table";
to
$query = "SELECT * FROM '".$table."'";
$query = "SELECT * FROM $table WHERE Grupo='$value'";
to
$query = "SELECT * FROM '".$table."' WHERE Grupo='".$value."'";
and
$query = "SELECT * FROM '".$table."' ORDER BY Grupo";
to
$query = "SELECT * FROM '".$table."' ORDER BY Grupo";

retrieve data from database mysql not working

Hi i am using the html dropdown's onchange event using ajax
In the code i am using, should get the address column value when i change the
drop down.
but it is not working.What may have gone wrong?
here is the code
<html>
<head>
<script>
function showUser( str ) {
if ( str == "" ) {
document.getElementById("txtHint").innerHTML="";
return;
}
if ( window.XMLHttpRequest ) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if ( xmlhttp.readyState==4 && xmlhttp.status == 200 ) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", "getuser.php?q=" + str, true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<?php
mysql_connect('localhost', 'tiger', 'tiger');
mysql_select_db('theaterdb');
$sql = "select theater_name from theater;";
$result = mysql_query($sql);
echo "<select name='theater_name' id='course' onchange='showUser(this.value);'>";
while ( $row = mysql_fetch_array( $result ) ) {
echo "<option value='" . $row['theater_name'] ."'>" . $row['theater_name']. "</option>";
}
echo "</select>";
?>
</form>
<br>
<div id="txtHint"><b>Info</b></div>
</body>
</html>
Code for getuser.php
<?php
$q = $_GET["q"];
$con = mysqli_connect("localhost", "tiger", "tiger", "theaterdb");
if ( !$con ) {
die('Could not connect: ' . mysqli_error( $con ) );
}
mysqli_select_db( $con );
$sql = "SELECT address FROM theater WHERE theater_name = '".$q."'";
$result = mysqli_query( $con, $sql );
echo "<table border='1'>
<tr>
<th>Firstname</th>
</tr>";
while( $row = mysqli_fetch_array( $result ) ) {
echo "<tr>";
echo "<td>" . $row['address'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Ok, I've tweaked your files slightly, you shouldn't be using mysql_ or the mysqli_ functions any more, just don't... And you certainly shouldn't be using mysql function in one file and mysqli functions in the other... I've switched them over to use PDO, you're script now isn't susceptible to SQL injection, and as far as I can tell it works just fine.
index.html
<html>
<head>
<script>
function showUser(str) {
if(str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if(window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<?php
try {
$dbh = new PDO('mysql:dbname=theaterdb;host=localhost','tiger','tiger');
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$sql = "SELECT theater_name FROM theater;";
$sth = $dbh->prepare($sql);
$sth->execute();
echo "<select name='theater_name' id='course' onchange='showUser(this.value);'>";
while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
echo "<option value='" . $row['theater_name'] ."'>" . $row['theater_name']. "</option>";
}
echo "</select>";
?>
</form>
<br>
<div id="txtHint"><b>Info</b></div>
</body>
</html>
getuser.php
<?php
$q = strtolower(trim($_GET["q"]));
try {
$dbh = new PDO('mysql:dbname=theaterdb;host=localhost','tiger','tiger');
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$sql = 'SELECT address FROM theater WHERE LOWER(theater_name) = :q';
$sth = $dbh->prepare($sql);
$sth->bindValue(':q', $q);
$sth->execute();
echo "<table border='1'><tr><th>Firstname</th></tr>";
while($row = $sth->fetch(PDO::FETCH_ASSOC)) {
echo "<tr>";
echo "<td>" . $row['address'] . "</td>";
echo "</tr>";
}
echo "</table>";
$dbh = null;
I am unable to understand why have you connected with database in both of php files ?
I would suggest you to visit below link.
http://www.w3schools.com/php/php_ajax_database.asp

Retrieve mySQL Data On Radio Button Click

Through some very much appreciated help from users of this site I've been able to put together a script that upon a radio button click will populate a table with user details.
I thought that I'd be able to adapt it even further, but, quite possibly because of my lack of experience, unfortunately I've come across another problem, hence why I've added a new post.
Pulling the data from a mySQL database I'm using the code below to create a list of dates with an associated radio button.
<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser2.php?="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
mysql_connect("hostname", "username", "password")or
die(mysql_error());
mysql_select_db("database");
$result = mysql_query("SELECT userdetails.userid, finds.dateoftrip, detectinglocations.locationname, finds.userid, finds.locationid, detectinglocations.locationid, finds.findname, finds.finddescription FROM userdetails, finds, detectinglocations WHERE finds.userid=userdetails.userid AND finds.locationid=detectinglocations.locationid AND finds.userid = 1 GROUP By dateoftrip ORDER BY dateoftrip DESC");
if (mysql_num_rows($result) == 0)
// table is empty
echo 'There are currently no finds recorded for this location.';
else
{
echo"<table>\n";
while (list($userid, $dateoftrip) =
mysql_fetch_row($result))
{
echo"<tr>\n"
.
"<td><input type='radio' name='show' dateoftrip value='{$userid}' onClick='showUser(this.value)'/></td>\n"
."<td><small>{$dateoftrip}</small><td>\n"
."</tr>\n";
}
echo'</table>';
}
?>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
</body>
</html>
Then with the following code I want to populate a table with the associated 'findname' details for the radio button clicked.
<?php
$q=$_GET["q"];
$con = mysql_connect('hostname', 'username', 'password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('database', $con);
$sql="SELECT * FROM finds WHERE id = '".$q."'";
$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Find Name</th>
</tr>";
while($row = mysql_fetch_array($sql))
{
echo "<tr>";
echo "<td>" . $row['findname'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
I can get the first part of the script to work, i.e. the creation of the date list and radio buttons, but when I select the radio button, the table appears with the correct column heading, but I receive the following error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /homepages/2/d333603417/htdocs/development/getuser2.php on line 21 with line 21 being this line: while($row = mysql_fetch_array($sql)).
As I said earlier the other users that answered my first post were great, but I just wondered if someone could perhaps have a look at this please and let me know where I've gone wrong.
Updated Code
Form
<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser2.php?="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
mysql_connect("hostname", "username", "password")or
die(mysql_error());
mysql_select_db("database");
$result = mysql_query("SELECT userdetails.userid, finds.dateoftrip, detectinglocations.locationname, finds.findid, finds.userid, finds.locationid, detectinglocations.locationid, finds.findname, finds.finddescription FROM userdetails, finds, detectinglocations WHERE finds.locationid=detectinglocations.locationid AND finds.userid = 1 GROUP By dateoftrip ORDER BY dateoftrip DESC");
if (mysql_num_rows($result) == 0)
// table is empty
echo 'There are currently no finds recorded for this location.';
else
{
echo"<table>\n";
while (list($findid, $dateoftrip) =
mysql_fetch_row($result))
{
echo"<tr>\n"
.
"<td><input type='radio' name='show' dateoftrip value='{$findid}' onClick='showUser(this.value)'/></td>\n"
."<td><small>{$dateoftrip}</small><td>\n"
."</tr>\n";
}
echo'</table>';
}
?>
<br />
<div id="txtHint"></div>
</body>
</html>
PHP
<?php
//$q=$_GET["q"];
$con = mysql_connect('hostname', 'username', 'password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('database', $con);
$sql="SELECT * FROM finds";
$result = mysql_query($sql);
// This is helpful for debugging
if (!$result) {
die('Invalid query: ' . mysql_error());
}
echo "<table border='1'>
<tr>
<th>Find Name</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['findname'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
while ($row = mysql_fetch_array($result))
not
while ($row = mysql_fetch_array($sql))
mysql_fetch_array accepts a mysql result object (which you get from the mysql_query function call), not a string
In $row = mysql_fetch_array($sql)
$sql is a string, you should use $result instead, which is a mysql_result object.

Categories