473,394 Members | 1,702 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,394 software developers and data experts.

blob insert returns null in query

201 100+
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.   }
  8.  
  9.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  10.  
  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. }
  32.  
  33. $editFormAction = $_SERVER['PHP_SELF'];
  34. if (isset($_SERVER['QUERY_STRING'])) {
  35.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  36. }
  37.  
  38. $IPA = $_SERVER['REMOTE_ADDR'] ;
  39. $DOM ="o1w" ;
  40. //$DT = 'now()' ;
  41.  
  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"));
  49.  
  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"));
  58.  
  59.  
  60.  
  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"));
  69.  
  70.  
  71.   mysql_select_db($database_user, $user);
  72.   $Result0 = mysql_query($insertSQL0, $user) or die(mysql_error());
  73.  
  74.    mysql_select_db($database_user, $user);
  75.   $Result1 = mysql_query($insertSQL1, $user) or die(mysql_error());
  76.  
  77.     mysql_select_db($database_user, $user);
  78.   $Result2 = mysql_query($insertSQL2, $user) or die(mysql_error());
  79.  
  80. }
  81.  
  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>
  94.  
  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. ?>
  136.  
  137.  
Mar 6 '09 #1
2 5007
wizardry
201 100+
i've added a debug print
Expand|Select|Wrap|Line Numbers
  1. $debug=1 ;
  2.  
  3. after sql insert
  4.  
  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
Atli
5,058 Expert 4TB
Hi.

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

7
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...
2
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...
7
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...
15
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'); ...
1
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...
11
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?
0
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...
1
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...
0
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.