Only first word of submitted text gets inserted

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
duhast
Forum Newbie
Posts: 6
Joined: Thu Nov 14, 2002 2:24 pm

Only first word of submitted text gets inserted

Post by duhast »

I am having a problem getting text to insert properly into the db. It inserts but ONLY the first word of what was written.
The text comes from a form that has a text area named "comments".All of the info is passing correctly but it keeps cutting off the rest of the text.
Any ideas anyone?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Could we see the code please.

Mac
duhast
Forum Newbie
Posts: 6
Joined: Thu Nov 14, 2002 2:24 pm

Post by duhast »

Sure! Here it is and I warn you ahead of time... yes I am new to this lol and not sure if I should have posted this here or in the php forum.

Code: Select all

if($attend==no){
mysql_select_db($database_dbi, $dbi);
$query_getstrike = "SELECT * FROM ".$user_prefix."_strike_count WHERE uname='$uname'";
$getstrike = mysql_query($query_getstrike, $dbi) or die(mysql_error());
$row_getstrike = mysql_fetch_assoc($getstrike);
$totalRows_getstrike = mysql_num_rows($getstrike);
$numstrikes=$row_getstrikeї'strikes'];
$memname=$row_getstrikeї'uname'];
if($numstrikes < 3)&#123;
$numstrikes++;
$totalstrikes=$numstrikes;
if (!isset($memname))&#123;
mysql_query(" INSERT INTO ".$prefix ."_attendance ( tid, uname, mday, month, year, attend, comments )
VALUES ( '$tid', '$uname', '$mday', '$month', '$year','$attend', '$comments' )",$dbi) or die ("Couldn't insert info");
 echo "<center>";
 echo "<br><br><br>";
  echo " Failure to attend training for $uname was successfully recorded";
&#125;
if (!isset($memname))&#123;
$numstrikes=1;
mysql_query(" INSERT INTO ".$prefix ."_strike_count ( uname, strikes) VALUES ('$uname','$numstrikes')", $dbi) or die (mysql_error());
echo "<br><br>";
echo "Strike for missed training was recorded for $uname";

&#125;
  elseif (isset($memname)) &#123;
 mysql_query(" UPDATE ".$prefix."_strike_count SET strikes='$totalstrikes' WHERE uname ='$uname'", $dbi) or die (mysql_error());
 echo "<center>";
 echo "<br><br><br>";
echo "Strike count for $uname was updated";

 &#125;
 &#125;
&#125;
  if($attend == excused)&#123;
   mysql_select_db($database_dbi, $dbi);
mysql_query(" INSERT INTO ".$prefix ."_attendance ( tid, uname, mday, month, year, attend, comments) VALUES ( '$tid', '$uname', '$mday', '$month', '$year','$attend', '$comments')", $dbi)
 or die (mysql_error());
  echo "<center>";
  echo "<br><br><br>";
  echo " Excused abscence from training for $uname was successfully recorded";

  &#125;
   if($attend == yes)&#123;
   mysql_select_db($database_dbi, $dbi);
mysql_query(" INSERT INTO ".$prefix ."_attendance ( tid, uname, mday, month, year, attend, comments) VALUES ( '$tid', '$uname', '$mday', '$month', '$year','$attend', '$comments')", $dbi)
 or die (mysql_error());
  echo "<center>";
 echo "<br><br><br>";
  echo " Attendance for $uname was successfully recorded";
&#125;
  &#125;
Once the form is submitted it gets "previewed" before it arrives at this code. All of the text input into the textarea is displayed right. They then click a submit button from there that passes the info to the above code. The only thing that gets inserted into the comments field of the db is the first word. Everything else is cut off.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You say that the information from the text area is passed fine to the preview page so the stuff coming from the form is fine there, how does the information then get passed to this code?

Mac
duhast
Forum Newbie
Posts: 6
Joined: Thu Nov 14, 2002 2:24 pm

Post by duhast »

I have it set up so that the information from the form goes to a preview page and asks if the information is correct then using a hidden form on that page it gets passed to this one. I look into the database and all of the submitted info is in there but if any comments are entered all it puts into the table is the first word.

I have it going into a field called comments set as a type "text".
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

When you put the value into the hidden field you do put quotation marks around it?

Code: Select all

<input type="hidden" name="comments" value="here are the comments" />
If there weren't any quotation marks around the value attribute this might explain why only one word gets passed through to the database.

Mac
duhast
Forum Newbie
Posts: 6
Joined: Thu Nov 14, 2002 2:24 pm

Post by duhast »

Ahhh you were definitely correct!

This is how I was passing from the preview form:

Code: Select all

<input name=comments type=hidden value=$comments>
then I changed it to this:

Code: Select all

<input name=comments type=hidden value="$comments">
And that fixed it. Thank you so much for pointing that out! This was driving me crazy because I knew I had it working before then once I added the preview before insertion it broke.

Thank you! Thank you!
Post Reply