|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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
|
|
#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... |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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.
|
|
#6
|
|||
|
|||
|
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> |
|
#7
|
|||
|
|||
|
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.
|
|
#8
|
||||
|
||||
|
RE: Inserting Long Strings into MSSQL from PHP
possibly there is a character in the text that is escaping the string?
|
|
#9
|
||||
|
||||
|
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. |
|
#10
|
|||
|
|||
|
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:
that is why I originally inquired about the field length. |
|
#11
|
||||
|
||||
|
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 |
|
#12
|
||||
|
||||
|
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.
|
|
#13
|
|||
|
|||
|
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. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > Inserting Long Strings into MSSQL from PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|