试图创建一个搜索工具,但有问题

时间:2014-12-05 21:22:14

标签: php mysql sql

我的PHP代码存在问题,一直在尝试创建搜索工具并遇到一些错误,并且不知道该怎么做。这是我的代码区域有问题:

<input type="text"  required="required" name="name"> 
<input name="submit" name="submit" value="Search">
</form>

<?php
if(isset($_POST['submit'])) {
if(isset($_GET['go'])){
if(preg_match("^/[A-Za-z]+/", $_POST['name'])){   //to make sure its either capital or small letters
    $name=$_POST['name'];

//connection to database
$db=mysql_connect ("localhost", "<u1375454>", "<25jun94>") or die ('Cannot connect to database: ' .mysql_error());

//selection of database to use
$mydb=mysql_select_db("Cars");

 $sql="SELECT Brand i_d, Brand_name, Headquarters, Net_worth FROM Cars WHERE Brand_name LIKE '%" . $name . '%" OR Headquarters LIKE '%" . $name ."%'"; 





$result=mysql_query($sql); 
// HERES WHERE AM HAVING THE PROBLEM
while($row=mysql_fetch_array($result)){ 
  $Brand_name=$row['Brand_name']; 
  $Headquarters=$row['Headquarters']; 
  $Brand i_d=$row['Brand i_d']; 
  echo "<ul>\n"; 
  echo "<li>" . "<a  href=\"search.php?id=$ID\">"   .$Brand_name . " " . $Headquarters .  "</a>     </li>\n"; 
  echo "</ul>"; 
} 

1 个答案:

答案 0 :(得分:1)

你的变量“$ Brand i_d”不能那样!改变它$ Brand_i_d;