Hi Guys I have a quick question. I have a form that is collecting Information for a newsletter. In the same page I have the results of the newsletter. What is happening is that after I submit the page to the database with the forms the page is not updating and when I do click reload in the browser it just places duplicate copies in to the Database.
I know this is pretty simple to do I just can't think right now on how to do it.
Thanks for the help!!
Here is my code:
<?php
$title = strip_tags(trim($_POST['title']));
$teaser = strip_tags(trim($_POST['teaser']));
$content = strip_tags(trim($_POST['content']));
$date = $_POST['date'];
?>
<?php
if (isset($_POST["Submit"]))
{
//upload directory.
//change to fit your need eg. files, upload .... etc.
$upload_dir = "_images/right_thing/";
//number of files to upload.
$num_files = 1;
//the file size in bytes.
$size_bytes =151200; //51200 bytes = 50KB.
//Extensions you want files uploaded limited to.
$limitedext = array(".gif",".jpg",".jpeg");
define ("FILE_DIR", "_images/right_thing/");
if (is_uploaded_file($_FILES['file']['tmp_name'])) {
if ($_FILES['file']['type'] !="application/jpg") {
echo "Pictures Must Be in .JPG Format!";
}
else {
$name = $_POST['title'];
$result = move_uploaded_file($_FILES['file']['tmp_name'],FILE_DIR."/$name.jpg");
if ($result == 1) echo "File Successfuly Uploaded.";
else {
echo "There was problem uploading the file";
$query = "INSERT INTO Right_thing (date, title, teaser, content, image) VALUES ('$date', '$title', '$teaser', '$content', '$title')";
$result = mysql_query($query) or die ("couldn't add entry");
}
}
}
}
?>
<body>
<form enctype="multipart/form-data" name="add" method="post" action="">
<table width="75%" border="0">
<tr>
<td width="16%"><div align="right">Title</div></td>
<td width="84%"><input name="title" type="text" id="title"></td>
</tr>
<tr>
<td><div align="right">Teaser Content</div></td>
<td><textarea name="teaser" id="teaser"></textarea></td>
</tr>
<tr>
<td><div align="right">Content</div></td>
<td><textarea name="content" id="content"></textarea></td>
</tr>
<tr>
<td><div align="right">Image</div></td>
<td><input name="file" type="file" id="file">
(File Must Be in .jpg format)</td>
</tr>
</table>
<p><br>
<input name="date" type="hidden" id="date" value= "<?php echo date('Y-m-d'); ?>">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<p> </p>
<p> </p>
<p> </p>
<table width="75%" border="1">
<tr>
<td width="2%">ID</td>
<td width="7%">Date</td>
<td width="19%">Title</td>
<td width="50%">Content</td>
<td width="22%">Image</td>
</tr>
<?php
do { ?>
<tr>
<td><?php echo $row_right_thing ['id']; ?></td>
<td><?php echo $row_right_thing ['date']; ?></td>
<td><?php echo $row_right_thing ['title']; ?></td>
<td><?php echo $row_right_thing ['content']; ?></td>
<td><img src= "_images/right_thing/<?php echo $row_right_thing ['image'];?>"></td>
<td><input type="submit" name="edit" value="Edit" onclick="" /></td>
<td><input type="submit" name="delete" value="Delete" onclick="" /></td>
</tr>
<?php }
while ($row_right_thing = mysql_fetch_assoc($result_right_thing));
?>