0

file does not appear

hi guys, i having problem with my forms which i already set a value from my database which my file input doesn't appear out from database. who have idea what problem? the datatype i using for file in mysql is medium blob which stores the file in a folder called upload. first code is my editquiz.php, while second codes is my pedit.php.

     <form method ="post" action = "peditQuiz.php" enctype="multipart/form-data">
                <input type = "hidden" name = "quizID" id="quizID" value = "<?php echo $st_row['q_id'] ?>" >
                      <div class="form-group">
                      <h4><b>Quiz ID: <span class="text-primary"><?php echo $st_row['q_id'] ?></span> </b></h4>

                      </div>
                      <hr>
                      <div class="form-group">
                        <label>Quiz Title</label>
                        <input type="text" class="form-control" name = "quizTitle" id="quizTitle" value = "<?php echo $st_row['q_title'] ?>" required>
                      </div>
                      <div class="form-group">
                        <label>Quiz Description</label>
                        <input type="text" class="form-control" name = "quizDesc" id="quizDesc" value = "<?php echo $st_row['q_desc'] ?>" required >
                      </div>
                      <div class="form-group">
                        <label>Quiz URL (paste the link here)</label>
                        <input type="url" class="form-control" name = "quizURL" id="quizURL" value = "<?php echo $st_row['q_url'] ?>">
                      </div>


                      <div class="form-group">
                        <label>Upload new Quiz file (Max. allowed file size is 8MB)</label>
                        <input type="file" class="form-control"  name = "quizFile" id ="quizFile" value = "<?php echo $st_row['q_file'] ?>" placeholder = "<?php echo $st_row['q_file'] ?>">

                      </div>

                       <input type="submit" class="btn btn-default" name = "btnUpdate" value = "Update">
                      <input type="reset"  class="btn btn-default" value = "Clear"> 
                      <a href = "manageQuiz.php"><button type="button"  style = "float:right" class="btn btn-info" >Back</button></a>


//Pedit.php
<?php
include("connection.php");

    $userid =  $_SESSION['userID'];
    $title= $_POST['quiz_Title'];
    $desc = $_POST['quiz_Desc'];
    $url = $_POST['quiz_URL'];

    $file = rand(1000, 100000). "-".$_FILES['quiz_File']['name'];
    $file_loc = $_FILES['quiz_File']['tmp_name'];
    $file_size = $_FILES['quiz_File']['size'];
    $file_type = $_FILES['quiz_File']['type'];
    $folder="files/";

    move_uploaded_file($file_loc, $folder.$file);

    /*
    $id = $_POST['quizID'];
    $sql = "SELECT * FROM quiz where quiz_id = '$id'";
    $result = mysql_query($sql) or die(mysql_error()); 
    $row = mysql_fetch_assoc($result);

    $count = mysql_num_rows($result);

    if($count > 0){
        echo "<script>alert('Quiz record already exist');window.location.href = 'addQuiz.php';</script>";
    } else {    */
        if($url==NULL){ 
            $sql = "insert into quiz (q_title, q_desc, q_url, q_file, admin)
            values ('$title','$desc ','$url','$file','$userid ' )" ;
            mysql_query($sql);
            echo "<script>alert('New record created succcessfully');window.location.href = 'manageQuiz.php';</script>";
        } else{
            $sql = "insert into quiz (q_title, q_desc, q_url, admin)
            values ('$title','$desc ','$url','$userid ' )" ;
            mysql_query($sql);
            echo "<script>alert('New record created succcessfully');window.location.href = 'manageQuiz.php';</script>";

        }

    //}



    mysql_close($con);

?>
Mike Lai
  • 9
  • 1
  • 2
    Possible duplicate of [Remember and Repopulate File Input](https://stackoverflow.com/questions/20537696/remember-and-repopulate-file-input) – rickdenhaan Jan 01 '18 at 02:55

1 Answers1

-2

Your question is difficult to follow, but I'll try:

It looks like you are using php to dump values in your form via PHP before you load the values later with your include statement.

I'm also not sure why you are saying that you use a file-based database but also seem to include sql commands, but regardless of how you load values into "$st_row['q_id']", they must be loaded before you attempt to echo them into your html.

If you have a requirement to include the db file later for some reason, you could use javascript to push the values into the form fields after the fact.

If, however, you are looking for the results of the sql queries from an included file ... I think you'll need to specify what value you expected to load from what file and provide that code as well.

Hope that helped. Good luck. Also congrats on asking a question on stackoverflow. Looks like you're a beginner but trying hard. ;)

TheSatinKnight
  • 696
  • 7
  • 16
  • Perhaps add an example demonstrating your suggestions. – Nae Jan 01 '18 at 04:26
  • Seriously: Without a valid idea of what this poster is really looking for, the goal was to offer some guidance and *hope* to have been helpful. Offering random examples when already shooting in the dark would just add confusion until OP posts details. I know that this forum is often populated by those who like to exercise their downvotes to discourage pure "help me!" and "here's some help!" But I still try to help. – TheSatinKnight Jan 19 '18 at 20:43