data submit error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deepaks85
    New Member
    • Aug 2006
    • 114

    data submit error

    Dear Friends,

    I have a small problem....but hope you guys can help me out...I am unable to submit data into my database.

    Here is the code......

    filesubmit.htm

    [HTML]<html>
    <head>
    <title>
    My Test database file
    </title>
    </head>
    <body>

    <form method="POST" name="upload" action="dbtestf ilesubmit.php">
    <p>
    <input type="file" name="file" size="40"></p>
    <p><input type="submit" value="Submit" name="submit">
    <input type="reset" value="Reset" name="reset"></p>
    </form>

    </body>[/HTML]

    dbtestfilesubmi t.php

    [PHP]<?php
    //Connect To Database
    $hostname="mysq l.secureserver. net";
    $username="mydb ";
    $password="deep ak";
    $dbname="mydb";
    $usertable="tes t";
    $yourfield = "file";

    mysql_connect($ hostname,$usern ame, $password) OR DIE ("Unable to connect to database! Please try again later.");
    mysql_select_db ($dbname);

    $file = $_POST['file'];
    //$file = "{$_FILES['file']['name']}";

    $insert_query = ("INSERT INTO $usertable VALUES ('$file')");

    if(!@mysql_quer y ($query)) {
    echo mysql_error();
    }else{
    echo "<br>File". $_FILES['file']['name']." uploaded<br>";

    }


    ?> [/PHP]

    Please tell me where I am doing wrong.

    Thanks
    Deepak
    Last edited by deepaks85; Apr 25 '07, 11:39 PM. Reason: wrong information
  • prashanth023
    New Member
    • Apr 2007
    • 13

    #2
    Hi,

    use enctype="multip art/form-data" in form tag for getting file .

    i.e. <<form name="frmadd" action="" method="" enctype="multip art/form-data">


    and also use $_FILE[file_name]name] to get file name.



    And i Think we can insert only file name. not the entire data using ur code.

    If you want to insert all the date so use file concepts read the data form file and store in one variable then insert into the table.
    try it

    Comment

    • deepaks85
      New Member
      • Aug 2006
      • 114

      #3
      Thanks man...........i t worked for me...........



      Originally posted by prashanth023
      Hi,

      use enctype="multip art/form-data" in form tag for getting file .

      i.e. <<form name="frmadd" action="" method="" enctype="multip art/form-data">


      and also use $_FILE[file_name]name] to get file name.



      And i Think we can insert only file name. not the entire data using ur code.

      If you want to insert all the date so use file concepts read the data form file and store in one variable then insert into the table.
      try it

      Comment

      Working...