0

こんにちは、これらのコード行を使用して SQL データベースを更新する予定です

  <?php
  //session_start();
  $user=$_SESSION['user_level'];
  // Check if a file has been uploaded
  if(isset($_FILES['fileToUpload'])) {
  // Make sure the file was sent without errors
  if($_FILES['fileToUpload']['error'] == 0) {
    // Connect to the database
    $dbLink = new mysqli('$host', '$user', '$pass', 
    '$tbl_name');
    if(mysqli_connect_errno()) {
        die("MySQL connection failed: ". mysqli_connect_error());
    }

    // Gather all required data
    //$id= mysql_insert_id(); 
    $name = $dbLink->real_escape_string($_FILES['fileToUpload']['name']);
    $mime = $dbLink->real_escape_string($_FILES['fileToUpload']['type']);
    $data = $dbLink->real_escape_string(file_get_contents($_FILES  ['fileToUpload']
    ['tmp_name']));
    $size = intval($_FILES['fileToUpload']['size']);
    // Create the SQL query
    $query = "
        UPDATE userinfo SET resume=$name
            WHERE FirstName=$user";
    // Execute the query
    $result = $dbLink->query($query);}}
    ?>
    <?php 


    move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],   
    "/home/u152912911/public_html/upload/" . $_FILES["fileToUpload"]["name"]);
    ?>

    <?php
    if ($_FILES["fileToUpload"]["error"] > 0)
    {
     echo "Apologies, an error has occurred.";
     echo "Error Code: " . $_FILES["fileToUpload"]["error"];
    }
    else
    {
    move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
    "/home/u152912911/public_html/upload/" . $_FILES["fileToUpload"]["name"]);
    }
    if (($_FILES["fileToUpload"]["type"] == "image/DOC")
    || ($_FILES["fileToUpload"]["type"] == "image/jpeg")
    || ($_FILES["fileToUpload"]["type"] == "image/png" )
    && ($_FILES["fileToUpload"]["size"] < 10000))
    {
    move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
    "/home/u152912911/public_html/upload/" . $_FILES["fileToUpload"]["name"]);

ECHO "Files Uploaded Succesfully";
echo'<script type="text/javascript">

    window.location.href ="resume2.php"
    </script>';
    }
    else
    {
    }
    echo "Your Resume was Successfully Upload";
    ?>

問題は、それが機能しないことです。私の履歴書の列は変わりません。私は何かを逃していますか?エラーが表示されないためです。前もって感謝します!

4

2 に答える 2

1

次の行を使用するだけです

$query = "UPDATE userinfo SET resume='$name' WHERE FirstName='$user'";

それ以外の

$query = "UPDATE userinfo SET resume=$name WHERE FirstName=$user";

やってみなよ。それはうまくいくかもしれません

于 2013-01-05T11:01:27.980 に答える
0

次を試してください:

PHP 部分:

<?php
$host = 'Your Host Name';
$user = 'Your Database Username';
$pass = 'Your Database Password';
$db_name = 'Your Database Name';
$first_name = 'john';//Here your session user firstname

//Check if a file has been uploaded

if(isset($_FILES['fileToUpload'])) {

// Connect to the database
$dbLink = new mysqli(''.$host.'', ''.$user.'', ''.$pass.'',''.$db_name.'');

/*
 * This is the "official" OO way to do it,
 * BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
 */
if ($dbLink->connect_error) {
    die('Connect Error (' . $dbLink->connect_errno . ') '. $dbLink->connect_error);
}

$name       = $_FILES['fileToUpload']['name'];
$mime       = $_FILES['fileToUpload']['type'];
$temp_name  = $_FILES['fileToUpload']['tmp_name'];
$size       = intval($_FILES['fileToUpload']['size']);
$first_name = $_POST['first_name'];

if(($_FILES["fileToUpload"]["type"] == "image/DOC") || ($_FILES["fileToUpload"]["type"] == "image/jpeg") || ($_FILES["fileToUpload"]["type"] == "image/png" ) && ($_FILES["fileToUpload"]["size"] < 10000)) {

 // Create the SQL query
 $query = "UPDATE `userinfo` SET `resume`='$name' WHERE `FirstName`='$first_name'";
 // Execute the query
 $result = $dbLink->query($query);

 move_uploaded_file($temp_name,"gallery3/".$name);

 echo "Files Uploaded Succesfully";

}
else {
 echo "Apologies, an error has occurred.";
 echo "Error Code: " . $_FILES["fileToUpload"]["error"];
}
}
?>

HTML 部分 :

<form action="" method="post" enctype="multipart/form-data" name="fileupload">
<input type="file" name="fileToUpload">
<input type="hidden" name="first_name" value="<?php echo $first_name;?>">
<input type="submit" name="uploading" value="File Upload">
</form>

これはあなたの問題を解決するのに役立つかもしれないと思います.

于 2013-01-05T11:21:59.430 に答える