473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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
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
3 1738
ak1dnar
1,584 Expert 1GB
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
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
6,050 Expert 4TB
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

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

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
1
by: Maciej Paras | last post by:
Hello! I've written 2 pages: one i HTML format, and second - in ASP. When I'm posting data from HTML page, I receive this error generated by ASP page: Microsoft JET Database Engine (0x80040E14)...
2
by: Joe | last post by:
Hello All, I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message, System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. ...
1
by: Joe | last post by:
Hello All, I am trying to insert a record in the MS Access DB and for some reason I cannot get rid of error message, System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. ...
10
by: Krakatioison | last post by:
Hi everyone, can someone point me to download of an example for saving and retrieving to/from MYSQL database. Or did anyone of you tried this and could share your code with me. I've got some data...
1
by: Mikey G | last post by:
Hi, I created a simple VB.NET 2003 application through Visual Studio that connects to a MySQL database and loads a table into a Dataset, and then displays that table information in a DataGrid on a...
0
by: Wayne Smith | last post by:
I've taken the following code from a developers web site which should allow a user to register and receive an email message with a link to activate their account, but when I click the link on my...
2
by: jessDMiller | last post by:
I have no clue why the data from the form isn't saving into the database. What am I doing wrong? addAnnounce.php: <td align=top> <form action="index2.php" method="post">Heading:<br...
0
by: kammaldeep | last post by:
hi, i m newbie 2 PHP & to b frank ... will alwaz be ... i dont think i will go into much details with PHP as my work doesnot include workin with PHP bt i have a forum .. and i want to make a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.