这是我的小搜索脚本。
<a href="insert_link.php">Register Your Site</a>
<div id="wrapper">
<form action="result.php" method="get">
<span class="icon"><i class="fa fa-search"></i></span>
Search Something : <br/><input type="search" id="search" name="value" placeholder="Type Something" /><br/>
<div class="se"><input type="submit" id="search" name="search" value="search now" /></div>
</form>
<?php
mysql_connect(" host "," user ","pass");
mysql_select_db(" db ");
if(isset($_GET['search']))
{
$search_value = $_GET['value'];
$query = "select * from sites where site_keywords like '%$search_value%'";
.......
我使用xampp离线创建了此脚本。我导出了我的mysql表并导入到我的在线主机。但问题是,从我的网站我无法连接到mysql数据库 - 离线它工作正常。
有人可以告诉我哪里弄错了吗?这是网站:http://abdulhakim.x10hostinger.net
答案 0 :(得分:4)
连接字符串中不应该有空格:
mysql_connect(" host "," user ","pass");
mysql_select_db(" db ");
试试这样:
mysql_connect("host","user","pass");
mysql_select_db("db");
旁注:
您不应该使用mysql_,因为它已被弃用,请使用mysqli_或PDO!
答案 1 :(得分:4)
您的凭证中有一个空格,例如,主机名用户名和密码
$host="localhost";
$username="root";
$pwd="";
$link=mysql_connect($host,$username,$pwd);
$con=mysql_select_db('your_db_name',$link);