Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question loop is not working in php..........help me...

    hi all,
    code below is for inserting an image to database.....control is not entering into the "if" loop when the page is submitted ......i dont know why.....pls help me....

    ---------------------------
    PHP Code:
    <html>
    <head><title>Store binary data into SQL Database</title></head>
    <body>
    <?php
    // code that will be executed if the form has been submitted:
    if ($submit) {

        
    // connect to the database
        // (you may have to adjust the hostname,username or password)

        
    MYSQL_CONNECT("localhost","root","sa");
        
    mysql_select_db("signup");
        
    $data addslashes(fread(fopen($form_data"r"), filesize($form_data)));

        
    $result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
            
    "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");

        
    $idmysql_insert_id();
        print 
    "<p>This file has the following Database ID: <b>$id</b>";

        
    MYSQL_CLOSE();

    } else {

        
    // else show the form to submit new data:
    ?>

        <form method="post" action="<?php echo $PHP_SELF?>" enctype="multipart/form-data">
        File Description:<br>
        <input type="text" name="form_description"  size="40">
        
        <br>File to upload/store in database:<br>
        <input type="file" name="form_data"  size="40">
        <p><input type="submit" name="submit" value="submit">
        </form>

    <?php

    }

    ?>

    </body>
    </html>
    ------------------------------
    CREATE TABLE binary_data (
    id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    description CHAR(50),
    bin_data LONGBLOB,
    filename CHAR(50),
    filesize CHAR(50),
    filetype CHAR(50)
    );

    -----------------------------
    thanks in advance.............
    Last edited by mds8000; 08-04-2007 at 09:34 PM.

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    First of all, please post your code between [code] tags or [php] tags - makes it easier to help you.

    I don't see where you are obtaining the value for $submit, so I'm assuming it's supposed to be from the form.

    Try changing:
    PHP Code:
    if ($submit) { 
    to
    PHP Code:
    if ($_POST['submit']) { 

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy it is showing a warning.....wat to do next........

    Code:
    Warning: fread(): supplied argument is not a valid stream resource in C:\Program Files\Apache Group\Apache2\htdocs\ex.php on line 21

  • #4
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    With the way your server is configured, you can not access any variable submitted by a form simply by using:
    PHP Code:
    $form_data 
    For each such variable, you'll have to use the form:
    PHP Code:
    $_POST['variable_name'
    For more info - http://us2.php.net/manual/en/security.globals.php
    Last edited by PappaJohn; 08-04-2007 at 11:29 PM. Reason: added link

  • #5
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes PappaJohn is right you have to use POST['variable name'] or GET['variable name'] depending upon method in form tag...

    or u can use REQUEST['variable name'].

    try this it should solve your problem.

  • #6
    New to the CF scene
    Join Date
    Aug 2007
    Location
    Kolkata,India
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $data addslashes(fread(fopen($_FILES['form_data']['tmp_name'], "r"), filesize($_FILES['form_data']['tmp_name']))); 


  •  

    Posting Permissions

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