Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 19th, 2003, 11:17 PM
Symbeon Symbeon is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 18 Symbeon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Inserting Long Strings into MSSQL from PHP

I have a piece of code that is setup for the user to update the body of a form e-mail that will get sent out whenever they access the system. The variable I am using is a textarea

<textarea rows="5" cols="50" name="body"></textarea>

When I submit my php page and try to do the insert, it truncates the body on insert. I printed out the sql and it looks ok:

insert into email (active, body) values ( 1, 'some string 500 characters long')

mssql is truncating the insert at about character 250-255.

My environment is php on apache running on a Red Hat 8.x server. It is attaching to a MS SQL Server 2000 db server running Windows 2000.

Thanks for the help.


Reply With Quote
  #2  
Old August 20th, 2003, 12:41 AM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Inserting Long Strings into MSSQL from PHP

what data type is the field you are inserting the string into and what is its length. The length of the field you are inserting into is probably only 255 characters

Reply With Quote
  #3  
Old August 20th, 2003, 01:14 AM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Inserting Long Strings into MSSQL from PHP

you are probably using varchar(250).

use (medium)blob or (medium)text field types..

look them up in mysql manual...

Reply With Quote
  #4  
Old August 20th, 2003, 02:26 AM
Symbeon Symbeon is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 18 Symbeon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Inserting Long Strings into MSSQL from PHP

I forgot to put that in my post. The field that I am inserting into is a varchar(2000).

Also, I was able to insert this data fine with dbqwikedit pro, if that makes any difference.

Reply With Quote
  #5  
Old August 20th, 2003, 11:17 AM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Inserting Long Strings into MSSQL from PHP

Post the code of the form and the code for the DB processing so we can take a look.

Reply With Quote
  #6  
Old August 20th, 2003, 01:58 PM
Symbeon Symbeon is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 18 Symbeon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Inserting Long Strings into MSSQL from PHP

Here's the code that I am using, minus the includes for mysql connect, etc.

<form method="POST" action="update_email.php" name="form1">

<table>
<?

if($saveChanges == 1) {
mssql_query("update email set active = 0");

$sql = "insert into email ( active, body ) values ( 1, '$body' )";

$result = mssql_query($sql)
or die ("There was an error updating the e-mail form. Please contact customer support.<br><br>There is currently no active e-mail to send out.");
?>
<tr>
<th>The e-mail has been updated</th>
</tr>
<tr><td height="20" style="text-align: center; vertical-align: middle"><hr></td></tr>

<? } ?>

<tr>
<td nowrap><b>Update E-Mail:</b></td>
</tr>

<?
$sql = "select body from email where active = 1";
$result = mssql_query($sql);

if (mssql_num_rows($result) > 0) {
$row = mssql_fetch_array($result);
$currEmail = $row["body"];
} else {
$currEmail = "";
}
?>

<tr><td height="15"/></tr>

<tr>
<td>
<textarea rows="20" cols="50" name="body"><?= $currEmail ?></textarea>
</td>
</tr>

<tr>
<td nowrap height="20" colspan="6"></td>
</tr>
<tr>
<td nowrap colspan="6" height="20" style="text-align: center;">
<input type="hidden" name="saveChanges" value="1">
<input type="submit" value="Submit">
</td>
<tr>
<td nowrap colspan="4" height="13"></td>
</table>
</form>

Reply With Quote
  #7  
Old August 20th, 2003, 03:08 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Inserting Long Strings into MSSQL from PHP

I don't see anything wrong with the code, can't imagine why it is not working.

Reply With Quote
  #8  
Old August 21st, 2003, 01:02 PM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,253 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 4
Send a message via Yahoo to bakertrg
RE: Inserting Long Strings into MSSQL from PHP

possibly there is a character in the text that is escaping the string?

Reply With Quote
  #9  
Old August 21st, 2003, 01:09 PM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,253 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 4
Send a message via Yahoo to bakertrg
RE: Inserting Long Strings into MSSQL from PHP

I can't believe I missed this: there's no such thing as varchar(2000) it has a maximum size of 255.

use text or blob they are 64k characters in size (it's the next smallest available size)

varchar = tinytext = 2^8-1 = 255
text = blob = 2^16-1 = 64k
mediumtext = mediumblob = 2^24-1 = 16.5M+
longtext = longblob = 2^32-1 = some really big number I forget what it is

the only difference between text and blob is how you can search/index them I think.

Reply With Quote
  #10  
Old August 21st, 2003, 01:27 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: Inserting Long Strings into MSSQL from PHP

MSSQL Varchar data types can be from 1 to 8000 characters long.

here is a quote from the manual.

Quote:
varchar[(n)]

Variable-length non-Unicode character data with length of n bytes. n must be a value from 1 through 8,000. Storage size is the actual length in bytes of the data entered, not n bytes. The data entered can be 0 characters in length. The SQL-92 synonyms for varchar are char varying or character varying.



that is why I originally inquired about the field length.

Reply With Quote
  #11  
Old August 21st, 2003, 02:34 PM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,253 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 4
Send a message via Yahoo to bakertrg
RE: Inserting Long Strings into MSSQL from PHP

I'm not sure where you got that from, but here are two links in the manual that say different:

http://www.mysql.com/doc/en/CHAR.html

http://www.mysql.com/doc/en/Storage_requirements.html

Reply With Quote
  #12  
Old August 21st, 2003, 02:47 PM
bakertrg's Avatar
bakertrg bakertrg is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Scottsdale AZ, US
Posts: 2,253 bakertrg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 48 m 45 sec
Reputation Power: 4
Send a message via Yahoo to bakertrg
RE: Inserting Long Strings into MSSQL from PHP

sorry eddie, if only I was using the correct database... ;) I just assume MySQL in here and didn't look hard enough. Looks like zombie made the same error.

Reply With Quote
  #13  
Old August 21st, 2003, 05:06 PM
Symbeon Symbeon is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 18 Symbeon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Inserting Long Strings into MSSQL from PHP

Thanks for the responses, all. I was able to get this to work by using

$sql = "insert into email ( active, body ) values ( 1, convert(text, '$body') )";


I don't know why this worked and the straight insert did not. It looks like it should have.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Inserting Long Strings into MSSQL from PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |