Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    494

    Unanswered: not inserting in field properly

    I suspect that this is a database issue and not a php programming issue. I have a url string which I want to insert in the db separated by commas:
    PHP Code:
    mysql_select_db($dbname$con);

    $sql "INSERT INTO ".$dbtable." ( ";
    for(
    $i=0$i<count($COLORS); $i++){
        
    $sql .= "txtarea".$i.",";
    }
    $sql .= "id0,
    book0,
    bookTitle0,
    chapter0,
    verse0,
    id1,
    book1,
    bookTitle1, 
    chapter1,
    verse1,
    comments
    ) VALUES ( "
    ;
    for(
    $i=0$i<count($COLORS); $i++){
        
    $sql .= "'".$_GET["keyword".$i]."', ";
    }
    $sql .= "'".$_GET['bibleid0']."',
    '"
    .$_GET['book0']."',
    '"
    .$_GET['btitle0']."',
    '"
    .$_GET['chapter0']."',
    '"
    .$_GET['verse0']."',
    '"
    .$_GET['bibleid1']."',
    '"
    .$_GET['book1']."',
    '"
    .$_GET['btitle1']."',
    '"
    .$_GET['chapter1']."',
    '"
    .$_GET['verse1']."',    
    '"
    .str_replace("'""\'"$_GET['comments'])."'
    )"

    within one field I want to enter a set of numbers separated by a comma or a plus sign or something else. And the result I get is an empty spot after the comma. When I type print_r to see if the array is passed on from the url everything is there. But it's not inserted properly.

    As an example if the array has (1, 2, 3, 4, 5) it would insert maybe the first 3 results 1, 2, 3, and that's it.

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Why not make it easier for us (and perhaps yourself) by printing out what the string $sql contains just before your try to run it through the database. It would also help if you gave us the create table statement for $dbtable.

    Have you tried printing out the COLOR array with print_r($COLOR); just to check it contains all the values you think it contains? Can I ask why $dbtable is a variable and not an actual table name? Why are some of the fields (the colours) taken from an array and others specified by hand? Why do you have colours in a table concerning bible text? Using parameters directly like $_GET['bibleid0'] is dangerous as someone could enter a string into your form containing 'x' ); delete from YourTableName; and then that would be the end of your table.

  3. #3
    Join Date
    Mar 2004
    Posts
    480
    Quote Originally Posted by gilgalbiblewhee View Post
    I suspect that this is a database issue and not a php programming issue.
    Then have you tried entering the string manually into the database? If it will enter that way fine then you'll know if it is a database issue (such as insufficient field type or length) rather than a php issue.

    [/quote]

    Quote Originally Posted by gilgalbiblewhee View Post
    As an example if the array has (1, 2, 3, 4, 5)
    if you plan on searching this field for individual numbers, then you should be normalizing your data instead.

  4. #4
    Join Date
    Jul 2004
    Posts
    494
    I realized that the var chars were wrong.

Posting Permissions

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