Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strings are truncated for no reason

Status
Not open for further replies.

majorbroncosfan

Programmer
Feb 23, 2001
121
0
0
US
I have been trying to get a string to parse on a form, but can only get a truncated version of that string (if anything). For example, say I typed in a comments field and used carriage returns, etc. The database field this will be going into has a length of 255. When I pass this value through to a form, it gets truncated down to 99. I have tried using several different string functions, but nothing works.

Does anybody understand why this might be? I was under the impression that PHP could hold a very large string limited only by memory.

Thanks in advance!
 
Sample of code, please?

Can't tell you want you might be doing incorrectly without seeing what you're currently doing.

Ken
 
I'll give just a real simple example:

$issue = $HTTP_POST_VARS['txtIssue'];

echo $HTTP_POST_VARS['txtIssue'];
 
I am not sure if I follow. Do you have a form that is asking for this info and that form puts the info into the database? If so make sure you have the form size set correct. It may be the cause. Are you using POST to send this info or are you using get. I am not sure but I think get has some limitations. As Ken said it is hard without looking at the actual code (form, etc.).

- Zych
 
What kind of form field is "txtIssue"? Is it a textarea object?

Does your output change if your script reads:
Code:
<?php
print '<pre>';
print $HTTP_POST_VARS['txtIssue'];
print '<pre>';
?>

As an aside, if your version of PHP supports it, I strongly recommend that instead of $HTTP_POST_VARS you use $_POST.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
It is a textarea object. There is a form requesting this information and it is posted to be inserted into a mysql database.
 
Well, here's the interesting thing...

When I was working from home to do this, I could add any string length with no problem. The only limitation was the 255 variable string length restriction I placed on the database table.

Come to work, it's a different story.
 
Insufficient data for a meaningful comment.

Are you hitting the same server from both work and home?
Are you using the same browser?
What version(s) of PHP running on what OS(es) are we discussing here?


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
One question, majorbroncosfan:

The strings are truncated BEFORE database inserting, or they are truncated AFTER when you retrive the strings from DB. and the print in HTML page ?

If there is 2nd case you should take a look in database, the column definition.

If you want some help you should post here THE EXACT CODE that are you using:

- the form with textarea
- the php script which do the print in the HTML page.


PM


___
____
 
Well, here's something interesting. The string parses just fine if I am doing it through our company VPN remotely, but not internally.

Is there an explanation for this?
 
I am running PHP 4.3.11 on Apache 1.3.x via Windows 2000. I am using Internet Explorer 6 on Windows 2000/XP.
 
Are you using the same code in both cases ?
Is the same server?

PLs provide the HTML FORM which has textarea and the php script which prints the posted strings.

PM


___
____
 
<form name="frmLog" method="post" action="call_log_update.php">
<table class='Table' width="710" height="250">
<tr>
<td width="615" height="15" class="ColumnHead"> <div align="left">
<input class="SubmitButton" type="submit" name="cmdSave"
value="Save" onClick="javascript:parent.topFrame.location.href='call_log_list.php';">
<input class="SubmitButton" type="button" name="cmdCancel"
value="Cancel" onClick="redirect('call_log_edit.php?action=insert');">
</div></td>
<td width="83" class="ColumnHead">
<? if(!$action == "insert" && <code omitted for security reasons>)
{
?>
<input class="SubmitButton" type="button" name="cmdTicket" value="Open Ticket"
onClick="javascript:alert('Not yet available');">
<?
} elseif ($action == "update" && <code omitted for security reasons>) {
?>
<input class="SubmitButton" type="button" name="cmdTicket" value="Open Ticket"
onClick="javascript: if (document.forms[0].cboRequester.value != '')
{ redirect('ticket_edit.php?action=insert&id=<? echo $callID ;?>&location=call')}
else { alert ('You need to have an open call to place a ticket') };">

<?
}
?>
</td>

</tr>
<tr align="left" valign="top">
<td height="75" colspan="4" class="ColumnBody"> <div align="left">Log Information</div>
<div align="left"> </div>
<table width="700" height="72" border="0" align="left" cellpadding="0" cellspacing="0">
<?
if ($action == "insert")
{
?>
<tr valign="middle">
<td height="24" class="FormTitle">Hospital&nbsp;</td>
<td> <select name="cboHospital" class="SelectGreen" id="cboHospital"
onChange="filterHosp('call_log_edit.php?action=insert','hosp')">
<?
# get all of the available hospitals no matter what
$query = "SELECT hospital_id, hospital_name FROM hospital ";
$query .= "ORDER BY hospital_name";

# if a department exists, get the hospital for that department
if(!$dept == "")
{
$hospQuery = "SELECT hospital_id FROM hospital_department ";
$hospQuery .= "WHERE department_id=".$dept;


$hospResult = mysql_db_query($database, $hospQuery, $link)
or die("Could not complete database query");

$hospRow = mysql_fetch_array($hospResult);
}
?>
<option></option>
<option>View All Departments</option>
<?
$result = @mysql_db_query($database, $query, $link)
or die("Could not complete database query");

while (($row = mysql_fetch_array($result)))
{
if(trim($hosp) == trim($row["hospital_id"]))
{
?>
<option value=<? echo $row["hospital_id"]; ?> selected> <? echo $row["hospital_name"]; ?>
</option>
<?
} else {
?>
<option value=<? echo $row["hospital_id"]; ?>> <? echo $row["hospital_name"]; ?>
</option>
<?
}
}
?>
</select></td>
<td class="FormTitle">Department&nbsp;</td>
<td> <select name="cboDepartment" class="SelectGreen" id="cboDepartment"
onChange="filterHosp('call_log_edit.php?action=insert','dept')">
<?

if (!$dept == "")
{
# get the selected department
# $deptQuery = "SELECT department_id, department_name, department_code ";
# $deptQuery .= "FROM department WHERE department_id = ".$dept;
# $deptResult = @mysql_db_query($database, $deptQuery, $link)
# or die("Could not complete database query");
# $deptRow = mysql_fetch_array($deptResult);

if(!$hosp == "")
{
$query = "SELECT d.department_code, d.department_name, ";
$query .= "hd.hospital_id, hd.department_id ";
$query .= "FROM department d INNER JOIN hospital_department ";
$query .= "hd ON d.department_id = hd.department_id WHERE hd.hospital_id=".$hosp;
} else {
# $query = "SELECT * FROM department WHERE ";
# $query .= "department_hospital = ".$hosp." ORDER BY department_code";
$query = "SELECT d.department_code, d.department_name, ";
$query .= "hd.hospital_id, hd.department_id ";
$query .= "FROM department d INNER JOIN hospital_department ";
$query .= "hd ON d.department_id = hd.department_id WHERE hd.department_id=".$dept;
}

} elseif($dept == "") {
if (!$hosp == "")
{
$query = "SELECT d.department_code, d.department_name, ";
$query .= "hd.hospital_id, hd.department_id ";
$query .= "FROM department d INNER JOIN hospital_department ";
$query .= "hd ON d.department_id = hd.department_id ";
$query .= "WHERE hd.hospital_id = ".$hosp;
} else {
$query = "SELECT * FROM department ORDER BY department_code";
}

} elseif ($dept == "") {
$query = "SELECT * FROM department ORDER BY department_code";
}
$result = @mysql_db_query($database, $query, $link)
or die("Could not complete database query");
?>
<option></option>
<option>View All Contacts</option>
<?
while (($row = mysql_fetch_array($result)))
{
?>
<option value=<? echo $row["department_id"]; ?>> <? echo $row["department_code"]." - ".$row["department_name"]; ?>
</option>
<?
}
?>
</select></td>
</tr>
<?
}
?>
<tr valign="middle">
<td width="100" height="24" class="FormTitle"> <div align="right">Requester&nbsp;</div></td>
<td width="300"> <select name="cboRequester" class="SelectGreen" id="select">
<?
if (!$callID == "")
{
?>
<option></option>
<option value=<? echo $singleRow["lc_contact"];?> selected> <? echo $singleRow["contact_last"].", ".$singleRow["contact_first"];?>
</option>
<?
$query = "SELECT * FROM contact WHERE contact_id ";
$query .= "!= ".$singleRow["lc_contact"]." ORDER BY contact_last";
} else {
?>
<option></option>
<?
# both a hospital and department are selected
if (!$hosp == "" && !$dept == "")
{
$query = "SELECT c.contact_id, c.contact_first, ";
$query .= "c.contact_last, dc.department_id, hd.hospital_id ";
$query .= "FROM ((contact AS c INNER JOIN department_contact ";
$query .= "AS dc ON c.contact_id = dc.contact_id) INNER JOIN ";
$query .= "department AS d ON dc.department_id = d.department_id) ";
$query .= "INNER JOIN hospital_department AS hd ON ";
$query .= "d.department_id = hd.department_id WHERE dc.department_id=".$dept;

# a department is selected, but not a hospital
} elseif ($hosp == "" && !$dept == "") {
$query = "SELECT c.contact_id, c.contact_first, ";
$query .= "c.contact_last, dc.department_id, hd.hospital_id ";
$query .= "FROM ((contact AS c INNER JOIN department_contact ";
$query .= "AS dc ON c.contact_id = dc.contact_id) INNER JOIN ";
$query .= "department AS d ON dc.department_id = d.department_id) ";
$query .= "INNER JOIN hospital_department AS hd ON ";
$query .= "d.department_id = hd.department_id WHERE dc.department_id=".$dept;

# a hospital is selected, but not a department
} elseif (!$hosp == "" && $dept == "") {
$query = "SELECT c.contact_id, c.contact_first, ";
$query .= "c.contact_last, dc.department_id, hd.hospital_id ";
$query .= "FROM ((contact AS c INNER JOIN department_contact ";
$query .= "AS dc ON c.contact_id = dc.contact_id) INNER JOIN ";
$query .= "department AS d ON dc.department_id = d.department_id) ";
$query .= "INNER JOIN hospital_department AS hd ON ";
$query .= "d.department_id = hd.department_id WHERE hd.hospital_id=".$hosp;

# new entry
} else {
$query = "SELECT * FROM contact ORDER BY contact_last";
}
}
$result = @mysql_db_query($database, $query, $link)
or die("Could not complete database query");
while (($row = mysql_fetch_array($result)))
{
?>
<option value=<? echo $row["contact_id"]; ?>> <? echo $row["contact_last"].", ".$row["contact_first"]; ?>
</option>
<?
}
?>
</select> <input name="cmdRequester" type="button" class="LinkButton"
id="cmdRequester" value="..."
onClick="redirect('../contact/contact_edit.php?option=inline&action=update&contactID=<? echo $singleRow["lc_contact"]; ?>');">
</td>
<td width="100" class="FormTitle">Taken By&nbsp;</td>
<td width="200"> <select name="cboTakenBy" class="SelectGreen" id="select3">
<?
if (!$callID == "")
{
?>
<option></option>
<option value=<? echo $singleRow["taken_by"];?> selected> <? echo $singleRow["emp_first"].' '.$singleRow["emp_last"];?>
</option>
<?
$query = "SELECT * FROM sys_employee WHERE ";
$query .= "emp_id != ".$singleRow["taken_by"]." ORDER BY emp_last";
} else {
?>
<option></option>
<?
$query = "SELECT * FROM sys_employee ORDER BY emp_last";
}
$result = @mysql_db_query($database, $query, $link)
or die("Could not complete database query");
while (($row = mysql_fetch_array($result)))
{
?>
<option value=<? echo $row["emp_id"]; ?>> <? echo $row["emp_first"]." ".$row["emp_last"] ;?>
</option>
<?
}
?>
</select>
<input name="cmdAssignedTo2" type="button" class="LinkButton"
id="cmdAssignedTo2" value="..."
onclick="redirect('../systems/system_edit.php');"> </td>
</tr>
<?
if (!$callID == "" && (!$singleRow["department_name"] == ""
|| !$singleRow["extension"] == ""))
{
?>
<tr valign="middle">
<td width="100" height="24" class="FormTitle"> <div align="right">
<?
if (!$callID == "" && !$singleRow["department_name"] == "")
{
echo "Department&nbsp;";
}
?>
</div></td>
<td width="300">
<?
if (!$callID == "" && !$singleRow["department_name"] == "")
# the contact belongs to a department
# we are making this field read-only and
# it can be modified through the contact form
{
?>
<input name="txtDepartment" type="text" class="TextBoxGreen"
value="<? echo $singleRow["department_name"]; ?>"
size="40" maxlength="50" readonly="true">
<?
} else {
# the contact has no department
# don't put anything here
}
?>
</td>
<td width="100" class="FormTitle">Assigned To&nbsp;</td>
<td width="200"><select name="cboAssigned" class="SelectGreen" id="select4">
<?
$assignQuery = "SELECT cla.call_id, cla.emp_id, cla.date_entered, se.emp_first, se.emp_last ";
$assignQuery .= "FROM call_log_assignment cla INNER JOIN sys_employee se ON cla.emp_id = se.emp_id ";
$assignQuery .= "WHERE cla.call_id=".$callID;

$assignResult = mysql_db_query($database,$assignQuery,$link);

$assignRow = mysql_fetch_array($assignResult);

if (!$callID == "")
{
?>

<option value=<? echo $assignRow["call_id"];?> selected> <? echo $assignRow["emp_first"].' '.$assignRow["emp_last"];?>
</option>
<?
$query = "SELECT * FROM sys_employee WHERE ";
$query .= "emp_id != ".$singleRow["taken_by"]." ORDER BY emp_last";
} else {
?>
<option></option>
<?
$query = "SELECT * FROM sys_employee ORDER BY emp_last";
}
$result = @mysql_db_query($database, $query, $link)
or die("Could not complete database query");
while (($row = mysql_fetch_array($result)))
{
?>
<option value=<? echo $row["emp_id"]; ?>> <? echo $row["emp_first"]." ".$row["emp_last"] ;?>
</option>
<?
}
?>
</select>
<input name="cmdAssignedTo22" type="button" class="LinkButton"
id="cmdAssignedTo22" value="..."
onclick="redirect('../systems/system_edit.php');"></td>
</tr>
<?
}
?>
</table></td>
</tr>
<tr align="left" valign="top">
<td height="50" colspan="4" class="ColumnBody"> <div align="left"><br>
Activity</div>
<table width="700" height="94" border="0" align="left" cellpadding="0" cellspacing="0">
<tr valign="middle">
<td width="100" height="25" class="FormTitle"> <div align="right">
Date&nbsp;</div></td>
<td width="300">
<?
if(!$callID == "")
{
?>
<input name="txtStartDate" type="text" class="TextBoxGreen"
id="txtStartDate" width="170" value=<? echo $singleRow["call_date"]; ?>>
<?
} else {
?>
<input name="txtStartDate" type="text" class="TextBoxGreen"
id="txtStartDate" width="170" value=<? echo $current; ?>>
<?
}
?>
</td>
<td width="100" class="FormTitle">Status&nbsp;</td>
<td width="200"> <select name="cboStatus" class="SelectGreen" id="cboStatus">
<option></option>
<?
if(!$callID == "")
{
switch(trim($singleRow["status"]))
{
case "Assigned":
echo "<option value=".$singleRow["status"]." selected>".$singleRow["status"]."</option><option value='Pending'>Pending</option><option value='Resolved'>Resolved</option>";
break;
case "Pending":
echo "<option value=".$singleRow["status"]." selected>".$singleRow["status"]."</option><option value='Assigned'>Assigned</option><option value='Resolved'>Resolved</option>";
break;
case "Resolved":
echo "<option value=".$singleRow["status"]." selected>".$singleRow["status"]."</option><option value='Assigned'>Assigned</option><option value='Pending'>Pending</option>";
break;
default:
echo "<option value='Assigned'>Assigned</option><option value='Pending'>Pending</option><option value='Resolved'>Resolved</option>";
break;
}
} else {
?>
<option value="Assigned">Assigned</option>
<option value="Pending">Pending</option>
<option value="Resolved">Resolved</option>
<?
}
?>
</select> </td>
</tr>
<tr valign="middle">
<td width="100" height="56" class="FormTitle">
<div align="right">
Start Time&nbsp;
</div>
</td>
<td width="300">
<?
if(!$callID == "")
{
?>
<input name="txtStartTime" type="text" class="TextBoxGreen"
id="txtEndDate" width="170" value=<? echo $singleRow["start_time"]; ?>>
<?
} else {
?>
<input name="txtStartTime" type="text" class="TextBoxGreen"
id="txtEndDate" width="170" value=<? echo $startTime; ?>>
<?
}
?>
</td>
<td width="100" class="FormTitle">End Time&nbsp;</td>
<td width="200">
<?
if(!$callID == "")
{
?>
<input name="txtEndTime" type="text" class="TextBoxGreen"
id="txtEndTime" width="170" value=<? echo $singleRow["end_time"]; ?>>
<?
} else {
?>
<input name="txtEndTime" type="text" class="TextBoxGreen"
id="txtEndTime" width="170">
<?
}
?>
</td>
</tr>
</table></td>
</tr>
<tr valign="top">
<td height="111" colspan="4" class="ColumnBody">
<div align="left"><br>
Information<br>
<table width="700" height="82" border="0" align="left" cellpadding="0" cellspacing="0">
<tr valign="top">
<td width="100" height="24" class="FormTitle"> <div align="right">
Issue:&nbsp; </div></td>
<td width="600">

<textarea name="txtIssue" cols="100" rows="5" class="MultiTextBoxGreen"
id="txtIssue"><? if(!$callID =="") {echo rtrim($singleRow["issue_desc"]); }?>
</textarea>
</td>
</tr>
</table>
</div></td>
</tr>
</table>
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top