Its the insert form that doesnt work, it wont connect to the mysql database 🙁
Whats wrong guys?
EDIT:
iv put the insert code in both index.php and insert.php just to see if it mattered.(it didnt)
Here is my index.php file.
<?php
function texter()
{
global $conn;
$conn = mysql_connect("localhost", "root", "diewin") or die(mysql_error());
mysql_select_db("texter",$conn) or die(mysql_error());
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
Sök efter: <input type="text" size="25" name="searchfor" /><br />
<input type="submit" value="Sök!" />
</form>
<?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 />";
}
?>
<form action=insert.php method=post>
Title: <input type="text" name="title"><br>
Date: <input type="text" name="date"><br>
text: <input type="text" name="text"><br>
<input type="Submit">
</form>
<?
$title=$POST['title'];
$date=$POST['date'];
$text=$_POST['text'];
mysql_connect($localhost,$root,$diewin);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO details VALUES ('','$title','$date')";
$query = "INSERT INTO details VALUES ('','$text')";
mysql_query($query);
mysql_close();
?>
</html>
My database structure:
create database texter;
create table details (textid int not null primary key auto_increment,title varchar(255),date date);
create table texts (textid int not null,text longtext);