473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

File upload into MySQL database failing.

20
Hi. I have a problem here. I want to upload a file together with its semester. So I create two field. One for the semester and one for the file to be uploaded. But the script doesn't work. I don't know why. However, if I try to upload the file without the semester field, the script is working. May be the problem comes from the semester field. This is my codes.

Form.php

?>
Expand|Select|Wrap|Line Numbers
  1. <?php require_once('Connections/connection.php'); ?><?php
  2. if (!isset($_SESSION)) {
  3.   session_start();
  4. }
  5.  
  6. // ** Logout the current user. **
  7. $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
  8. if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  9.   $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
  10. }
  11.  
  12. if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  13.  
  14.   $_SESSION['MM_Username'] = NULL;
  15.   $_SESSION['MM_UserGroup'] = NULL;
  16.   $_SESSION['PrevUrl'] = NULL;
  17.   unset($_SESSION['MM_Username']);
  18.   unset($_SESSION['MM_UserGroup']);
  19.   unset($_SESSION['PrevUrl']);
  20.  
  21.   $logoutGoTo = "login_option.php";
  22.   if ($logoutGoTo) {
  23.     header("Location: $logoutGoTo");
  24.     exit;
  25.   }
  26. }
  27. ?>
  28. <?php
  29. $colname_rsSearchJKM_sem = "-1";
  30. if (isset($_GET['sesi'])) {
  31.   $colname_rsSearchJKM_sem = (get_magic_quotes_gpc()) ? $_GET['sesi'] : addslashes($_GET['sesi']);
  32. }
  33. mysql_select_db($database_connection, $connection);
  34. $query_rsSearchJKM_sem = sprintf("SELECT sesi FROM sesi");
  35. $rsSearchJKM_sem = mysql_query($query_rsSearchJKM_sem, $connection) or die(mysql_error());
  36. $row_rsSearchJKM_sem = mysql_fetch_assoc($rsSearchJKM_sem);
  37. $totalRows_rsSearchJKM_sem = mysql_num_rows($rsSearchJKM_sem);
  38. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  39. <html xmlns="http://www.w3.org/1999/xhtml">
  40. <head>
  41. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  42. <title>Untitled Document</title>
  43. <style type="text/css">
  44. <!--
  45. body {
  46.     background-image: url(images/backgrounding.gif);
  47.     background-repeat: no-repeat;
  48.     background-attachment: fixed;
  49. }
  50. -->
  51. </style></head>
  52.  
  53. <body>
  54. <div align="center">
  55. <table width="828" border="2">
  56.   <!--DWLayoutTable-->
  57.   <tr>
  58.     <td width="822" height="148" valign="top" bgcolor="#6699FF"><form id="form1" name="form1" method="post" action="">
  59.       <img src="banner/header.gif" width="822" height="128" />
  60.       <?php include 'selamat_datang.php'; ?>
  61.       <?php include 'jam.php'; ?>
  62.       <?php include 'dropDOwn.php'; ?>
  63.     </form></td>
  64.   </tr>
  65.   <tr>
  66.     <td height="32" valign="top" bgcolor="#6699FF"><p align="right">&nbsp;<a href="<?php echo $logoutAction ?>"><font color='#FF0000'>Keluar</font></a></p>
  67.         <p align="center">
  68.         <p align="center" style="font-family:'Lucida Handwriting'; font-size: 24px; color:#990000"><strong>JABATAN KEJURUTERAAN MEKANIKAL</strong></p>        
  69.         <p align="center">        
  70.         <p align="center">
  71.         <form action="Upload.php" method="post">
  72.         <div align="left"><strong>SESI:</strong>
  73.         <select name="uploaded_file" type="file" id="uploaded_file" &nbsp;name="uploaded_file">
  74.         <?php 
  75.             $sql="SELECT sesi FROM sesi";
  76.             $result =mysql_query($sql);
  77.             while ($data=mysql_fetch_assoc($result))
  78.             {
  79.                  echo "<option value=\"{$data['sesi']}\">{$data['sesi']}</option>";
  80.                 }
  81.             ?>
  82.           </select>
  83.          </p>
  84.             <p>     
  85.           <div align="left">
  86.                 <p><strong>ABSTRAK:</strong>
  87.                       <input name="uploaded_file" type="file" size="40" id="uploaded_file"&nbsp;name="uploaded_file" />
  88.               </p>
  89.                 <p><br />
  90.                       <input type="submit"&nbsp;value="Upload file" />
  91.                   </p>
  92.                         </p>
  93.         </form>
  94.  
  95. <p>&nbsp;    </p>
  96. <p><a href="listJKM.php">Lihat semua abstrak</a>
  97. </p>
  98. *</p>
  99.       <p>&nbsp;</p>
  100.       <p>&nbsp;</p>
  101.       <p>&nbsp;</p></td>
  102.   </tr>
  103.   <tr>
  104.     <td height="18" valign="top" bgcolor="#6699FF"><form id="form4" name="form4" method="post" action="">
  105.       <div align="center">
  106.         <?php include 'copyright.php'; ?>
  107.           </div>
  108.     </form>
  109.     </td>
  110.   </tr>
  111. </table>
  112. </div>
  113. </body>
  114. </html>
  115. <?php
  116. mysql_free_result($rsSearchJKM_sem);
  117. ?>
Upload.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. if (!isset($_SESSION)) {
  4.   session_start();
  5. }
  6.  
  7. // ** Logout the current user. **
  8. $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
  9. if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  10.   $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
  11. }
  12.  
  13. if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  14.   $_SESSION['MM_Username'] = NULL;
  15.   $_SESSION['MM_UserGroup'] = NULL;
  16.   $_SESSION['PrevUrl'] = NULL;
  17.   unset($_SESSION['MM_Username']);
  18.   unset($_SESSION['MM_UserGroup']);
  19.   unset($_SESSION['PrevUrl']);
  20.  
  21.   $logoutGoTo = "login_option.php";
  22.   if ($logoutGoTo) {
  23.     header("Location: $logoutGoTo");
  24.     exit;
  25.   }
  26. }
  27. ?>
  28. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  29. <html xmlns="http://www.w3.org/1999/xhtml">
  30. <head>
  31. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  32. <title>Untitled Document</title>
  33. <style type="text/css">
  34. <!--
  35. body {
  36.     background-image: url(images/backgrounding.gif);
  37.     background-repeat: no-repeat;
  38.     background-attachment: fixed;
  39. }
  40. -->
  41. </style></head>
  42.  
  43. <body>
  44. <div align="center">
  45. <table width="828" border="0">
  46.   <!--DWLayoutTable-->
  47.   <tr>
  48.     <td width="822" height="148" valign="top" bgcolor="#6699FF"><form id="form1" name="form1" method="post" action="">
  49.       <img src="banner/header.gif" width="822" height="128" />
  50.       <?php include 'selamat_datang.php'; ?>
  51.       <?php include 'dropDown.php'; ?>
  52.     </form></td>
  53.   </tr>
  54.   <tr>
  55.     <td height="32" valign="top" bgcolor="#6699FF"><p align="right">&nbsp;<a href="<?php echo $logoutAction ?>"><font color='#FF0000'>Keluar</font></a></p>
  56.         <p align="center">
  57. <?php
  58.  
  59. if(isset($_FILES['uploaded_file'])) 
  60.  
  61.     if($_FILES['uploaded_file']['error'] == 0) 
  62.     {
  63.  
  64.         $dbLink = mysqli_connect("localhost", "root", "", "inovasi");
  65.         if(mysqli_connect_errno()) {
  66.             die("MySQL connection failed: ". mysqli_connect_error());
  67.         }       
  68.         $sesi = mysqli_real_escape_string($dbLink, $_FILES['uploaded_file']['sesi']);
  69.         $name = mysqli_real_escape_string($dbLink, $_FILES['uploaded_file']['name']);
  70.         $mime = mysqli_real_escape_string($dbLink, $_FILES['uploaded_file']['type']);
  71.         $size = $_FILES['uploaded_file']['size'];
  72.         $data = mysqli_real_escape_string($dbLink, file_get_contents($_FILES  ['uploaded_file']['tmp_name']));
  73.  
  74.         $query = "
  75.             INSERT INTO FileStorage (
  76.                 FileName, FileMime, FileSize, FileData, Created, sesi
  77.             )
  78.             VALUES (
  79.                 '{$name}', '{$mime}', {$size}, '{$data}', NOW(), '{$sesi}'
  80.             )";
  81.  
  82.         $result = mysqli_query($dbLink, $query);
  83.  
  84.         if($result) 
  85.         {
  86.             echo "Berjaya! Abstrak telah di upload.";
  87.         }
  88.         else 
  89.         {
  90.             echo "Error! Failed to insert the file";
  91.             echo "<pre>". mysqli_error($dbLink) ."</pre>";
  92.         }
  93.     }
  94.     else 
  95.     {
  96.         echo "Error! 
  97.                 An error accured while the file was being uploaded. 
  98.                 Error code: ". $_FILES['uploaded_file']['error'];
  99.     }
  100.     mysqli_close($dbLink);
  101. }
  102. else 
  103. {
  104.     echo "Gagal! Abstrak tidak berjaya di upload!";
  105. }
  106. echo '<p>Klik <a href="JKM_admin.php">di sini</a> untuk kembali</p>';
  107. ?>
  108.  
  109. &nbsp;</p>
  110.       </td>
  111.   </tr>
  112.   <tr>
  113.     <td height="18" valign="top" bgcolor="#6699FF"><form id="form4" name="form4" method="post" action="">
  114.       <div align="center">
  115.         <?php include 'copyright.php'; ?>
  116.           </div>
  117.     </form>
  118.     </td>
  119.   </tr>
  120. </table>
  121. </div>
  122. </body>
  123. </html>
  124.  
Someone please help me...Thanks
Jul 1 '09 #1
1 2232
dlite922
1,584 Expert 1GB
That's too much code to go through and find one problem. Have you done your part of troubleshooting? what's the semester field? if with it, it fails, have you tried looking into to see if it's correct?

can you run a manual test query with the semester field from a client?

At least trace the problem (follow the values with die(print_r($value)) lines) until you find the code that doesn't do what it's suppose to do.


Good luck,







Dan
Jul 1 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Alper Adatoz | last post by:
Hi, i have a little problem. i hope u guys give me a clear solution (: db: mssql i just want to put jpeg file to the image field at the mssql db. and after that i want to call it back..
1
by: windandwaves | last post by:
Hi Folk I want my clients to load up a file to a MySql database. The file should contain rows with name, email, address, city What would be the easiest way (in terms of the big picture), to...
4
by: news | last post by:
Our production database in an exported textfil runs about 60 MB. Compressed that's about 9 MB. I'm trying to import the export into another machine running FC3 and mySQL 11.18, and it appears as...
7
by: Nathan Sokalski | last post by:
I have a form that allows the user to upload a file. Even though <input type="file" runat="server"> is intended to have the user choose the file using the browse button, it still allows them to...
0
by: slingare | last post by:
Hi, I am new to asp.net and I am having a problem when I try to upload a word document from asp.net to Mysql database. I have a field of type mediumblob in mysql table. I looked for some...
3
by: siyaverma | last post by:
i am trying to upload csv file from user's computer to main server the code i am using is if(((isset($_GET)) && ($_GET=="yes")) ) { $typefield = $_GET; echo...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
6
Jacotheron
by: Jacotheron | last post by:
I need a PHP script that can upload music files (mp3). The script is for a home project I have started a while ago. I have a MySQL database of all the music that I have. Other computers on the...
8
johngault
by: johngault | last post by:
I've been working with this PHP page for several days now and I'm stumped. The page is supposed to allow the user to upload up to six images for their profile. When the user adds an image it (the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.