469,603 Members | 2,076 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,603 developers. It's quick & easy.

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 4730
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

Post your reply

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

Similar topics

7 posts views Thread by John | last post: by
7 posts views Thread by sime | last post: by
15 posts views Thread by Daniel Schuchardt | last post: by
1 post views Thread by sid_mulpuru | last post: by
11 posts views Thread by Chris Fink | last post: by
reply views Thread by Wescotte | last post: by
1 post views Thread by cricrin | last post: by
reply views Thread by dimitri pater | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.