Forum Moderators: coopster
I'm mucking about with forms and php, and trying to pass an option selection to a variable.
Some of the text in the option tags from the html form have spaces between them, and when they are echoed they display each word on a new line.
Is there a way to stop this and echo to one line only?
Here is the form part of the code...
<form name="select" method="post" action="edit.php">
<p>
<select name="selection">
<?php
include ('set.php');
// Display page edit selection menu
while ($formrow = mysql_fetch_assoc($adminfileinfo)) {
$page_items = $formrow['linktext'];
echo "<option value=\"$page_items\" name=\"$page_items\">$page_items</option>\n";
}
?>
And here is the edit part...
<?php
$columnselect = $_POST["selection"];
$rowreturn = "SELECT * FROM menu WHERE linktext = '$columnselect'";
$rowdata = mysql_query($rowreturn) or die('Query failed: ' . mysql_error());
// Test variable
echo "$columnselect";
?>
e.g. If the $columnselect variable was THIS IS THE TEXT then it appears,
THIS
IS
THE
TEXT
aaarrgggh!
What am I doing wrong?
Moreover option doesn't have the name (it's in the select).
The only way this is possible is that you pass those new lines from a db.
You can get rid of them with this function
$columnselect = str_replace(array("\n", "\r"), "", $_POST["selection"]);
This will get rid of any new line in $columnselect
Best regards
Michal Cibor
PS. But there shouldn't be any, unless you have that in your db. Strange!
The new lines display in the browser only,
the source code shows the text correctly as it appears in the database.
So I am mystified!
What I do know is I can't query on that variable either, so I am guessing that php is reading it with new lines also.
Oh well, maybe just one of those things.
Thanks for the workaround anyway.
But I got it to work,
Maybe I should have included the full html, as there was a table tag before the php code, and then a closing tag after it.
I removed the table, and low n' behold...
Can anyone explain this though?
Is it bad practice to put php inside a table?
should I echo the table instead?