Hi all,
I've been trying to read up about sessions and cookies, it all kind of makes sense, but I've not really got the jist of it yet.
I have an upload_image page (uploads an image to a database then returns the reults on the same page)
I have a few things that I wish to accomplish:
When the page is refreshed it does not resubmit the data to the database causing duplicate entries.
If the user bookmarks the page or types in the url then it will not display the form (as this service is a paying service and upload_image.php is the redirect from paypal after a successfull transaction)
If the user wants to update their record in the database then the page displays a form to do this.
I know it sounds like a hell of a lot, but I'm not asking for miracles to happen. I've got to learn this, but if anyone could help, then that'd be great 🙂
here is the upload_image.php code:
<html>
<head><title>Image Upload</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<table width="100%" border="0" align="center">
<tr>
<td><div align="center">
<?php include ('header.php') ?>
</div> </td>
</tr>
</table>
<table width="800" border="0" align="center">
<tr>
<td width="2%" rowspan="2" valign="top"><?php include ('column_left.php') ?></td>
<td width="96%" valign="top"><?php
mysql_connect("xxxxx", "xxxxx", "xxxxx");
mysql_select_db("xxxxx");
// code that will be executed if the form has been submitted:
if ((isset($_POST['submit']))&&(isset($_FILES['form_data']))) {
upload();
} else {
show_form();
}//end if
function upload() {
//define variables
$image_file = '';
$image_desc = '';
$type = '';
$size = 0;
$name = '';
$image_file = $_FILES['form_data']['tmp_name'];
$image_desc = $_POST['form_description'];
$type = $_FILES['form_data']['type'];
$size = $_FILES['form_data']['size'];
$name = $_FILES['form_data']['name'];
$clientname = $_POST['form_clientname'];
$clientemail= $_POST['form_clientemail'];
$data = fread(fopen($image_file, "r"), filesize($image_file));
$data = addslashes($data);
$result="INSERT INTO binary_data VALUES (NULL,'". $clientname ."','". $clientemail ."','". $image_desc ."','". $data ."','". $name ."','". $size ."','". $type ."')";
@mysql_query($result) or die(mysql_error());
$id= mysql_insert_id();
// display the results //
echo "<p class=\"box_text\">Thankyou <b>" ?>
<?php $content=mysql_query("SELECT name, filename, email, description FROM binary_data WHERE id='". $id ."'");
if(mysql_num_rows($content)){ ?>
<?php while ($c=mysql_fetch_array($content)){
extract($c);
echo "$name";};
}else{
?>
<?php } ?>
<?php echo "</b></p>" ?>
<?php echo"<p class=\"box_text\">Your image:<br><br>[ <b>$filename</b> ]<br><br>has been successfully entered into our database and is now available for immediate use.</p> "; ?>
<?php echo "<p class=\"box_text\">To view your image please <a href=https://www.blackwidowdesign.co.uk/show_image.php?id=$id target=\"_blank\" class=\"avail\">click here</a>";
echo "<br><br><p class=\"box_text\">To use your secure image please copy and paste the following url:<br><br><span class=\"faq\">https://www.xxxxx.co.uk/show_image.php?id=". $id ."</span><br><br>";
?>
<?php echo "<p class=\"box_text\">Your contact email that you provided us with is:<br><br> [ <b>$email</b> ]</p>"; ?>
<?php echo "<p class=\"box_text\">My we wish you every success with your business <b>$description</b></p>"; ?>
<?php
//show the form again to load the next image
//show_form();
}
function show_form()
{
// else show the form to submit new data:
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<table width="100%" border="0">
<tr>
<td width="112" class="box_text">Your Name</td>
<td width="378"><input name="form_clientname" type="text" class="box_text" size="40"></td>
</tr>
<tr>
<td class="box_text">Email</td>
<td><input name="form_clientemail" type="text" class="box_text" size="40"></td>
</tr>
<tr>
<td class="box_text">Company Name </td>
<td><input name="form_description" type="text" class="box_text" size="40">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000"></td>
</tr>
<tr>
<td class="box_text">File to upload </td>
<td><input name="form_data" type="file" class="box_text" size="40"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit" class="box_text" value="Upload Data"></td>
</tr>
</table>
</form>
<?php
}
?> </td>
<td width="2%" rowspan="2" valign="top"><?php include ('column_right.php') ?></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
many thanks in advance
Mark