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
?>
------------------
Sofia
------------------
Sofia