Hi
I am trying to get a file uploaded onto the ftp server and get the filepath stored in the mysql database, I have got the location stored in the database but the file is not uploading onto the server, I have tried a .doc file and a .png file and keeps saying the same error
Form has been submitted successfully.
Warning: move_uploaded_file(candidatescvs/testimonials.png): failed to open stream: No such file or directory in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/recruitment-site/candidates-signup.php on line 88 Warning: move_uploaded_file(): Unable to move ‘/tmp/phpQgIPaN’ to ‘candidatescvs/testimonials.png’ in /home/sites/broadwaymediadesigns.co.uk/public_html/sites/recruitment-site/candidates-signup.php on line 88 Sorry, there was a problem uploading your file.
MySQL error no 1062 : Duplicate entry ‘ianhaney’ for key ‘username’
All the data is being saved correctly apart from the dob gets stored as 0000-00-00 in the database but will sort that issue after
I can’t work out why the file is being uploaded onto the ftp server, the coding is below
[code=php]
<?php
ini_set(‘display_startup_errors’,1);
ini_set(‘display_errors’,1);
error_reporting(-1);
?>
<?php
require_once(“functions.php”);
require_once(“db-const.php”);
?>
<?php
$title = “Candidates Signup – Recruitment Site”;
$pgDesc=””;
$pgKeywords=””;
include ( ‘includes/header.php’ );
?>
<!–CONTENT–>
<?php
if (isset($_POST[‘submit’]) && isset($error) == ”) { // if there is no error, then process further
echo “<p class=’success’>Form has been submitted successfully.</p>”; // showing success message
## connect mysql server
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
echo “<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>”;
exit();
}
//This is the directory where images will be saved
$target = “candidatescvs/”;
$target = $target . basename( $_FILES[‘cvfile’][‘name’]);
## query database
# prepare data for insertion
$username = mysqli_real_escape_string($mysqli, $_POST[‘username’]);
$password = md5($_POST[‘password’]);
/*$password = $_POST[‘password’];*/
$name = mysqli_real_escape_string($mysqli, $_POST[‘name’]);
$dob = ($_POST[‘dob’]);
$email = mysqli_real_escape_string($mysqli, $_POST[’email’]);
$address1 = mysqli_real_escape_string($mysqli, $_POST[‘address1’]);
$address2 = mysqli_real_escape_string($mysqli, $_POST[‘address2’]);
$town = mysqli_real_escape_string($mysqli, $_POST[‘town’]);
$county = mysqli_real_escape_string($mysqli, $_POST[‘county’]);
$postcode = mysqli_real_escape_string($mysqli, $_POST[‘postcode’]);
$telnumber = mysqli_real_escape_string($mysqli, $_POST[‘telnumber’]);
$mobnumber = mysqli_real_escape_string($mysqli, $_POST[‘mobnumber’]);
$worklocation = mysqli_real_escape_string($mysqli, $_POST[‘worklocation’]);
$desiredsalary = mysqli_real_escape_string($mysqli, $_POST[‘desiredsalary’]);
$currentempstatus = mysqli_real_escape_string($mysqli, $_POST[‘currentempstatus’]);
$educationlevel = mysqli_real_escape_string($mysqli, $_POST[‘educationlevel’]);
$availableforwork = mysqli_real_escape_string($mysqli, $_POST[‘availableforwork’]);
$jobtype = mysqli_real_escape_string($mysqli, $_POST[‘jobtype’]);
$cv = ($_FILES[‘cvfile’][‘name’]);
# check if username and email exist else insert
// u = username, e = emai, ue = both username and email already exists
$exists = “”;
$result = $mysqli->query(“SELECT username from candidates WHERE username = ‘{$username}’ LIMIT 1”);
if ($result->num_rows == 1) {
$exists .= “u”;
}
$result = $mysqli->query(“SELECT email from candidates WHERE email = ‘{$email}’ LIMIT 1”);
if ($result->num_rows == 1) {
$exists .= “e”;
}
if ($exists == “u”) echo “<p><b>Error:</b> Username already exists!</p>”;
else if ($exists == “e”) echo “<p><b>Error:</b> Email already exists!</p>”;
else if ($exists == “ue”) echo “<p><b>Error:</b> Username and Email already exists!</p>”;
else {
# insert data into mysql database
$sql = “INSERT INTO `candidates` (`id`, `username`, `password`, `name`, `dob`, `email`, `address1`, `address2`, `town`, `county`, `postcode`, `telnumber`, `mobnumber`, `worklocation`, `desiredsalary`, `currentempstatus`, `educationlevel`, `availableforwork`, `jobtype`, `cvfile`)
VALUES (NULL, ‘{$username}’, ‘{$password}’, ‘{$name}’, ‘{$dob}’, ‘{$email}’, ‘{$address1}’, ‘{$address2}’, ‘{$town}’, ‘{$county}’, ‘{$postcode}’, ‘{$telnumber}’, ‘{$mobnumber}’, ‘{$worklocation}’, ‘{$desiredsalary}’, ‘{$currentempstatus}’, ‘{$educationlevel}’, ‘{$availableforwork}’, ‘{$jobtype}’, ‘{$cv}’)”;
$result = $mysqli->query($sql);
$id = $mysqli->insert_id;
//Writes the photo to the server
if(move_uploaded_file($_FILES[‘cvfile’][‘tmp_name’], $target))
{
//Tells you if its all ok
echo “The file “. basename( $_FILES[‘cvfile’][‘name’]). ” has been uploaded, and your information has been added to the directory”;
}
else {
//Gives and error if its not
echo “Sorry, there was a problem uploading your file.”;
}
$dob = date(‘Y-m-d’, strtotime($_POST[‘dob’]));
if ($mysqli->query($sql)) {
$to = $_POST[’email’];
$subject = “Login Credentials”;
$message = “Thank you for signing up, your login information is below rn Username: {$_POST[‘username’]} rn Password: {$_POST[‘password’]}”;
$header = “From:[email protected] rn”;
$retval = mail ($to,$subject,$message,$header);
if( $retval == true )
{
echo “Message sent successfully…”;
}
else
{
echo “Message could not be sent…”;
}
redirect_to(“candidates-login.php?msg=Registered successfully”);
} else {
echo “<p>MySQL error no {$mysqli->errno} : {$mysqli->error}</p>”;
exit();
}
}
}
?>
<!– The HTML registration form –>
<form method=”post” action=”<?=$_SERVER[‘PHP_SELF’]?>” enctype=”multipart/form-data”>
<br />
<label>Upload CV: </label>
<input type=”hidden” name=”size” value=”350000″>
<input type=”file” name=”cvfile”>
<br /><br />
<input type=”submit” name=”submit” value=”Register” disabled=”disabled” id=”submitBtn” />
</form>
<!–CONTENT–>
I took out all the other fields in the form and just left the upload cv coding in the form