Jump to content

Why is my code not working? :(


haug1

Recommended Posts

Hello, I just started coding and I'm having some troubles getting my code working. It's just supposed to let me search for a string written in a "database" .txt document. It's supposed to get the search word from the value in the <select> thingie. Most of the variables and stuff are written in Norwegian, I hope that's not too confusing!

 

Edit: When I run it, everything shows up nicely, but it just won't find matches with the database.

<!doctype html>
<html lang="no">
<meta charset="UTF-8">
<head>
<title>Vis klasseliste</title>
</head>
<a href="klassereg.php">Registrer klasse</a>
<a href="visklasse.php">Vis alle klasser</a>
<a href="studentreg.php">Registrer student</a>
<a href="visstudent.php">Vis alle studenter</a>
<a href="klasseliste.php">Vis klasseliste</a>
<h1>Vis klasseliste</h1>
<br>
<form method="POST" action="" name="visklasse" id="visklasse">
Klassekode: <select name="klassekode" id="klassekode">
<option value="">Velg klasse..</option>

<?php
	$fil=fopen("x/klasse.txt","r");
	while ($linje = fgets ($fil))
		{
			$del=explode("!", $linje);
				print("<option value='$del[0]'>$del[0]</option>");
		}
	fclose ($fil);
?>

</select>
<input type="submit" name="submit" id="submit" value="Vis klasse"><br>
</form>

<?php
	@$klassekode=$_POST["klassekode"];
	$filb=fopen("x/student.txt", "r");
	$treff="0";
	while ($linjeb = fgets($filb))
	{
		$delb=explode("!", $linjeb);
		$brukernavn=trim($delb[0]);
		$fornavn=trim($delb[1]);
		$etternavn=trim($delb[2]);
		$klassekodeb=trim($delb[3]);
		if ($klassekode == $klassekodeb)
		{
			$treff++;
			print("$brukernavn $fornavn $etternavn<br>");
		}
	}
	print("<br>Antall treff: $treff");
?>

</html>
Edited by haug1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.