Forum Moderators: coopster
sokvideo.php
<html>
<head>
<title>sök video</title>
</head>
<body>
<h1> sök en film!</h1><br>
<form action = "sok_result.php" method = post>
Namn :
<input type=text name=soknamn><br>
<br><br>
<input type=submit name=submit value="Sign">
<input type=reset name=reset value="Reset">
</form></body>
</html>
sok_result.php
<html>
<head>
<title>sök databas resultat</title>
</head>
<body>
<?php
$db = "video";
$table = "video1";
// connecting to MySQL
$conn = mysql_connect("localhost", "root") or
die("Count not connect to database");
echo "connected to database.<br>";
// selecting database
mysql_select_db($db) or
die ("Could not select database");
echo "selcted database $db.<br>";
// displaying the contents of video1
echo "<h2>Videoboken</h2>";
$query = "select * from $table where (soknamn) like ('soknamn')";
$result = mysql_query($query) or
die(mysql_error());
while ($row = mysql_fetch_array($result))
{
echo "<b>Namn:</b>";
echo $row["namn"];
echo "<br>";
echo "<b>Nummer:</b>";
echo $row["nummer"];
echo "<br>";
echo "<b>Tid:</b>";
echo $row["tid"];
echo "<br><br>";
}
?>
<h2><a href = "videobok.htm">Lägg till film</a></h2>
</body>
</html>
and i get this error message
Unknown column 'soknamn' in 'where clause'
i have tried many things and it vill not work
select * from $table where soknamn like 'soknamn'
...but so will...
select * from $table where soknamn = 'soknamn'
If the soknamn you refer to in the mysql statement is the result of the form, that is, <input type=text name=soknamn> then you'll need to add a $, as in:
select * from $table where soknamn like '$soknamn'
<form action = "sok_result.php" method = post>
Namn :
<input type=text name=soknamn><br>
<input type=text name=soknamn2><br>
you can access the values the user submitted like so
$_POST['soknamn'];
$_POST['soknamn2'];
Variables from outside PHP [php.net]
Andreas