Forum Moderators: coopster

Message Too Old, No Replies

trying to pass info from html form

odd display on php form output

         

huds

6:47 pm on Jun 15, 2005 (gmt 0)

10+ Year Member



Hi there,

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?

mcibor

9:00 pm on Jun 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does it display so in the html browser or source code?

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!

huds

4:32 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



Thanks Michal, I will try that.

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.

huds

5:34 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



I just tried it with the new code and still no joy.

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?

mcibor

8:10 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the source code is correct and only the browser showes new line, then the problem lies within html, not php.

Does your html validate? Maybe it's something in the css you use. Did you check other browsers?

Pass part of parsed html, and I'll try to see what may be wrong

huds

11:07 am on Jun 18, 2005 (gmt 0)

10+ Year Member



here's the parsed html...

<form name="options" method="post">

<table><tr><td>Php Practice page 3</td></tr></table>

It is working though, since I moved the <table> tags inside the php echo.