473,748 Members | 8,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error with saving Form data to MySQL

35 New Member
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 1752
ak1dnar
1,584 Recognized Expert Top Contributor
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
mirianCalin
35 New Member
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 Recognized Expert Expert
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
5038
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 double-checked the path to my error log. It is in /var/www/logs/php_error_log Thanks. :) -Wayne Stevenson
1
11128
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) Syntax error (missing operator) in query expression '' AND (='OFFICE DEPOT')''. "Office Depot" is the value from form. When all values are set to "*" the script generates correct results, but if its value contains any string it generates the...
2
2852
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. And the line it shows in red is cmd.ExecuteNonQuery()
1
5422
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. And the line it shows in red is cmd.ExecuteNonQuery()
10
1698
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 which needs to be put to mysql database using VB.NET and I can't figure this out. Thanks a lot. K.
1
8840
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 form for editing. The table fill works fine, the delete function works fine, but when I try to update a row, the application fails with the following error message: An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in...
0
1623
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 home page to take me to the 'registration.aspx' page, it throws up the following error message and I can't figure out why. ------------------------------------------------------------------------------ Server Error in '/' Application. ...
2
2226
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 /><textarea name="heading" cols="50" rows="10"></textarea><br /><br />Announcement:<br /> <textarea name="announce" cols="50" rows="10"></textarea> <br /><br />Date:<br /><textarea name="date" cols="50" rows="10"></textarea><br /><br /><input...
0
1915
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 personal contact page in it .... and save all details in my new database.... i have website in the root folder i get dis error
0
8989
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9537
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8241
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6795
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.