SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem inserting text

    Hi, iam currently trying to build a site with dynamic pages. My problem is that when i try and insert a lot of text into my table (field set to text), it does not insert. i can insert small amounts less than 250 words or so. after looking at phpinfo i noticed that max_input_time is set to -1. the default according to the php website should be 30. is this what is causing my problem. Please help i am stuck until this is sorted.

  2. #2
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Welcome to the SitePoint forumns

    When you say 'table' are you talking about a database table? If yes, then how is this table defined? It may be that the field into which you want to insert your data is limited to a set number of characters.

    Post some code so we can see what it is you are doing, and also any error messages that you get.

  3. #3
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a database table set up with 7 fields. with a autoincrementing custom ID field. A few of the fields are set to varchar and the text fields are set to text, although i have tried longtext, blob and long blob with no success. the code is done by dreamweaver as i am new to php. It all works fine except when i insert a lot of text into the text fields. sorry if there is too much code below, iam not sure which bits are important. Thanks for your help
    Code:
    <?php
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    
    $editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
    if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
      $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
    }
    
    if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO support (heading, introduction, text, text2, image, image2) VALUES (%s, %s, %s, %s, %s, %s)",
                           GetSQLValueString($HTTP_POST_VARS['heading'], "text"),
                           GetSQLValueString($HTTP_POST_VARS['introduction'], "text"),
                           GetSQLValueString($HTTP_POST_VARS['text'], "text"),
    					   GetSQLValueString($HTTP_POST_VARS['text2'], "text"),
                           GetSQLValueString($HTTP_POST_VARS['image'], "text"),
                           GetSQLValueString($HTTP_POST_VARS['image2'], "text"));
    
      mysql_select_db($database_registration, $registration);
      $Result1 = mysql_query($insertSQL, $registration) or die(mysql_error());
    
      $insertGoTo = "support.htm";
      if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
    }
    ?>

  4. #4
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *** START RANT ***
    God how I hate the crap code generated by DreamWeaver. You would have thought by now that they would be able to generate more modern PHP code, and better code.
    *** END RANT ***

    You have a field called 'text'. This is a MySQL reserved word. I fpossible, I would change the name of this field. Wherever possible, never use reserved words as field names. If you can;t change it, you need to quote the fieldname using backticks = i.e.`text` - these are not single quotes (') or double quotes (")

    Add a line of code - echo $insertSQL - just before your call mysql_query.

    Do you get any errors when the insert fails?

    $HTTP_POST_VARS should be replaced with $_POST
    $HTTP_SERVER_VARS should be replaces with $_SERVER

  5. #5
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use "text" instead of blob and other try it.
    Arunkumar

  6. #6
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when it works it goes to the next page and when it doesn't work all it does is clear the form. I have tried blob, long blob and longtext to no avail.

  7. #7
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    did you add the 'echo $insertSQL' line. What does that display when it fails?

  8. #8
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    iam not sure whether i was putting it in the correct place as it didn't do anything. iam very new to writing in php. am i correct in putting
    {
    echo $insertSQL;
    }
    or am i completely off track.

  9. #9
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes - but it depends on where you are putting that code

    replace these 2 lines
    PHP Code:
     mysql_select_db($database_registration$registration);
     
    $Result1 mysql_query($insertSQL$registration) or die(mysql_error()); 
    with these 3 lines
    PHP Code:
     mysql_select_db($database_registration$registration);
     echo 
    $insertSQL;
     
    $Result1 mysql_query($insertSQL$registration) or die(mysql_error()); 

  10. #10
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just tried it but it didn't do anything other than what it was doing before. small amount of text ok large amount of text cleared the form.

  11. #11
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume that this is not all the code.
    Can you post all the code including the form bits. There is something strange going on and I'm not sure if it is in this piece of code or somewhere else.

    The other ooption, rather that post all the code, is, right at the top of this code, place this code

    PHP Code:
     <?php
     
    echo '<pre>';
     
    print_r($_POST);
     echo </
    pre>';
     ?>
    and tell me what is says when the insert succeeds and when it fails

  12. #12
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where did you mean as i placed the code right at the top of my script and tried it above the new bit but on both occassions it caused a parse error when i sent it to the testing server. here is the entire thing.

    Code:
    <?php require_once('../Connect/reg.php'); ?>
    <?php
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . $_SERVER['QUERY_STRING'];
    }
    
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO support (heading, introduction, text, text2, image, image2) VALUES (%s, %s, %s, %s, %s, %s)",
                           GetSQLValueString($_POST['heading'], "text"),
                           GetSQLValueString($_POST['introduction'], "text"),
                           GetSQLValueString($_POST['text'], "text"),
    					   GetSQLValueString($_POST['text2'], "text"),
                           GetSQLValueString($_POST['image'], "text"),
                           GetSQLValueString($_POST['image2'], "text"));
      mysql_select_db($database_registration, $registration);
    echo $insertSQL;
    $Result1 = mysql_query($insertSQL, $registration) or die(mysql_error()); 
    
    
      $insertGoTo = "support.htm";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
    }
    ?>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
      <table align="center">
        <tr valign="baseline"> 
          <td nowrap align="right">Heading:</td>
          <td><input type="text" name="heading" value="" size="50"></td>
        </tr>
        <tr valign="baseline"> 
          <td nowrap align="right" valign="top">Introduction:</td>
          <td> <textarea name="introduction" cols="75" rows="4"></textarea> 
          </td>
        </tr>
        <tr valign="baseline"> 
          <td nowrap align="right">Text:</td>
          <td><textarea name="text" cols="75" rows="4"></textarea></td>
        </tr>
        <tr valign="baseline"> 
          <td nowrap align="right">text 2</td>
          <td><textarea name="text2" cols="75" rows="14" id="text2"></textarea></td>
        </tr>
        <tr valign="baseline"> 
          <td nowrap align="right">Image:</td>
          <td><input type="text" name="image" value="" size="32"></td>
        </tr>
        <tr valign="baseline"> 
          <td nowrap align="right">Image2:</td>
          <td><input type="text" name="image2" value="" size="32"></td>
        </tr>
        <tr valign="baseline"> 
          <td nowrap align="right">&nbsp;</td>
          <td><input type="submit" value="Insert Record"></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1">
    </form>
    <p>&nbsp;</p>
      
    </body>
    </html>

  13. #13
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My apologies - I forgot a single quote

    This is what it should be

    PHP Code:
     <?php
     
    echo '<pre>';
     
    print_r($_POST);
     echo 
    '</pre>';
    and place this before the line
    PHP Code:
     <?php require_once('../Connect/reg.php'); ?>

  14. #14
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When it failed it put some of the text onto the screen corresponding to the correct teext box. It was not all of the text that i had put in the form. which presumably means its a problem with the form not my database table ???

  15. #15
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a note to say thanks for your help, as i am going home now and didn't want to appear rude by just not responding anymore. it would be great to work out what is going wrong but please don't put yourself out. cheers. hopefully pick up the thread again tommorrow.

    PS the site iam working on is for a marine charity so iam sure the dolphins will thank you too.

  16. #16
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no problems.
    Yes - it may be a limitatpon of the textarea control. I don't know if there is a limit. How much data are you trying to store?

  17. #17
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Only trying to store a page or two of text from a word document in each row. Ive tried just entering normal letters with no ' ; : / > or anything like that in case that was effecting it, but it didn't input that either.
    It would be used for storing our press releases. at present we have about 100 separate html pages of press releases which is crazy and impossible to manage.

  18. #18
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    Hiding from the world
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Success, Thanks to the last thing you said about a limit on the text box. I realised that perhaps even though it was allowing me to paste the text into the box and looked as though it was allowing it all as it was increaseing the scroll bar at the side of the box, it obviously wasn't. I just changed the amount of text rows to 50 to make sure it was huge and pasted in some text and it worked. In summary iam an idiot who is very greatfull for the help i got here.

  19. #19
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    151 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Noppy
    In summary iam an idiot who is very greatfull for the help i got here.
    Noppy, you are not an idiot, you are learning!
    I challenge anyone in these forums to say that they heven't made some dumbass little mistake that has cost them hours, days or weeks in their coding life!!!

    Glad you got it sorted!

    SpikeZ
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •