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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

field string variables with spaces

Status
Not open for further replies.

HOTLIPS

Technical User
Dec 5, 2000
55
GB
Hi
Can anyone help ... i am reading in from mysql database...and
setting php variable equal to a $_request variable from database....but because the variable ...
ie "name" is John Smith....the variable only picks up the John and not the Smith...is this because of the space between the name John Smith????...
Code sample
$name=$_request['name']...
Cant find any details in manuals regarding this

Hotlips
 
$name="$_request['name']"; should fix it.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 

Hi

thanks but tried that and get error message ....

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\Apache Group\Apache2\htdocs\index.php on line 14


Hotlips
 
show us yer code :)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Hi
I enclose my code
I seem to have sorted the space problem on variable($Manufacturer)...("Smith Jones")..(not $name which I used as example) .. by inserting double quotes in the href link codeing .. this sends the variable back ok including the space.....the name or manufacturer name I originally had trouble with was "Smith & Jones" ......I realised that the "&" was also causing a problem..so I missed it out...... Can u confirm that mysql or php does not like "&"

Many thanks
Hotlips


<html><head><title>W&WCOUK</title>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;wandw.css&quot;>
<script language=JavaScript src=catlist.js type=text/javascript></script>
<script language=JavaScript src=stdinc.js type=text/javascript></script>
<script language=JavaScript type=text/javascript>
</script>
<?php>
//session_start() ;
include_once(&quot;dbconnectwandw.php&quot;);
$page=&quot;&quot;;
$Manufacturer=&quot;Startup&quot;;
$range=&quot;&quot;;
$page=$_REQUEST['page'];
$Manufacturer=$_REQUEST['Manufacturer'];
$range=$_REQUEST['range'];
// $page=&quot;&quot;;
// $Manufacturer=&quot;&quot;;
$today = date(&quot;l&quot;).&quot; &quot;.date(&quot;d F Y&quot;) ;
$string=&quot;&quot;
//echo ($page) ;
//echo ($Manufacturer) ;


?>
</head><body>
<div style='position:absolute;top:0px;left:0px;visibility:hidden;color:#000000;background-color:#000000'>
</div>
<div style='position:absolute; left:1; top:0; width:780' >
<div style='position:absolute; left:0; top:0; width:779; height:119'><img src=images/wwetc2.gif width=779 height=120>
<!-- *********** create top menu ********* -->
<div style='position:absolute; left:0; top:95; width:779; height:24'>
<table class=menu4 width=779>
<tr><th><a href=&quot;index.php?page=Home&quot;>Home</a></th><th><a href=&quot;index.php?page=aboutus&quot;>About us</a></th><th>Home</th><th>Home</th><th>Terms & conditons</th><th>Contact us</th></tr>
</table>
</div>
<!-- ***************** end top menu ************* -->
</div>
<!-- <div style='position:absolute; left:0; top:0; width:779; height:50'><img src=images/quadtrader_background.gif width=779 height=500></div> -->
<div style=' z-index:2; position:absolute; right:10; top:10; text-align:right; color:#000000'><?php echo($today)?><br></div>
<div class=Main2 style='position:absolute; width:119; left:1; text-align:left; top:119; height:500'>

<?php
//**************** Do query to get list of products categories and descriptions for left menu************************
$sqlcat = &quot;SELECT * FROM Category&quot;;
$resultcat = mysql_query($sqlcat, $conn) or die(mysql_error());

//**************** Do query to get list of manufacturers.by category..ie wallpapers..fabrics ************************
$sql1 = &quot;SELECT DISTINCT c1.Category, c1.Manufacturer, c2.categoryno, c2.categorydesc
FROM stockcatalog AS c1, category AS c2
WHERE c1.category = c2.categoryno
GROUP BY c1.category, c1.manufacturer&quot;;
$result1 = mysql_query($sql1, $conn) or die(mysql_error());
//$myrow= mysql_fetch_array($result1);
//$rangename=$myrow1['range'];
// if (mysql_num_rows($result1)>0){ //does the range already exist?

$stylepicked=&quot;style='color: green '&quot; ;

//**************** Do query to get Range or collection from selected manufacturer ************************
$sql = &quot;SELECT DISTINCT range FROM stockcatalog WHERE category = '$page' and Manufacturer = '$Manufacturer'&quot;;
$result = mysql_query($sql, $conn) or die(mysql_error());
//************ loop through query result and create sub list of ranges/collections ***********************add &nbsp; at end of field to print cell border if cell empty
while ($myrow = mysql_fetch_array($result))
{
$string.=&quot;&nbsp; &nbsp; &nbsp; <a href=&quot;.&quot;\&quot;&quot;.&quot;/index.php?page=&quot;.$page.&quot;&Manufacturer=&quot;.$Manufacturer.&quot;&range=&quot;.$myrow['range'].&quot;\&quot;&quot;;
//if (($page==$myrowcat['categoryno'])&&($Manufacturer==$myrow1['Manufacturer'])&&($range==$myrow['range'])) {
if ($range==$myrow['range']) {
$string.=&quot;&nbsp; style='color: green'&quot;;
$s=&quot;OKOK&quot; ;
}

$string.=&quot;>&quot;.$myrow['range'].&quot;</a><br>\n&quot; ;
//$string.=&quot;&nbsp; &nbsp; &nbsp;&quot;.$myrow['range'].&quot;</a><br>\n&quot; ;
}
?>
<!--**************** create LEFT menu from earlier querys(sqlcat) to database *********************************************** -->
<table class=menuLeft>
<?php

while ($myrowcat = mysql_fetch_array($resultcat)) {
echo(&quot;<tr><th>&quot;.$myrowcat['categorydesc'].&quot;</th></tr><tr><td>&quot;); // list CATEGORIES

mysql_data_seek($result1,0); // put the array pointer to the start of the array

while ($myrow1 = mysql_fetch_array($result1)) {
if ($myrow1['Category']==$myrowcat['categoryno']) {
// echo($myrow1['category']) ;
echo(&quot;<a href=&quot;.&quot;\&quot;&quot;.&quot;/index.php?page=&quot;.$myrow1['Category'].&quot;&Manufacturer=&quot;.$myrow1['Manufacturer']).&quot;\&quot;&quot; ;
//************ change font color to green for selected manufacturer
if (($page==$myrowcat['categoryno'])&&($Manufacturer==$myrow1['Manufacturer'])) {
echo (&quot;&nbsp; style='color: green'&quot;);
}
echo (&quot;>&quot;.$myrow1['Manufacturer'].&quot;</a><br>\n&quot;) ; // list MANUFACTURES
if (($page==$myrowcat['categoryno'])&&($Manufacturer==$myrow1['Manufacturer'])) {
$catdesc=$myrowcat['categorydesc']; // get the category desc for main section of page
echo($string) ;} // create list of RANGES OF CATEGORIES by SELECTED MANUFACTURER
}
}
echo(&quot;<br><br></td</tr>&quot;) ; // put spaces between categories

}
// echo ($page) ;
// echo ($Manufacturer).&quot;<br>&quot;;
// echo ($range).&quot;<br>&quot;;
// echo $_GET['Manufacturer'] ;
//**********end of left menu ************************************************
?>
</td</tr>
<?php

?>
<style type=&quot;text/css&quot; ><!-- CAPTION {color: blue; font-size=10pt} --></style> <!--- ******** STYLE ***** -->
</div>
<!-- ********* create MAIN section of page **************************************** -->
<div class=main2 style='position:absolute; left:120; top:0; width:658; height:500'>
<?php

// ********** first create details of ALL RANGES by manufacturer as per category ***************
if (($page>0)&&($Manufacturer<>Startup)&&($range==&quot;&quot;)){
//********** Do query to FULL Range of ALL collection from selected manufacturer of ALL categories************************
$sql2a = &quot;SELECT * FROM stockcatalog WHERE category = '$page' and Manufacturer ='$Manufacturer'&quot;;
$result2a = mysql_query($sql2a, $conn) or die(mysql_error());
//************ loop through query result and create table ***********************add &nbsp; at end of field to print cell border if cell empty
$string2a.=&quot;<table class=menu5 width=658 ><Caption align=top>&quot;.$catdesc.&quot; by &quot;.$Manufacturer.&quot;</caption><tr><th>StockID</th><th>Pattern No</th><th>Description</th><th>Price</th><th>Prod code</th><th>Width/<br>Depth</th><th>Pattern Repeat</th><th>Sample</th></tr>&quot;;
while ($myrow2a = mysql_fetch_array($result2a)) {
$string2a.=&quot;<tr><td>&quot;.$myrow2a['stockID'].&quot;</td><td>&nbsp;&quot;.$myrow2a['patternname'].&quot;</td><td>&quot;.$myrow2a['description'].&quot;</td><td>&nbsp;&quot;.$myrow2a['price'].&quot;</td><td>&nbsp;&quot;.$myrow2a['productcode'].&quot;</td>
<td>&quot;.$myrow2a['width'].&quot;<br>&quot;.$myrow2a['depth'].&quot;</td><td>&nbsp;&quot;.$myrow2a['patternrepeat'].&quot;</td>
<td><a href='../images/{$myrow2a['pix2']}' border='0'><img src='../images/{$myrow2a['pix1']}' border='0'width='100' height='80'></a></td></tr>\n&quot; ;
}
echo ($string2a);} //create table of ALL RANGES in ALL CATEGORIES
//**************************** now do JUST the RANGE in category ONLY ***********************************************************

if (($page>0)&&($Manufacturer<>Startup)&&($range<>&quot;&quot;)){
//$stylepicked=&quot;<style='color: green'>&quot; ;
//**************** Do query to get Range or collection from selected manufacturer ************************
$sql2 = &quot;SELECT * FROM stockcatalog WHERE category = '$page' and Manufacturer ='$Manufacturer' and range='$range'&quot;;
$result2 = mysql_query($sql2, $conn) or die(mysql_error());

//************ loop through query result and create table ***********************add &nbsp; at end of field to print cell border if cell empty
$string2.=&quot;<table class=menu5 width=658 ><CAPTION align=top>&quot;.$catdesc.&quot; - &quot;.$range.&quot; range by &quot;.$Manufacturer.&quot;</CAPTION><tr><th>StockID</th><th>Pattern No</th><th>Description</th><th>Price</th><th>Prod code</th><th>Width/<br>Depth</th><th>Pattern Repeat</th><th>Sample</th></tr>&quot;;
while ($myrow2 = mysql_fetch_array($result2)) {
$string2.=&quot;<tr><td>&quot;.$myrow2['stockID'].&quot;</td><td>&nbsp;&quot;.$myrow2['patternname'].&quot;</td><td>&quot;.$myrow2['description'].&quot;</td><td>&nbsp;&quot;.$myrow2['price'].&quot;</td><td>&nbsp;&quot;.$myrow2['productcode'].&quot;</td>
<td>&quot;.$myrow2['width'].&quot;<br>&quot;.$myrow2['depth'].&quot;</td><td>&nbsp;&quot;.$myrow2['patternrepeat'].&quot;</td>
<td><a href='../images/{$myrow2['pix2']}' border='0'><img src='../images/{$myrow2['pix1']}' border='0'width='100' height='80'></a></td></tr>\n&quot; ;
}
echo ($string2);} // create table of SELECTED RANGE
?>
</table>
<!--- ****************************************************************************************************
<!-- </div> -->
<?php
if (($page==Home)or ($page==&quot;&quot;)){
$stringhome.=&quot;<div class=main2 style='position:absolute; left:120; top:0; width:658; height:500'>&quot;;
$stringhome.=&quot;This our HOME PAGE&quot;;
echo($stringhome);
}
if ($page==aboutus){
$stringhome.=&quot;<div class=main2 style='position:absolute; left:120; top:0; width:658; height:500'>&quot;;
$stringhome.=&quot;This our ABOUT US PAGE&quot;;
echo($stringhome);
}
?>
</div>
</div>
</body>

</html>
 
Look at this line:
Code:
<a href=&quot;.&quot;\&quot;&quot;.&quot;/index.php?page=&quot;.$page.&quot;&Manufacturer=&quot;.
Code:
$Manufacturer.
Code:
&quot;&range=&quot;.$myrow['range'].&quot;\&quot;&quot;;

Note that you just printed the name &quot;X & Y&quot; in there. The ampersand is used to concatenate GET elements in the URL. If you variable $Manufacturer contains an ampersand you have to URL encode it first before inserting it. Otherwise the ampersand is literally interpreted as separator for the next GET parameter.

Have a look at the urlencode() function:
 
Thanks alot
I have now put my &quot;&&quot; and &quot;spaces&quot; back in my manufacturers name field in my data base and its working a treat.

Many thanks again

Hotlips
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top