Jump to content

SELECT query is not pulling full value from table


yammez

Recommended Posts

I'm banging my head against the wall on this one. I have an MSSQL database which stores information from an online form. I also have a PHP script that pulls information from this database, one record at a time, to display on a .php page.

 

Four of the columns, that are set to VARCHAR(2000), contain values that are about 1000 characters long. These values come from a <textarea> field on a separate form. When I view the table in SQL Server Management Studio Express, I can see the full 1000 character values. Because of this, I know the insert query is working properly.

 

The problem comes when I try to echo these values in the PHP script, it only echoes 250 characters. What would prevent this from echoing the full 1000 characters?

 

Some things that I've tried, none of which work:

- I've tried to echo the value with the nl2br() function.

- I've tried print instead of echo. (if there is even a difference anymore)

- I've tried making a separate query string and result set that only fetches one of the 1000-character values, and echoing that.

- I've checked my code on the W3C validator; it IS valid.

- I've tried different settings for the <textarea>'s "wrap" attribute.

- I've changed the html tags around the echoed value to <p>, <pre>, <span> etc.

- I've made sure the CSS is not affecting these tags by not linking it.

 

Here's a sample of my code:

The textarea:
<textarea name="question22" rows="4" cols="50" wrap="hard"></textarea>

The query:
$query = "SELECT * FROM dbo.academic_success_assessments WHERE assessment_id = '$assessment_id'";
$result = mssql_query($query);
$row = mssql_fetch_array($result,MSSQL_ASSOC);

The display:
echo "<p>".$row['question20'].</p>";

Link to comment
Share on other sites

Have you done a "view source" of the page in your browser to see if all the content is actually present?

 

All content that could contain any HTML special characters (<, >, ', ") must be passed through the htmlentities function to insure that any HTML special characters in it don't break the HTML on your page.

Link to comment
Share on other sites

Ah, my mistake, I'll edit my first post to reflect this. When the value from the form is inserting into the database, I do run it through the htmlentities() function. Also, I have looked at the source, at it only displays the first 250 characters there too.

 

Edit: I just realized I cannot edit my initial post :(

 

I should also note that there are also only alpha characters (no apostrophes, commas, even periods) in the text that I'm entering. I'm just entering something along the lines of:

sdjfh ashflkjasdhfkasj hdfkasl ksajdfh akshf khsafl hsaldkjfh sldkjfh aslkj
sakdj fhkjlashf kjhf lkjsdhafk jsdhfk jlhsdk jhaslk fjhsladkj fhksj fhkja
skdjfhka jhksjad hkj hkjsfh kjshakflsjd hdklsja fhkljshf kjshadk fjhskl f

Link to comment
Share on other sites

are you using the mssql.dll for your connections?

 

There was a bug with select statements that limited return to 256 characters with that .dll - What setup do you have? If windows try using the sqlsrv.dll instead. It's got a different API which is a pain, but it apparently resolves a lot of flaws that the mssql.dll has.

 

http://www.microsoft.com/downloads/details.aspx?FamilyID=ccdf728b-1ea0-48a8-a84a-5052214caad9&displaylang=en

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.