Error with saving Form data to MySQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mirianCalin
    New Member
    • Feb 2008
    • 35

    Error with saving Form data to MySQL

    the code saves the category, image title, image, and feature..
    but the problem is that the "feature" is not saved, but the others were saved..
    this is the data types of my table

    category = text
    title = text
    image = longblob
    feature = text

    in html, the users input the feature in (textarea)..
    is there a problem with the code? pls.. help
    [code=php]
    <?php

    // Connect to database

    $errmsg = "";
    if (! @mysql_connect( "localhost","ro ot","")) {
    $errmsg = "Cannot connect to database";
    }
    @mysql_select_d b("upload");

    // Insert any new image into database

    if ($_REQUEST[completed] == 1) {
    // Need to add - check for large upload. Otherwise the code
    // will just duplicate old file ;-)
    // ALSO - note that latest.img must be public write and in a
    // live appliaction should be in another (safe!) directory.
    move_uploaded_f ile($_FILES['imagefile']['tmp_name'],"latest.img ");
    $instr = fopen("latest.i mg","rb");
    $image = addslashes(frea d($instr,filesi ze("latest.img" )));
    if (strlen($instr) < 149000) {
    mysql_query ("insert into sharp (category, title, imgdata, feature) values (\"". $_REQUEST[categ] . "\", \"". $_REQUEST[whatsit] . "\", \"". $image . "\", \"". $feature . "\")");
    } else {
    $errmsg = "Too large!";

    }
    }


    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitl ed Document</title>
    <link href="div.css" rel="stylesheet " type="text/css" />
    </head>
    <body>
    <style type="text/css">

    body
    {
    background-image: url(body.jpg);
    background-repeat: no-repeat;

    background-position: top left;
    }

    </style>


    <h3 align = "left">Plea se upload a new picture and title</h3>
    <form method=post>
    <table border = "0" align = "left">
    <tr>
    <td>Brand:</td>
    <td><select name = "brand">
    <option>SONY</option>
    <option>SHARP </option>
    <option>LG</option>
    <option>PANASON IC</option>
    <option>SAMSUNG </option>
    <option>JVC</option></select></td>
    </tr>

    <tr>
    <td>Category: </td>
    <td><select name = "categ">
    <option>TV</option>
    <option>AUDIO </option>
    <option>WASHI NG MACHINE</option>
    <option>REFRIGE RATOR</option>
    <option>AIR CONDITIONER</option>
    <option>MICROWA VE OVEN</option></select></td>
    </tr>

    <tr>
    <td>Image Title:</td>
    <td><input name=whatsit></td>
    </tr>

    <tr>
    <input type=hidden name=MAX_FILE_S IZE value=150000>
    <input type=hidden name=completed value=1>
    <td>Upload Image:</td>
    <td><input type=file name=imagefile> </td>
    </tr>

    <tr>
    <td>Feature:</td>
    <td><textarea name = "feature"></textarea></td>
    </tr>

    <tr>
    <td></td>
    <td><input type=submit value = "Save"></td>
    </tr>

    </table>
    <br>

    </form><br>


    </body>
    </html>
    [/code]
    Last edited by ak1dnar; Feb 10 '08, 06:24 AM. Reason: Added [Code=php] tags;Thread Title changed
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    In line number 22 (Your SQL Insert Statement), you have to assign the posted textarea value to $feature variable. You should use $_REQUEST['feature'] instead of $featureOr else put this Line before your sql query.
    [PHP]$feature = $_REQUEST['feature'];[/PHP]

    Comment

    • mirianCalin
      New Member
      • Feb 2008
      • 35

      #3
      Originally posted by ak1dnar
      In line number 22 (Your SQL Insert Statement), you have to assign the posted textarea value to $feature variable. You should use $_REQUEST['feature'] instead of $featureOr else put this Line before your sql query.
      [PHP]$feature = $_REQUEST['feature'];[/PHP]
      thanks for correcting me, it worked..
      i was figuring that out the whole day..
      thanks again..

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        You should also try and use single quotes around array indeces!
        [php]
        $_something = $_FILES[file][type]; // baaaad!
        $_something = $_FILES['file']['type'] // good good good!
        [/php]

        Comment

        Working...