www.webdeveloper.com
Results 1 to 4 of 4

Thread: parameter is not entering in xmlhttp.open( "POST", 'show.php', true);

  1. #1
    Join Date
    Jan 2014
    Posts
    2

    parameter is not entering in xmlhttp.open( "POST", 'show.php', true);

    my code is uploading anything what i want. Problem is that it is not entering in the page show.php. Although i did debug and failed to understand why this is not going to other page.

    **show.php**

    <?php
    echo"heloo00";
    $con=mysql_connect("localhost","root",'');
    mysql_select_db("project",$con) or die("error db");

    $sql="select * from upload";
    $query=mysql_query($sql);
    while($row=mysql_fetch_array($query))
    {
    $image=$row ['name'];

    echo '<img src="data:image/png;base64,' . base64_encode( $row['content'] ) . '" />';
    }
    ?>

    **test.php**

    <html>
    <head>
    <style>
    #boox{
    overflow:auto;
    width:600px;
    height:400px;
    }
    </style>

    <script>
    alert("helo");
    </script>
    <script>

    function pict()
    { alert("hel");
    xmlhttp = new XMLHttpRequest();
    var picInput = document.getElementById('userfile').value;
    var uploadpic = document.getElementById('upload').value;
    document.getElementById('usf').innerHTML = picInput;
    document.getElementById('upic').innerHTML = uploadpic;
    xmlhttp.onreadystatechange = function () {

    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    var resp = xmlhttp.responseText;
    alert(resp);
    } alert("a");
    xmlhttp.open( "POST", 'show.php', true); //POST Because you use $_POST in php
    xmlhttp.send();
    }

    }
    </script>
    </head>
    <div id="boox">
    <?php
    if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
    {
    $fileName = $_FILES['userfile']['name'];
    $tmpName = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];
    $fp = fopen($tmpName, 'r');
    $content = fread($fp, filesize($tmpName));
    $content = addslashes($content);
    fclose($fp);
    if(!get_magic_quotes_gpc())
    {
    $fileName = addslashes($fileName);
    }
    $con=mysql_connect("localhost","root",'');
    mysql_select_db("project",$con) or die("error db");

    $query = "INSERT INTO upload (name, size, type, content ) ".
    "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
    mysql_query($query) or die('Error, query failed');
    mysql_close($con);
    echo "<br>File $fileName uploaded<br>";

    }
    ?>
    </div>
    <body>
    <form method="post" enctype="multipart/form-data">
    <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
    <input name="userfile" type="file" id="userfile">
    <input name="upload" type="submit" onClick="pict()" class="box" id="upload" value=" Upload ">
    </form>
    </body>
    </html>

  2. #2
    Join Date
    Jan 2014
    Posts
    2
    no one????

  3. #3
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,656
    what you mean by xmlhttp.open( "POST", 'show.php', true); //POST Because you use $_POST in php ?
    there is nothing dealing with $_POST in your show.php code

    and please use the [code]code goes here[/code] tags when posting code
    Last edited by Padonak; 01-14-2014 at 11:28 AM.

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,414
    Also... storing images inside a database has a toll on the server turn around, get allot of requests and the server gives up.

    Databases are meant to serve data, just because someone has found a way to stuff a database with data and files doesn't mean that you should.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles