---
title: "sökning"
type: "forum-thread"
url: "https://www.webforum.nu/amne/php/16168-sökning"
topic: "PHP"
topic_url: "https://www.webforum.nu/amne/php"
author: "soffan76"
published: "2001-10-09T07:19:00.000Z"
updated: "2001-10-09T08:17:00.000Z"
replies: 3
views: 161
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/php/16168-sökning"
---

# sökning

## #1 — soffan76, 2001-10-09T07:19Z

Hej alla PHP-are!

Sitter och knepar med ett sök-skript som ej vill funka.
Jag har en databas som heter databas, en tabell som heter register och fyra fält: id, fornamn, efternamn och email.
Vad gör jag för fel?

Mvh Sofia

sidan "search.php":

```

<form method="post"  action="result.php">  
<select name="metode" size="1"> 
<option value="fornamn">Namn</option> 
<option value="efternamn">Efternamn</option> 
</select> 
<input type="text" name="search" size="25">  
<input type="submit" value="Begin Searching!!">  
</form> 

<?
echo date("lj:S F Y");
?>
```

sidan "result.php":

```
<? 
$hostname = "localhost";   // Usually localhost. 
$username = "";       	   // If you have no username, leave this space empty. 
$password = "";            // The same applies here. 
$usertable = "register";   // This is the table you made. 
$dbName = "databas";       // This is the main database you connect to. 
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); 
@mysql_select_db( "$dbName") or die( "Unable to select database"); 
?> 
<? 
//error message (not found message) 
$XX = "No Record Found"; 
$query = mysql_query("SELECT * FROM $register WHERE $metode LIKE '%$search%' LIMIT 0, 30 "); 
while ($row  =  mysql_fetch_array($query)) 
   { 
        $variable1=$row["fornamn"]; 
        $variable2=$row["efternamn"]; 
print ("this is for $variable1, and this print the variable2 end so on...");  
   } 

//below this is the function for no record!! 
if (!$variable1)  
{ 
print ("$XX"); 
} 
//end 
?>
```

Permalänk: https://www.webforum.nu/p/16168

## #2 — spango, 2001-10-09T07:30Z

Tja, vad är det som blir fel?

Permalänk: https://www.webforum.nu/p/324228

## #3 — LarsG, 2001-10-09T07:30Z

```
$query = mysql_query("SELECT * FROM register WHERE $metode LIKE '%$search%' LIMIT 0, 30 ") or die(mysql_error());
```

Permalänk: https://www.webforum.nu/p/324229

## #4 — soffan76, 2001-10-09T08:17Z

Det verkar funka nu. Tack!

Permalänk: https://www.webforum.nu/p/324230

---

Tråden på webben: https://www.webforum.nu/amne/php/16168-sökning
