If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > not inserting in field properly

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-09-10, 00:43
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
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.
Reply With Quote
  #2 (permalink)  
Old 02-09-10, 05:24
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
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.
Reply With Quote
  #3 (permalink)  
Old 02-10-10, 11:05
guelphdad guelphdad is online now
Registered User
 
Join Date: Mar 2004
Posts: 435
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.
Reply With Quote
  #4 (permalink)  
Old 02-13-10, 22:43
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 494
I realized that the var chars were wrong.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On