Jump to content

Problem with spaces in form field


jpl225

Recommended Posts

Hi!

 

I have a problem getting data to form value. Here is part of my code:

 

---clip---clip---clip---clip---clip---clip---clip---clip---clip---clip---clip

$result = mysql_query("SELECT yrityksennimi, yhteyshenkilonimi, yhteyshenkilotitteli, katuosoite, postinumero, postitoimipaikka, maa, puhelin, web, email FROM toimittajat Where yrityksennimi='$_POST[yritys]'");

 

$a = mysql_fetch_assoc($result);

echo $a["yhteyshenkilonimi"];

---clip---clip---clip---clip---clip---clip---clip---clip---clip---clip---clip

 

And this works fine. I get result: Jukka Norvanto

 

But if I try to put that result to form field:

 

---clip---clip---clip---clip---clip---clip---clip---clip---clip---clip---clip

<tr><td>Yrityksen nimi:</td><td><INPUT TYPE='text' NAME='Yritys' VALUE=" . $a['yhteyshenkilonimi'] ."></td>

---clip---clip---clip---clip---clip---clip---clip---clip---clip---clip---clip

 

I got result: Jukka

 

Somehow the code will cut everything after space away.

 

Any ideas, how to solve this?

 

Jyri

Link to comment
https://forums.phpfreaks.com/topic/173081-problem-with-spaces-in-form-field/
Share on other sites

<?php

$yhteys = mysql_connect("localhost","user","xxxx");

if (!$yhteys)

  {

  die('Tietokantaan ei saada yhteyttä: ' . mysql_error());

  }

 

mysql_select_db("sukellus", $yhteys);

if (! @mysql_select_db("sukellus") ) {

  echo( "<P>Unable to locate the sukellus " .

        "database at this time.</P>" );

  exit();

}

 

//echo "<B>" . $_POST[yritys] . " :n tiedot</B><p>";

$result = mysql_query("SELECT yrityksennimi, yhteyshenkilonimi, yhteyshenkilotitteli, katuosoite, postinumero, postitoimipaikka, maa, puhelin, web, email FROM toimittajat Where yrityksennimi='$_POST[yritys]'");

if (!$result) {

  echo("<P>Error performing query: " .

      mysql_error() . "</P>");

  exit();

}

$a = mysql_fetch_assoc($result);

echo $a["yhteyshenkilonimi"];

 

 

//while (list($Yritys, $Yhteyshlo, $Titteli, $Katu, $Postinro, $PTP, $Maa, $Puhelin, $Web, $Email) = mysql_fetch_assoc($result)){

echo "<form action='addseller.php' method='post'>

<table>

<tr><td>Yrityksen nimi:</td><td><INPUT TYPE='text' NAME='Yritys' VALUE=" . $a['yhteyshenkilonimi'] ."></td>

<tr><td>Yhteyshenkilön nimi:</td><td><INPUT TYPE='text' NAME='Yhteyshenkilo' VALUE=" . $Yhteyshlo . "></td>

<tr><td>Yhteyshenkilön titteli:</td><td><INPUT TYPE='text' NAME='Titteli' VALUE=" . $Titteli . "></td>

<tr><td>Katuosoite:</td><td><INPUT TYPE='text' NAME='Katuosoite' VALUE=" . $Katu . "></td>

<tr><td>Postinumero:</td><td><INPUT TYPE='text' NAME='Postinro' VALUE=" . $Postinro . "></td>

<tr><td>Postitoimipaikka:</td><td><INPUT TYPE='text' NAME='PTP' VALUE=" . $PTP . "></td>

<tr><td>Maa:</td><td><INPUT TYPE='text' NAME='Maa' VALUE=" . $Maa . "></td>

<tr><td>Puhelin:</td><td><INPUT TYPE='text' NAME='Puhelin' VALUE=" . $Puhelin . "></td>

<tr><td>WWW-osoite:</td><td><INPUT TYPE='text' NAME='Web' VALUE=" . $Web . "></td>

<tr><td>Sähköposti:</td><td><INPUT TYPE='text' NAME='Email' VALUE=" . $Email . "></td>

</table></form>";

//}

?>

Run this, tell me what it says at the bottom:

<?php
	$yhteys = mysql_connect("localhost","user","xxxx");
	if (!$yhteys)
  		{
  			die('Tietokantaan ei saada yhteyttä: ' . mysql_error());
  		}

	mysql_select_db("sukellus", $yhteys);
if (! @mysql_select_db("sukellus") ) {
  echo( "<P>Unable to locate the sukellus " .
        "database at this time.</P>" );
  exit();
}

//echo "<B>" . $_POST[yritys] . " :n tiedot</B><p>";
$result = mysql_query("SELECT yrityksennimi, yhteyshenkilonimi, yhteyshenkilotitteli, katuosoite, postinumero, postitoimipaikka, maa, puhelin, web, email FROM toimittajat Where yrityksennimi='$_POST[yritys]'");
if (!$result) {
  echo("<P>Error performing query: " .
       mysql_error() . "</P>");
  exit();
}
$a = mysql_fetch_assoc($result);
echo $a["yhteyshenkilonimi"];


//while (list($Yritys, $Yhteyshlo, $Titteli, $Katu, $Postinro, $PTP, $Maa, $Puhelin, $Web, $Email) = mysql_fetch_assoc($result)){
echo "<form action='addseller.php' method='post'>
<table>
	<tr><td>Yrityksen nimi:</td><td><INPUT TYPE='text' NAME='Yritys' VALUE=" . $a['yhteyshenkilonimi'] ."></td>
	<tr><td>Yhteyshenkilön nimi:</td><td><INPUT TYPE='text' NAME='Yhteyshenkilo' VALUE=" . $Yhteyshlo . "></td>
	<tr><td>Yhteyshenkilön titteli:</td><td><INPUT TYPE='text' NAME='Titteli' VALUE=" . $Titteli . "></td>
	<tr><td>Katuosoite:</td><td><INPUT TYPE='text' NAME='Katuosoite' VALUE=" . $Katu . "></td>
	<tr><td>Postinumero:</td><td><INPUT TYPE='text' NAME='Postinro' VALUE=" . $Postinro . "></td>
	<tr><td>Postitoimipaikka:</td><td><INPUT TYPE='text' NAME='PTP' VALUE=" . $PTP . "></td>
	<tr><td>Maa:</td><td><INPUT TYPE='text' NAME='Maa' VALUE=" . $Maa . "></td>
	<tr><td>Puhelin:</td><td><INPUT TYPE='text' NAME='Puhelin' VALUE=" . $Puhelin . "></td>
	<tr><td>WWW-osoite:</td><td><INPUT TYPE='text' NAME='Web' VALUE=" . $Web . "></td>
	<tr><td>Sähköposti:</td><td><INPUT TYPE='text' NAME='Email' VALUE=" . $Email . "></td>
	</table></form>";
//}	

echo "<br /><br />";
echo "What does this say? " . $a['yhteyshenkilonimi'];
?>

Pekka Jokimies

Notice: Undefined variable: Yhteyshlo in C:\wamp\www\test.php on line 78

 

Notice: Undefined variable: Titteli in C:\wamp\www\test.php on line 84

 

Notice: Undefined variable: Katu in C:\wamp\www\test.php on line 90

 

Notice: Undefined variable: Postinro in C:\wamp\www\test.php on line 96

 

Notice: Undefined variable: PTP in C:\wamp\www\test.php on line 102

 

Notice: Undefined variable: Maa in C:\wamp\www\test.php on line 108

 

Notice: Undefined variable: Puhelin in C:\wamp\www\test.php on line 114

 

Notice: Undefined variable: Web in C:\wamp\www\test.php on line 120

 

Notice: Undefined variable: Email in C:\wamp\www\test.php on line 126

Yrityksen nimi:

Yhteyshenkilön nimi:

Yhteyshenkilön titteli:

Katuosoite:

Postinumero:

Postitoimipaikka:

Maa:

Puhelin:

WWW-osoite:

Sähköposti:

 

 

What does this say? Pekka Jokimies

So MySql will return right info: Pekka Jokimies, but when I try to put it into form value, it will show only Pekka (everything after first space will be removed).

 

$a = mysql_fetch_assoc($result);

echo $a["yhteyshenkilonimi"];

 

Will return Pekka Jokimies, but

 

echo "<form action='addseller.php' method='post'>

  <table>

      <tr><td>Yrityksen nimi:</td><td><INPUT TYPE='text' NAME='Yritys' VALUE=" . $a['yhteyshenkilonimi'] ."></td></table></form>";

 

will return only Pekka

 

So the problem is in that form -clause?

 

Jyri

 

 

You have not contained the value of the text element within quotes correctly. This is the case with all of your form elements. Validate your HTML:

<?php
echo "<tr><td>Yrityksen nimi:</td><td><INPUT TYPE='text' NAME='Yritys' VALUE='".$a['yhteyshenkilonimi']."'></td>";
?>

Cleaner html should use double quotes for html attributes i.e

<?php
echo "<tr><td>Yrityksen nimi:</td><td><INPUT TYPE=\"text\" NAME=\"Yritys\" VALUE=\"".$a['yhteyshenkilonimi']."\"></td>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.