Page 1 of 1

am not able to upload doc file

Posted: Wed Feb 25, 2009 5:39 am
by ms_dos10
am not able to upload file i need some one to help me im my way


Code: Select all

<?php require_once('Connections/config.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
 
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO tbl_sheets (id_sheets, id_semster, id_course, she_name, she_ext) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id_sheets'], "int"),
                       GetSQLValueString($_POST['id_semster'], "int"),
                       GetSQLValueString($_POST['id_course'], "int"),
                       GetSQLValueString($_POST['she_name'], "text"),
                       GetSQLValueString($_POST['she_ext'], "text"));
 
  mysql_select_db($database_config, $config);
  $Result1 = mysql_query($insertSQL, $config) or die(mysql_error());
 
  $insertGoTo = "confirmRegSheets.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
 
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO tbl_sheets (id_sheets, id_semster, id_course, she_name, she_ext) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id_sheets'], "int"),
                       GetSQLValueString($_POST['id_semster'], "int"),
                       GetSQLValueString($_POST['id_course'], "int"),
                       GetSQLValueString($_POST['she_name'], "text"),
                       GetSQLValueString($_POST['she_ext'], "text"));
 
  mysql_select_db($database_config, $config);
  $Result1 = mysql_query($insertSQL, $config) or die(mysql_error());
 
  $insertGoTo = "confirmRegSheets.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
 
mysql_select_db($database_config, $config);
$query_regsheets = "SELECT * FROM tbl_sheets";
$regsheets = mysql_query($query_regsheets, $config) or die(mysql_error());
$row_regsheets = mysql_fetch_assoc($regsheets);
$totalRows_regsheets = mysql_num_rows($regsheets);
 
mysql_select_db($database_config, $config);
$query_getIDCourse = "SELECT * FROM tbl_course";
$getIDCourse = mysql_query($query_getIDCourse, $config) or die(mysql_error());
$row_getIDCourse = mysql_fetch_assoc($getIDCourse);
$totalRows_getIDCourse = mysql_num_rows($getIDCourse);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
    font: 100% Verdana, Arial, Helvetica, sans-serif;
    background: #666666;
    margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
    padding: 0;
    text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
    color: #000000;
}
.oneColLiqCtr #container {
    width: 80%;  /* this will create a container 80% of the browser width */
    background: #FFFFFF;
    margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
    border: 1px solid #000000;
    text-align: left; /* this overrides the text-align: center on the body element. */
}
.oneColLiqCtr #mainContent {
    padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
}
-->
</style></head>
 
<body class="oneColLiqCtr">
 
<div id="container">
  <div id="mainContent">
    <h1>Reg Sheets </h1>
    <p>&nbsp;</p>
    
   
    
    
 
    
    
    <form enctype="multipart/form-data" action="<?php echo $editFormAction; ?>" method="POST">
 
      <table align="center">
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Id_sheets:</td>
          <td colspan="2"><input type="text" name="id_sheets" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Id_semster:</td>
          <td colspan="2"><select name="id_semster">
              <option value="1" <?php if (!(strcmp(1, ""))) {echo "SELECTED";} ?>>One</option>
              <option value="2" <?php if (!(strcmp(2, ""))) {echo "SELECTED";} ?>>Two</option>
              <option value="3" <?php if (!(strcmp(3, ""))) {echo "SELECTED";} ?>>Three</option>
              <option value="4" <?php if (!(strcmp(4, ""))) {echo "SELECTED";} ?>>Four</option>
              <option value="5" <?php if (!(strcmp(5, ""))) {echo "SELECTED";} ?>>Five</option>
              <option value="6" <?php if (!(strcmp(6, ""))) {echo "SELECTED";} ?>>Six</option>
              <option value="7" <?php if (!(strcmp(7, ""))) {echo "SELECTED";} ?>>Seven</option>
              <option value="8" <?php if (!(strcmp(8, ""))) {echo "SELECTED";} ?>>Eigth</option>
              <option value="9" <?php if (!(strcmp(9, ""))) {echo "SELECTED";} ?>>Nine</option>
              <option value="10" <?php if (!(strcmp(10, ""))) {echo "SELECTED";} ?>>Ten</option>
            </select>          </td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Id_course:</td>
          <td colspan="2"><select name="id_course">
            <?php
do {  
?>
            <option value="<?php echo $row_getIDCourse['id_course']?>"<?php if (!(strcmp($row_getIDCourse['id_course'], $row_getIDCourse['id_course']))) {echo "selected=\"selected\"";} ?>><?php echo $row_getIDCourse['course_name']?></option>
            <?php
} while ($row_getIDCourse = mysql_fetch_assoc($getIDCourse));
  $rows = mysql_num_rows($getIDCourse);
  if($rows > 0) {
      mysql_data_seek($getIDCourse, 0);
      $row_getIDCourse = mysql_fetch_assoc($getIDCourse);
  }
?>
                      </select>          </td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">She_name:</td>
          <td colspan="2"><input type="text" name="she_name" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">She_ext:</td>
          <td colspan="2"><input type="file" name="she_ext" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">&nbsp;</td>
          <td><input type="submit" value="Insert record" /></td>
          <td><label>
            <input type="reset" name="Reset" id="button" value="Reset" />
          </label></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <!-- end #mainContent --></div>
<!-- end #container --></div>
 
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($regsheets);
 
mysql_free_result($getIDCourse);
?>
 

Re: am not able to upload doc file

Posted: Fri Mar 06, 2009 8:54 am
by ms_dos10
NO No One is going to help me thanks You all

Re: am not able to upload doc file

Posted: Fri Mar 06, 2009 9:08 am
by susrisha
I dont really know what you are trying to acheive in the code but there is a problem

Code: Select all

 
$insertSQL = sprintf("INSERT INTO tbl_sheets (id_sheets, id_semster, id_course, she_name, she_ext) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id_sheets'], "int"),
                       GetSQLValueString($_POST['id_semster'], "int"),
                       GetSQLValueString($_POST['id_course'], "int"),
                       GetSQLValueString($_POST['she_name'], "text"),
                       GetSQLValueString($_POST['she_ext'], "text")); //this is where u went wrong..
                       
                       //you will get the name of the file as 
                       $she_ext_file_name = basename($_FILES['she_ext']);
 
If its the content of the file that you want to insert into the DB, you should probably open the file and access the whole content as text.
Any file uploaded through POST will be accessible under $_FILES and not $_POST