php mysql web connection

admin

Administrator
Staff member
I am new at php. Below is a script that should allow me to search a database named bktest that resides on a mysql server on a linux machine running apache. The mysql server and the web server live on the same machine.

So far all I get is an error on line 7 that states " Fatal error: Call to unsupported or undefined function mysql_connect() in /home/httpd/html/www.thebklounge.com/search.php3 on line 7"
I have placed my username and password in this script and still get the same error. Any help woould be greatly appreciated.

<?php

if(!isset(&query) || empty($query))
{$query = "select*from bktest";}
$query=stripslashes ($query);

mysql_connect("username", "password", "")
or die ("Could not access database, something is wrong.");
mysql_select_db("bktest") or
die ("Could not access bktest database");
$result = mysql_query($query) or
die ( mysql_error() );

$number_cols = mysql_num_fields($result);

echo "<b>query: $query</b>";

//layout table header
echo "<table Border = 1>\n";
echo "<tr align=center>\n";

for ($i=0; $i<$number_cols; $i++)
{
echo "<th>" . mysql_field_name($result, $i). "</th>\n";
}
echo "</tr>\n";//end table header

//body layout

while ($row = mysql_fetch_row($result))
{
ECHO "<TR AALIGN=LEFT>\n";
for ($i=0; $i<$number_cols; $i++)
{
echo "<td>";
if (!isset($row[$i])) //test for null values
{echo "NULL";}
else
{echo $row[$i];}
echo "</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";

?>

<form action="<? echo $PHP_SELF?>" method="get">
input type ="text" name ="query" size="50"><br>
<input type="submit">
</form>
 
Back
Top