473,574 Members | 3,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

blob insert returns null in query

201 New Member
hello -

i'm trying to insert a blob into my table, it will insert but the string that i insert when i query the inserted data returns null with 0 bytes in the column.

I have other tables set up this way and i'm able to insert text data into it with no problems. I've checked the database design its basiclly a duplicate. I did have to remove my not null on the long blob element.

but other then that, i don't understand why this is capturing a null value.

Thanks, in advance for your help.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (!function_exists("GetSQLValueString")) {
  3. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  4. {
  5.   if (PHP_VERSION < 6) {
  6.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  7.   }
  9.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.   switch ($theType) {
  12.     case "text":
  13.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  14.       break;    
  15.     case "long":
  16.     case "int":
  17.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  18.       break;
  19.     case "double":
  20.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  21.       break;
  22.     case "date":
  23.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  24.       break;
  25.     case "defined":
  26.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  27.       break;
  28.   }
  29.   return $theValue;
  30. }
  31. }
  33. $editFormAction = $_SERVER['PHP_SELF'];
  34. if (isset($_SERVER['QUERY_STRING'])) {
  35.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  36. }
  38. $IPA = $_SERVER['REMOTE_ADDR'] ;
  39. $DOM ="o1w" ;
  40. //$DT = 'now()' ;
  42. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  43.   $insertSQL0 = sprintf("INSERT INTO domain (Id, doms_Id, Dt, Domain, IpAddress) VALUES (%s, %s, now(), '$DOM', '$IPA')",
  44.                        GetSQLValueString($_POST['Id'], "int"),
  45.                        GetSQLValueString($_POST['doms_Id'], "int"),
  46.                        GetSQLValueString($_POST['Dt'], "date"),
  47.                        GetSQLValueString($_POST['Domain'], "text"),
  48.                        GetSQLValueString($_POST['IpAddress'], "text"));
  50. // eula schema
  51. $insertSQL1 = sprintf("insert into eos (Id_fk, Id, Eula, Dt, Domain, IpAddress) values (last_insert_id(), last_insert_id(), AES_ENCRYPT(%s, '$userpass'), now(), '$DOM', '$IPA')",
  52.                       GetSQLValueString($_POST['Id_fk'], "int"),
  53.                       GetSQLValueString($_POST['Id'], "int"),
  54.                       GetSQLValueString($_POST['Eula'], "text"),
  55.                       GetSQLValueString($_POST['Dt'], "date"),
  56.                       GetSQLValueString($_POST['Domain'], "text"),
  57.                       GetSQLValueString($_POST['IpAddress'], "text"));
  61. //tos schema
  62. $insertSQL2 = sprintf("insert into tos (Id_fk, Id, TOS, Dt, Domain, IpAddress) values (last_insert_id(), last_insert_id(), AES_ENCRYPT(%s, '$userpass'), now(), '$DOM', '$IPA')",
  63.                       GetSQLValueString($_POST['Id_fk'], "int"),
  64.                       GetSQLValueString($_POST['Id'], "int"),
  65.                       GetSQLValueString($_POST['TOS'], "text"),
  66.                       GetSQLValueString($_POST['Dt'], "date"),
  67.                       GetSQLValueString($_POST['Domain'], "text"),
  68.                       GetSQLValueString($_POST['IpAddress'], "text"));
  71.   mysql_select_db($database_user, $user);
  72.   $Result0 = mysql_query($insertSQL0, $user) or die(mysql_error());
  74.    mysql_select_db($database_user, $user);
  75.   $Result1 = mysql_query($insertSQL1, $user) or die(mysql_error());
  77.     mysql_select_db($database_user, $user);
  78.   $Result2 = mysql_query($insertSQL2, $user) or die(mysql_error());
  80. }
  82. mysql_select_db($database_user, $user);
  83. $query_Recordset1 = "SELECT * FROM user";
  84. $Recordset1 = mysql_query($query_Recordset1, $user) or die(mysql_error());
  85. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  86. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  87. ?>
  88. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  89. <html xmlns="http://www.w3.org/1999/xhtml">
  90. <head>
  91. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  92. <title>Untitled Document</title>
  93. </head>
  95. <body>
  96. <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  97.   <table align="center">
  98.     <tr valign="baseline">
  99.       <td nowrap="nowrap" align="right">Id:</td>
  100.       <td><select name="doms_Id">
  101.         <?php 
  102. do {  
  103. ?>
  104.         <option value="<?php echo $row_Recordset1['doms_Id']?>" ><?php echo $row_Recordset1['Domain_Name']?></option>
  105.         <?php
  106. } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  107. ?>
  108.       </select></td>
  109.     </tr>
  110.     <tr> </tr>
  111.     <tr valign="baseline">
  112.           <td height="23" align="right" nowrap="nowrap">EULA:</td>
  113.           <td><input type="text" name="Eula" value="" size="32" /></td>
  114.         </tr>
  115.         <tr valign="baseline">
  116.           <td height="45" align="right" nowrap="nowrap">TOS:</td>
  117.           <td><input type="text" name="TOS" value="" size="32" /></td>
  118.         </tr>
  119.     <tr valign="baseline">
  120.       <td nowrap="nowrap" align="right">&nbsp;</td>
  121.       <td><input type="submit" value="Insert record" /></td>
  122.     </tr>
  123.   </table>
  124.   <input type="hidden" name="Id" value="" />
  125.   <input type="hidden" name="Dt" value="" />
  126.   <input type="hidden" name="Domain" value="" />
  127.   <input type="hidden" name="IpAddress" value="" />
  128.   <input type="hidden" name="MM_insert" value="form1" />
  129. </form>
  130. <p>&nbsp;</p>
  131. </body>
  132. </html>
  133. <?php
  134. mysql_free_result($Recordset1);
  135. ?>
Mar 6 '09 #1
2 5025
201 New Member
i've added a debug print
Expand|Select|Wrap|Line Numbers
  1. $debug=1 ;
  3. after sql insert
  5. if ($debug=1)
  6. {
  7. print sqlinsert;
  8. }
i see that the variables are not being captured.

What could cause this?
Mar 6 '09 #2
5,058 Recognized Expert Expert

The sprintf functions on lines #42, #51, and #62 look a bit odd.
Seems like there are to many parameters, and you add values directly into the string, rather than put them as parameters.

Other that that, I couldn't really locate the problem in all that code.
(PHP and HTML all mixed together is always hard to read, especially if you don't know the thinking behind it.)
Could you perhaps point to the specific part that is causing the problem?

And also, could you post the structure of the table that is causing the problem?
Apr 8 '09 #3

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

Similar topics

by: John | last post by:
I have over 5000 thumbnail pictures of size 5kb each. I would like to able to load all 5000 pictures and view 50 per page using mysql_data_seek(). I would like to know what are the advantages and disadvantages of using a MySQL blob field rather than reading the images directly from the file? How does one insert an image into a blob field?...
by: Tony | last post by:
Hi, I have dynamically created a PDF document in memory as a FileOutputStream Now I have to get it into a DB2 table, storing it as a BLOB. The table has a document id, document name, some date fields and this BLOB column that stores PDF Files. Until now, the PDF files were read off of a disk drive. The code used was: byte fileAsBytes =...
by: sime | last post by:
Hi, I have a blob field in a mysql database table. I want to copy a blob from one record to another. I am having trouble transferring the data via a php variable. Maybe I need to addslashes or convert to Hex or something. I've tried a few things but can't quite get it. Here is simplified code. mysql_select_db($dbname, $connection);
by: Daniel Schuchardt | last post by:
Hi @ all, i'm sure there was a psql-function to transfere my Blob-Data to the server but I can't remember. I have a script like this : UPDATE xy SET z = lo_import('localpath_and_file'); but i want to execute this script from the client and so my blob-data is
by: sid_mulpuru | last post by:
I am trying to read data from a DB2 Blob Data type Field (using wsad 5.1.0) using getBlob() which when executed gives an SQL Exception 2005-01-07 15:48:40,506 ERROR - Error in servlet:xxxxx.jsp initiateDownloadFri Jan 07 15:48:39 CST 2005com.ibm.db2.jcc.a.SqlException: 1 (in debug mode exception called at rs =
by: Chris Fink | last post by:
I have setup an Oracle table which contains a blob field. How do I insert data into this field using C# and ADO.net?
by: Wescotte | last post by:
I'm abit confused on how to work with binary data with an ODBC connection (My database is DB2 btw) Say I have a table like CREATE TABLE EJWLIB.BLOBTEST ( ID NUMERIC(5) NOT NULL, FILENAME VARCHAR(128) NOT NULL, BINARY BLOB(2M) ) Now I (I assume this is the correct method) insert data in the
by: cricrin | last post by:
Hello guys! This is Cristian From Argentina, and I wanted to ask you some help, I've looking on this and it makes me mad, I found that the error is in the $content , when y try to insert the record into the table via PHP code i receive an error message saying that the sin taxis its incorrect,however if i print the query echo ($query) and i...
by: dimitri pater | last post by:
Hi, I am trying to insert an image, which is stored as a blob in MySQL, into a table using Reportlab. I have tried this: from StringIO import StringIO cfoto = StringIO(result) # where result is the 'blob' cfoto.seek(0) foto=cfoto.getvalue
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...
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...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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...
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...
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...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.