Iv got my insert and search script ready.
its just when i insert Zeb and insert something similar like Zeb2.
When i then try to search for say Zeb, it gives me the first title Zeb but lists the text from both Zeb and Zeb2
My search script:
<?php
if (isset($_POST['searchfor']) && trim($_POST['searchfor']) != '')
{
texter();
$searchfor = addslashes($_POST['searchfor']);
$sql="SELECT title, text FROM texts,details WHERE texts.textid=details.textid AND title LIKE '%".$searchfor."%';";
$result=mysql_query($sql, $conn);
if(mysql_affected_rows()>0)
{
echo "Följande poster hittades:<br /><br />";
while($row = mysql_fetch_array($result))
{
$details = $row['title'];
$texts = $row['text'];
printf("<B>%s</B><br /><textarea name=text COLS=80 ROWS=20>%s<textarea/>", $details, $texts);
}
mysql_free_result($result);
}
else
echo "Inga poster hittades.<br /><br />";
}
?>
</html>
My Insert script:
<?
//Connect to MySQL
$connect = mysql_connect("localhost","root","diewin") or die("Can't connect to MySQL ".mysql_error());
//select the database
mysql_select_db ("texter");
?>
<?
$title=mysql_real_escape_string($_POST['title']);
$date=mysql_real_escape_string($_POST['date']);
$text=mysql_real_escape_string($_POST['text']);
$query_details = "INSERT INTO details (title, date) VALUES ('$title', '$date')";
mysql_query($query_details);
$last_id=mysql_insert_id();
$query_texts = "INSERT INTO texts (textid, text) VALUES ('$last_id', '$text')";
mysql_query($query_texts);
$last_id=mysql_insert_id();
mysql_close();
?>