Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

blank space in access text field not seen as value in html

Codes here !

Moderators: macek, egami, gesf

blank space in access text field not seen as value in html

Postby jac » Sun Oct 14, 2012 10:39 am

Hello everyone, this is a rather peculiar problem that I have been banging my head against for a while. I am using an MS database that has pump information, it is converted to a MYSQL database and stored on the server. I use a field of the db to populate an html select widget to select the country of origin this then is used to display more info. Here is a short part of the code that produces the error:

Code: Select all
<?php

// standard html web header
require 'header.html';
// html user data input form
 require 'dbpump.php';
?>
<font size="14"><b>PumP search</b></font>
<br />
<br />
<?php
$query = "SELECT DISTINCT home_office FROM data ORDER BY home_office ASC";

if(!($connection = @ mysql_connect($hostName,$username,$password)))
   die("Could not connect");

//select database to edit
if(!(@ mysql_select_db($databaseName, $connection)))
showerror();
   
if(!($result = @ mysql_query($query)))
   showerror();
if(isset($_get['headoffice']))
{
    //required to recover from server the previous selection
    $headoffice = $_get['headoffice'];
}
?>

<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">   
<b>Home office country:</b>
<select name="headoffice">
<option value="All">All</option>
<?php
//cycles through all the home office countries in db and lists them in the html select
while($row = mysql_fetch_array($result))
{
if ($headoffice == $row['home_office'])
echo   "<option SELECTED value=".$row['home_office'].">".$row['home_office']."</option>";
else
echo "<option value=".$row['home_office'].">".$row['home_office']."</option>";
}   ///end while

mysql_free_result($result);
//this country added manually to see effect, works fine!
if ($headoffice == "New Jac territory") echo   "<option SELECTED value=\"New Jac territory\">New Jac territory</option>";
else echo   "<option value=\"New Jac territory\">New Jac territory</option>";
echo  "</select>";?>

<input type="submit" value="SEARCH">
</form>

<br />
<?php //echo $headoffice;?>
<?php // standard html web page footer
require 'footer.html';?>



you run from this web site: http://www.pumpfundamentals.com/pumpdatabase2/test2.php

What happens is when you select South Africa and you click the Search button, the get function will only transmit the first part of the term or "South" so that you can't do a match to display further information.

I typed the country "New Jac territory" directly in the html as the last html select item to appear in the list; this has a couple of blanks and works fine. So it seems that html does not interpret correctly the value coming from the mysql db.

I hope I explained this properly.

Thanks,

Jacques
jac
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sun Jul 18, 2010 6:07 am

Re: blank space in access text field not seen as value in ht

Postby seandisanti » Tue Oct 16, 2012 12:38 pm

Is the drop down populated by values in the database, or is it static? Have you confirmed that you in fact have data with multiple words in the table? I ask because if it was an issue with the script, your test entry shouldn't have worked. also, may want to look at htmlentities to make a string html can definitely understand. I suspect you've had some data corruption in your migration though and you may not have the data that you think you do.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: blank space in access text field not seen as value in ht

Postby jac » Tue Oct 16, 2012 12:59 pm

Thanks. I have found the solution, the option value was not in quotes as can be seen in view source. What threw me was that it was working for a one word string.

Cheers,

Jacques
jac
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sun Jul 18, 2010 6:07 am


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.