# [SOLVED] PHP SQL variable cut off



## JayKF014 (Dec 10, 2004)

Below is the full code for one of the web pages I am currently developing. The idea is to display data stored on a SQL database, through the web browser, with the data being interactive and relational. So you can search for a value, bring up a list of those values and any corresponding values, click on another value which creates a new search for that value, etc.

The problem area is bolded in the code below. Everything seems to work fine except for when the variables (var1 - var6) are incorporated into the href links after the '?'. (See Below) The variable, say 'My Name', is dumped from the database into variable var1, then displayed in '.list'. However after the '?' in the href url, the variable is only 'My'. The variable cuts off at the space, but it doesn't do that anywhere else. Any ideas why?

so if....

POC = My Name ....
$var1 = $row['POC']; ...
<a href=searchPOC.php?POC=$var1>$var1</a>

____________________________^___^
___________________________'My'__'My Name'______-___why's it do that?

-----------------------------------------------------
CODE BELOW
-----------------------------------------------------

<html><head><title>POC Search Result</title></head><body bgcolor=#CCFFFF>

<?php
$URL = $_GET["URL"];
$Project = $_GET["Project"];
$POC = $_GET["POC"];
$Server = $_GET["Server"];
$ChargeCode = $_GET["ChargeCode"];
$Database = $_GET["DatabaseName"];

[email protected]_connect("localhost", "user", "pass")
or die("Could not connect");


$rs = @mysql_select_db("databasename", $conn)
or die("Could not select database");

$sql="SELECT * FROM pocs WHERE POC LIKE '%" . $POC . "%'";

$rs=mysql_query($sql,$conn)
or die("Could not execute query");

$list = "<table border=\"1\" bordercolor=black width=\"100%\" cellpadding=\"2\">";
$list.="<tr><th><u>POC</u></th>";
$list.="<th><u>URL</u></th>";
$list.="<th><u>Project</u></th>";
$list.="<th><u>Server</u></th>";
$list.="<th><u>ChargeCode</u></th>";
$list.="<th><u>Database</u></th>";

$counter=0;
while($row= mysql_fetch_array($rs))
{
$counter++;
if ($counter % 2)
{
$newRowColor=fuchsia;
}
else
{
$newRowColor=yellow;
}

*$var1 = $row['POC'];
$var2 = $row['URL'];
$var3 = $row['Project'];
$var4 = $row['Server'];
$var5 = $row['ChargeCode'];
$var6 = $row['DatabaseName'];

$list .= "<tr bgcolor=$newRowColor>";
$list .= "<td><a href=searchPOC.php?POC=$var1>$var1</a></td>";
$list .= "<td><a href=searchURL.php?URL=$var2>$var2</a></td>";
$list .= "<td><a href=searchProject.php?Project=$var3>$var3</a></td>";
$list .= "<td><a href=searchServer.php?Server=$var4>$var4</a></td>";
$list .= "<td><a href=searchChargeCode.php?ChargeCode=$var5>$var5</a></td>";
$list .= "<td><a href=searchDatabaseName.php?DatabaseName=$var6>$var6</a></td>";
$list .= "</tr>";

}

$list .= "</table><hr>";
echo($list);*?>

</body></html>


----------



## dm01 (Oct 10, 2006)

*Re: PHP SQL variable cut off*

The var is being cut off because you have a space between "My" and "Name". Either delete or replace this space to correct the issue.


----------



## JayKF014 (Dec 10, 2004)

*Re: PHP SQL variable cut off*

Those are the only possible options?

I understood that already but I was hoping there would be a method to fix the variable so that it doesn't end the string after a space? It doesn't get cut off in any other location other than the URL itself, and in the source the entire string is present there too. So for some reason the browser isn't recognizing the entire string even though it is there in the source? Or in that case could it possibly be an issue with the browser or web server? I don't suspect it is an issue with the database configuration because the data presents itself entirely in the variables var1 - var6.


----------



## JayKF014 (Dec 10, 2004)

*Re: PHP SQL variable cut off*

Problem Resolved. Resolution:

$var1a = $row['URL'];
$var1b = str_replace(" ","%25",$var1a);
$var2a = $row['Project'];
$var2b = str_replace(" ","%25",$var2a);
$var3a = $row['POC'];
$var3b = str_replace(" ","%25",$var3a);
$var4a = $row['Server'];
$var4b = str_replace(" ","%25",$var4a);
$var5a = $row['ChargeCode'];
$var5b = str_replace(" ","%25",$var5a);
$var6a = $row['DatabaseName'];
$var6b = str_replace(" ","%25",$var6a);

$list .= "<tr bgcolor=$newRowColor>";
$list .= "<td><a href=searchURL.php?URL=$var1b>$var1a</a></td>";
$list .= "<td><a href=searchProject.php?Project=$var2b>$var2a</a></td>";
$list .= "<td><a href=searchPOC.php?POC=$var3b>$var3a</a></td>";
$list .= "<td><a href=searchServer.php?Server=$var4b>$var4a</a></td>";
$list .= "<td><a href=searchChargeCode.php?ChargeCode=$var5b>$var5a</a></td>";
$list .= "<td><a href=searchDatabaseName.php?DatabaseName=$var6b>$var6a</a></td>";
$list .= "</tr>";


----------

