By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

Error with saving Form data to MySQL

P: 35
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
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. // Connect to database
  4.  
  5. $errmsg = "";
  6. if (! @mysql_connect("localhost","root","")) {
  7.         $errmsg = "Cannot connect to database";
  8.         }
  9. @mysql_select_db("upload");
  10.  
  11. // Insert any new image into database
  12.  
  13. if ($_REQUEST[completed] == 1) {
  14.         // Need to add - check for large upload. Otherwise the code
  15.         // will just duplicate old file ;-)
  16.         // ALSO - note that latest.img must be public write and in a
  17.         // live appliaction should be in another (safe!) directory.
  18.         move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
  19.         $instr = fopen("latest.img","rb");
  20.     $image = addslashes(fread($instr,filesize("latest.img")));
  21.     if (strlen($instr) < 149000) {
  22.                 mysql_query ("insert into sharp (category, title, imgdata, feature) values (\"". $_REQUEST[categ] . "\", \"". $_REQUEST[whatsit] . "\", \"". $image . "\", \"". $feature . "\")");
  23.         } else {
  24.                 $errmsg = "Too large!";
  25.  
  26.         }
  27. }
  28.  
  29.  
  30. ?>
  31.  
  32. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  33. <html xmlns="http://www.w3.org/1999/xhtml">
  34. <head>
  35. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  36. <title>Untitled Document</title>
  37. <link href="div.css" rel="stylesheet" type="text/css" />
  38. </head>
  39. <body>
  40. <style type="text/css"> 
  41.  
  42. body 
  43. background-image: url(body.jpg);
  44. background-repeat: no-repeat;
  45.  
  46. background-position: top left;
  47. }
  48.  
  49. </style>
  50.  
  51.  
  52. <h3 align = "left">Please upload a new picture and title</h3>
  53. <form method=post>
  54. <table border = "0" align = "left">
  55. <tr>
  56.     <td>Brand:</td>
  57.     <td><select name = "brand">
  58.         <option>SONY</option>
  59.         <option>SHARP</option>
  60.         <option>LG</option>
  61.         <option>PANASONIC</option>
  62.         <option>SAMSUNG</option>
  63.         <option>JVC</option></select></td>
  64. </tr>
  65.  
  66. <tr>
  67.     <td>Category:</td>
  68.     <td><select name = "categ">
  69.         <option>TV</option>
  70.         <option>AUDIO</option>
  71.         <option>WASHING MACHINE</option>
  72.         <option>REFRIGERATOR</option>
  73.         <option>AIR CONDITIONER</option>
  74.         <option>MICROWAVE OVEN</option></select></td>
  75. </tr>
  76.  
  77. <tr>
  78.     <td>Image Title:</td>
  79.     <td><input name=whatsit></td>
  80. </tr>
  81.  
  82. <tr>
  83.     <input type=hidden name=MAX_FILE_SIZE value=150000>
  84.     <input type=hidden name=completed value=1>
  85.     <td>Upload Image:</td>
  86.     <td><input type=file name=imagefile></td>
  87. </tr>
  88.  
  89. <tr>
  90.     <td>Feature:</td>
  91.     <td><textarea name = "feature"></textarea></td>
  92. </tr>
  93.  
  94. <tr>
  95.     <td></td>
  96.     <td><input type=submit value = "Save"></td>
  97. </tr>
  98.  
  99. </table>
  100. <br>
  101.  
  102. </form><br>
  103.  
  104.  
  105. </body>
  106. </html>
  107.  
Feb 10 '08 #1
Share this Question
Share on Google+
3 Replies


ak1dnar
Expert 100+
P: 1,584
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]
Feb 10 '08 #2

P: 35
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..
Feb 10 '08 #3

Markus
Expert 5K+
P: 6,050
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]
Feb 10 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.