Witam!
Mam problem z jednym z formularzy. Problem tkwi w tym że wysyła sie ona po kilka razy - do bazy danych dodaje się więcej rekordów niż powinno. Czasami po 2-3 a nie 1 jak powinno być.
Kod:
<?php
require("connection.php");
connection();
$username = ($_POST['username']);
$status = $_POST['status'];
$url = $_POST['url'];
$data = $_POST['data'];
$zapytanie = "INSERT INTO `mproof` VALUES(' ','$username','$status','$url','$data')";
$dir = "./proof/"; //Change this to the correct dir RELATIVE TO WHERE THIS SCRIPT IS, or /full/path/
//MIME types to allow, Gif, jpeg, zip ::Edit this to your liking
$types = array("image/png","image/x-png","image/gif","image/jpeg","image/pjpeg","image/jpg","image/bmp");
// Nothing to edit below here.
//Function to do a directory listing
function CPGscandir($dirstr) {
}
//Check to determine if the submit button has been pressed
if(isset($_POST['submit'])){
//Shorten Variables
$tmp_name = $_FILES['upload']['tmp_name'];
$new_name = $rand.$_FILES['upload']['name'];
$path = $_POST['subdir'];
$fullpath = "$dir$path/";
// lets see if we are uploading a file or doing a dir listing
if(isset($_POST['Dir'])){ echo "Directory listing for $fullpath\n"; scandir("$fullpath");
}else{
//Check MIME Type
// create a sub-directory if required
mkdir("$fullpath", 0755
); }
//Move file from tmp dir to new location
echo "<br />Your proof is uploaded correctly!";
}else{
//Print Error Message
echo "<small>File <strong><em>{$_FILES['upload']['name']}</em></strong> Was Not Uploaded - bad file type or file already exists</small><br />"; //Debug
$name = $_FILES['upload']['name'];
$type = $_FILES['upload']['type'];
$size = $_FILES['upload']['size'];
$tmp = $_FILES['upload']['name'];
echo "Name: $name<br />Type: $type<br />Size: $size<br />Tmp: $tmp";
}
}
} else {
} ?>
<br />
<div id="TOS">
<form action="" method="post" enctype="multipart/form-data">
Please upload your payment proof it will help us to grow faster and make our website even more reliable.<br /><br /><br />
<input type="hidden" name="username" value="<?=$_SESSION['login']?>"/>
<input type="hidden" name="status" value="Approved"/>
<input type="hidden" name="url" value="Test"/>
<input type="hidden" size="40" value="
<? $dzien0=date("d"); $miesiac0=date("m"); $rok0=date("Y"); echo "$rok0-$miesiac0-$dzien0"; ?>" name="data">
<input type="file" name="upload" /> <br /><br />
<input type="submit" name="submit" value="Upload" />
</form>
</div>
Kolejnym problemem jest to że nie przesyła się informacja z pola username, zawsze używałem tej samej metody tzn.
<?=$_SESSION['login']?>
i wszystko się pięknie przesyłało. Czy może mieć na to wpływ rodzaj formularza ?
Ten post edytował boro11 22.09.2011, 14:23:03