hi,
i know this is a long piece of code but i am desperate. does anyone know why the query does not produce any results?
i know the query works as i have tried it in mySQL. '$title' is a value from a input textbox. thanks
<?php
require '/home/lj917/public_html/mysql.php';
$title = $HTTP_POST_VARS['Title'];
function printError($errorMesg) {
printf("<br /> %s <br />\n", $errorMesg);
}
if ( !($link=mysql_connect($host, $user, $passwd)) ) {
printError(sprintf("Error connecting to database from %s, by user %s", $host, $user));
} else {
mysql_select_db($dbName);
$query = 'SELECT * FROM CD_data WHERE Artist LIKE '%$title%' OR Title LIKE '%$title%' OR Genre LIKE '%$title%'';
if ( !($result = mysql_query($query,$link)) ) {
printError(sprintf("Error %s : %s", mysql_errno(), mysql_error()));
} else {
if ( $result == 0 ) {
echo "Error " . mysql_errno() . ":" . mysql_error();
} else {
echo "<table bgcolor=\"ddeeff\"><thead><tr><th bgcolor=\"eeddff\">Row</th>";
for ( $i = 0 ; $i < mysql_num_fields($result) ; $i++ ) {
echo "<th bgcolor=\"abcdef\">" . mysql_field_name($result,$i) . "</th>\n";
}
echo "</tr></thead>\n<tbody>";
for ( $i = 0 ; $i < mysql_num_rows($result) ; $i++ ) {
echo "<tr><td bgcolor=\"eeddff\">" . ($i + 1) . "</td>";
$row = mysql_fetch_row($result);
for ( $j = 0 ; $j < mysql_num_fields($result) ; $j++ ) {
echo "<td> " . $row[$j] . "</td>";
}
echo "</tr>\n";
}
echo "</tbody></table>";
}
}
}
?>
</body></html>