I have an html file that is supposed to do a search and return of a database I have created in phpMyadmin but is giving me nothing but one error after another!!:'(
This is the html form

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Directory List Request</title>
</head>
<body>
<form action="Database.php" method="post">
<input type="reset" value="Clear Form" />&nbsp;
&nbsp;<input type="submit" name="submit" value="send request" />
</form>
</body>
</html>

and it seems to work properly but the results I am getting are annoying as this calls several other php files designed to attach to and search through my database. The first of those files is this

<?php
require ('connect.php');
// create SQL statement
$sql = "SELECT lname, fname, areacode, telephone
FROM directory";

// execute SQL query and get result
$sql_result = mysql_query($sql,$connection);

// start results formatting
echo "<TABLE BORDER=1>";
echo "<TR><TH>lname&lt;<TH>fname&lt;<TH>areacode&lt;<TH>telephone&lt;";

// format results by row
while ($row = mysql_fetch_array($sql_result)) {
$lname = $row["lname"];
$fname = $row["fname"];
$areacode = $row["areacode"];
$phone = $row["telephone"];
echo "<TR><TD>$lname&lt;/TD><TD>$fname&lt;/TD><TD>$areacode&lt;/TD><TD>$phone&lt;/TR>";
}

echo "&lt;/TABLE>";

// free resources and close connection
mysql_free_result($sql_result);
mysql_close($connection);
?>

and I am not sure if it is working correctly as it is dependent on this script

<?php

// create connection
$connection = mysql_connect("localhost","zlloyd","");

// test connection
if (!$connection) {
echo "Couldn't make a connection!";
exit;
}

// select database
$db = mysql_select_db("Directory", $connection);

// test selection
if (!$db) {
echo "Couldn't select database!";
exit;
}

and again I am not sure if this is the problem but what I do know is that the output I am getting is incorrect:
lname< fname< areacode< telephone<
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\database.php on line 15
</TABLE>
Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\database.php on line 26
and includes the errors that read expects parameter to be resource, boolean.:@
I cannot for the life of me see what is causing this and why the output is just lname, fname, areacode and telephone instead of the associated values from the database.:angry:
If anyone can tell me what is happening here I would be eternally grateful!!

P.S. I am fairly new to php and mysql so be gentle....

Recommended Answers

All 2 Replies

Change the line $sql_result = mysql_query($sql,$connection); to $sql_result = mysql_query($sql,$connection) or die(mysql_error()); which will tell you more about the cause.
Since I do not see any syntactical errors I assume that you got either the database name or the table name or some field names wrong. Try select * from directory as your query.
Check your spelling (also upper/lowercase).
And why do you output "&lt;" instead of "<"? It's all ruining your html.

Change the line $sql_result = mysql_query($sql,$connection); to $sql_result = mysql_query($sql,$connection) or die(mysql_error()); which will tell you more about the cause.
Since I do not see any syntactical errors I assume that you got either the database name or the table name or some field names wrong. Try select * from directory as your query.
Check your spelling (also upper/lowercase).
And why do you output "&lt;" instead of "<"? It's all ruining your html.

Thank you for the input and I made the changes you suggested and it is functioning correctly now!!:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.