<html> <head> <title>==Book-O-Rama Search Results==</title> </head> <body> <h1>[Book-O-Rama Search Results]</h1> <?php $searchtype=$_POST['searchtype']; $searchterm=$_POST['searchterm']; $searchterm=trim($searchterm); if (!$searchtype || !$searchterm) {echo 'you have not entered search detail.please go back and try again.'; exit; } if (!get_magic_quotes_gpc()) { $searchtype = addslashes($searchtype); $searchterm = addslashes($searchterm); echo 'chenchao'; } //@ $db = new mysqli('localhost','bookorama','123456','books'); $db=mysql_connect('localhost','bookorama','','books'); //mysql_select_db('books',$db); /* if (!mysql_connect()) { echo 'Error:could not connect to database.please try again later.'; exit; }*/ mysql_select_db("books",$db); echo $db; $sqlresult = "select * from books where ".$searchtype." like '%".$searchterm."%'"; echo $sqlresult; //$query = "select * from books where $searchtype like '%$searchterm%'"; $result = mysql_query($sqlresult,$db) or die(mysql_error()); echo $result; $num_results = mysql_num_rows($result); echo '##'.$num_results.'##'; if(!$num_results) { $num_results = 0; } echo '<p>Number of books found:'.$num_results.'</p>';echo "<p><strong>Title\t\t\tAuthor\t\t\tprice</br>"; while($sql_result = mysql_fetch_row($result)) { echo $sql_result[0]."\t\t\t".$sql_result[1]."\t\t\t".$sql_result[2]."</br>"; } 整个程序的上半部
1)在命令模式下你是用$db=mysql_connect('localhost','bookorama','','books');里的用户名和密码访问吗? 2)mysql_select_db("books",$db);=》mysql_select_db("books") or die (mysql_error());试试如果不是自定义函数后面那个参数可以不加。
怎么查看,我用mysql;use books;select *from books;能够看到我的那些数据,具体其他我就不会操作
<head>
<title>==Book-O-Rama Search Results==</title>
</head>
<body>
<h1>[Book-O-Rama Search Results]</h1>
<?php
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm=trim($searchterm);
if (!$searchtype || !$searchterm)
{echo 'you have not entered search detail.please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
echo 'chenchao';
}
//@ $db = new mysqli('localhost','bookorama','123456','books');
$db=mysql_connect('localhost','bookorama','','books');
//mysql_select_db('books',$db);
/*
if (!mysql_connect())
{
echo 'Error:could not connect to database.please try again later.';
exit;
}*/
mysql_select_db("books",$db);
echo $db;
$sqlresult = "select * from books where ".$searchtype." like '%".$searchterm."%'";
echo $sqlresult;
//$query = "select * from books where $searchtype like '%$searchterm%'";
$result = mysql_query($sqlresult,$db) or die(mysql_error());
echo $result;
$num_results = mysql_num_rows($result);
echo '##'.$num_results.'##';
if(!$num_results)
{
$num_results = 0;
}
echo '<p>Number of books found:'.$num_results.'</p>';echo "<p><strong>Title\t\t\tAuthor\t\t\tprice</br>";
while($sql_result = mysql_fetch_row($result))
{
echo $sql_result[0]."\t\t\t".$sql_result[1]."\t\t\t".$sql_result[2]."</br>";
}
整个程序的上半部
2)mysql_select_db("books",$db);=》mysql_select_db("books") or die (mysql_error());试试如果不是自定义函数后面那个参数可以不加。
就这样操作的啊,而那个bookorama用户也是根据书上建的,这个我在red hat8上的操作跟这里FC4
你干脆用"localhost" "root" ""试好了。不过照道理如果没有用户和权限都会提示其他的错误的。
echo $result;
还有,你要先弄清楚你的数据库的用户名和密码及可访问权限。
然后是在mysql_select_db这里做检查,这里如果没通过,你的mysql_query也不用看了。