Well mine was abit overly complicated, but i wonder if it wouldnt work if you just do something like this:
[php]
<?php print($text); ?>
<?php // Includes database connection file include("db.php"); // Fetches data from html forms $title=$_POST["title"]; $text=$_POST["text"]; // Fetches data from database and prints it out $query = mysql_query("SELECT * FROM `kontrakt` ORDER BY `id` DESC") or die(mysql_error()); $numRows = mysql_num_rows($query); for ($i=1;$i<$numRows;$i++) { $id = $data['id']; $title1 = $data['title']; $text1 = $data['text']; echo"
Title:$title1
Text:$text1
"; } $ok=$_POST["edit"]; if($ok) { $id=$_POST["identification"]; $sqlTestIfExists="SELECT tittel FROM kontrakt WHERE tittel='$title' AND tekst='$text'"; $testResult=mysql_query($sqlTestIfExists); if (mysql_num_rows($testResult) { $sqlEdit="UPDATE kontrakt SET tittel='$title', tekst='$text' WHERE id='$id';"; $sqlEditResult=mysql_query($sqlEdit) or die ("klarte ikke å endre på oppføring"); print("Data er nå endret"); } } // Checks if a row exists, IF it doesnt it inserts data into DB if (mysql_num_rows($testResult) < 1) { $sqlInsert="INSERT INTO kontrakt VALUES (' ','$title','$text');"; $sqlSave=mysql_query($sqlInsert) or die ("klarer ikke å lagre i databasen"); print("Data er nå lagret i databasen"); } ?>
[/php]
With special emphasis on the [php]
$ok=$_POST[“edit”];
if($ok)
{
$id=$_POST[“identification”];
$sqlTestIfExists=“SELECT tittel FROM kontrakt WHERE tittel=’$title’ AND tekst=’$text’”;
$testResult=mysql_query($sqlTestIfExists);
if (mysql_num_rows($testResult)
{
$sqlEdit="UPDATE kontrakt SET tittel='$title', tekst='$text' WHERE id='$id';";
$sqlEditResult=mysql_query($sqlEdit) or die ("klarte ikke å endre på oppføring");
print("Data er nå endret");
}
}
[/php]
Basically, i figured out (or think i figured out) that this is the way to solve it.
I solved it like this, but alot more complicated with alot more files.
ps: i got a syntax error making the example of the solution and i couldnt be asked to solve it.
Also, thanks guys, for helping a newbie help himself