Jump to content

Voor

Members
  • Posts

    4
  • Joined

  • Last visited

Voor's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Thank You for Your reply I found solution. Problem was an array ^^ Input fields were passing empty value into array. So system were like "Oh there is more stuff in array so I need to loop through it". It was doing loop over empty values. I removed empty values from array before upload and it works fine Cheers for help anyway ^^
  2. Hello! Again I have to ask the mighty power of internet for help with a bloody PHP code ^^ So what I need is a file upload with 5 input fields (I can not be bothered to do it different way ^^") and hey it work! Problem is it show crapload of errors as well ^^" I used script from this website and modified it to my needs here it is: HTML: <div id="selectorWrapper"> <div id="selector"> <input type="file" name="img[]" id="files" onchange="PreviewImage();"/> </div> <div id="delwrap"><button type=button id="del" onclick="empty();" >Delete</button></div> </div> <div id="selectorWrapper"> <div id="selector2"> <input type="file" name="img[]" id="files2" onchange="PreviewImage2();"/> </div> <div id="delwrap"><button type=button id="del2" onclick="empty2();" >Delete</button></div> </div> <div id="selectorWrapper"> <div id="selector3"> <input type="file" name="img[]" id="files3" onchange="PreviewImage3();"/> </div> <div id="delwrap"><button type=button id="del3" onclick="empty3();" >Delete</button></div> </div> <div id="selectorWrapper"> <div id="selector4"> <input type="file" name="img[]" id="files4" onchange="PreviewImage4();"/> </div> <div id="delwrap"><button type=button id="del4" onclick="empty4();" >Delete</button></div> </div> <div id="selectorWrapper"> <div id="selector5"> <input type="file" name="img[]" id="files5" onchange="PreviewImage5();"/> </div> <div id="delwrap"><button type=button id="del5" onclick="empty5();" >Delete</button></div> </div> PHP: $target_dir = "adimg/";$allfiles = $_FILES['img']['name'];$allfilestmp =$_FILES['img']['tmp_name'];foreach($allfiles as $singlefile){foreach($allfilestmp as $singlefiletmp){$target_file = $target_dir . uniqid() . basename($singlefile);$uploadOk = 1;$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);// Check if image file is a actual image or fake imageif($singlefiletmp != ""){if(isset($_POST["ad1post"])) { $check = getimagesize($singlefiletmp); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; }}// Check if file already existsif (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0;}// Check file sizeif ($singlefile > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0;}// Allow certain file formatsif($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPEG" ) { echo "Sorry, only JPG, JPEG, PNG files are allowed."; $uploadOk = 0;}// Check if $uploadOk is set to 0 by an errorif ($uploadOk == 0) { echo "Sorry, your file was not uploaded.";// if everything is ok, try to upload file} else { if (move_uploaded_file($singlefiletmp, $target_file)) { echo "The file ". basename($singlefile). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; }}}}}} And here are errors: It looks like it try to upload single files multiple times and I have no clue how to sort it out to stop it. I will be glad for any help given ^^
  3. Ok I sorted it. Problem was a mysqli_real_escape_string. For some reason it blocked a $_POST.
  4. Hello! So I was trying to make a basic registration form for website. Thing is, it kinda send data and insert it into database but not all of it. Name, Last name, Username and Password are not send but email and language are. I can not figure out where is a problem with it. HTML: <form name="reg" action="resscriptsdata.php" method="post" id="reg" onsubmit="return passCheck();"> <div> <label for="name">Name:</label> <input type="text" id="name" name="name" value="" required pattern="[^]+"/> </div> <div> <label for="last_name">Last Name:</label> <input type="text" id="last_name" name="last_name" value="" required pattern="[^]+" /> </div> <div> <label for="username">Username:</label> <input type="text" id="username" name="username" value="" required pattern="[^]+"/> </div> <div> <label for="password1">Password:</label> <input type="password" id="password1" name="password1" value="" required pattern="[^]+"/><span id="passerr"></span> </div> <div> <label for="email">Email:</label> <input type="email" name="email" id="email"/> </div> <div> <label for="lang1">First language</label> <select name="lang1" onChange="callSave(this)" required> <option value="">Select...</option> <option value="English">English</option> <option value="Polish">Polish</option> </select> </div> <div> <label for="lang2">Second language(optional):</label> <select name="lang2" onChange="callSave(this)"> <option value="">Select...</option> <option value="English">English</option> <option value="Polish">Polish</option> </select> </div> <div> <input name="submit" type="submit" id="register" value="Register"/> </div></form> PHP: <?php$con=mysqli_connect("localhost", "root", "", 'login');if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); }/*get form data*/$name = mysqli_real_escape_string($_POST['name']);$last_name = mysqli_real_escape_string($_POST['last_name']);$username = mysqli_real_escape_string($_POST['username']);$password1 = mysqli_real_escape_string($_POST['password1']);$email = mysqli_real_escape_string($_POST['email']);$lang1 = $_POST['lang1'];$lang2 = $_POST['lang2'];/*check if user in database*/$username_check = mysqli_query($con, 'SELECT Username FROM login.users WHERE Username = $username'); if (mysqli_num_rows($username_check) > 0){ header('Location: usererr.php'); };/*check if email in database*/$email_check = mysqli_query($con, 'SELECT Email FROM login.users WHERE Email = $email'); if (mysqli_num_rows($email_check) > 0){ header('Location: emailerr.php'); };/*hash password*/$hash = hash('sha256', $password1);function createSalt(){ $text = md5(uniqid(rand(), true)); return substr($text, 0,3); };$salt = createSalt();$password = hash('sha256',$salt . $hash);$activation = md5($email.time());/*send data*/$reg_query = "INSERT INTO users (Name, Surname, Username, Password, Email, Lang1, Lang2, Salt, Activation) VALUES ('$name', '$last_name', '$username', '$password', '$email', '$lang1', '$lang2', '$salt', '$activation');";mysqli_query($reg_query);mysqli_close;header('Location: regsuc.php'); ?> Database details: Thank You for any help given
×
×
  • Create New...