Page 1 of 1
Sending a string with spaces from a from options value
Posted: Sun Oct 26, 2003 6:15 pm
by cookie_monster
Is there a secret involved which will allows the whole string including spaces to be sent from a options value from within a form?
I have drop down options which contain file names and some of these file names have spaces in them. When they are selected in the drop down list they are added to a mysql database but only the first word before the first space gets added.
Could anyone help me please.
Posted: Sun Oct 26, 2003 6:29 pm
by scorphus
Please post the code that gets info from the form. Also post the way you are querying the DB, the query itself. Also mention which method you are using POST or GET and, if you can, do a print_r($_POST) or print_r($_GET). Then I think you will get helped faster.
Best regards,
Sco.
Posted: Sun Oct 26, 2003 6:39 pm
by volka
you probably
forgot to quote the property-values
Code: Select all
<html>
<head>
<title>quote the properties</title>
</head>
<body>
<pre><?php print_r($_POST); ?></pre>
<form method="POST" action="<?php echo $_SERVER['PHP_SERVER']; ?>">
<select name="aName">
<option value=this is without quotes and will fail>without quotes</quote>
<option value="this is with quotes">with quotes</quote>
</select>
<input type="submit" />
</form>
</body>
</html>
In case of doubt, quote
all values.
Still does it
Posted: Sun Oct 26, 2003 7:13 pm
by cookie_monster
It still only send the first word from the option menu. Here is the code and the print_r($_POST) stuff
Code: Select all
<form action="news_process.php" method="post" name="form1">
<blockquote>
<div align="left">
<input type="hidden" name="id" value="<? echo $news_rowї'id']; ?>">
</div>
<p align="left"><i> <span class="smallheading">Title</span></i><br>
<input name="title" type="text" id="title" size="80" value="<? echo $news_rowї'title']; ?>">
</p>
<p align="left"><span class="smallheading"><i>Date (yyyy-mm-dd)</i></span><i><br>
<input name="date" type="text" id="date" value="<? echo $news_rowї'date']; ?>">
</i></p>
<p align="left"><span class="smallheading"><i>Image</i></span><i><br>
<!-- This is the options which gabs image file name from a database -->
<select name="file" id="file">
<option selected><? echo $news_rowї'image1']; ?></option>
<?php
$images_result=mysql_query("SELECT file, title FROM tbl_images");
while($images_row=mysql_fetch_array($images_result))
{
echo("<option value=" . $images_rowї'file'] . ">" . $images_rowї'file'] . "</option>");
}
?>
</select>
<a href="upload.php" class="body">Upload New Image</a></i></p>
<p align="left"><span class="smallheading"><i>Content</i></span><i><br>
<textarea name="content" cols="80" rows="10" id="content"><? echo $news_rowї'content']; ?></textarea>
</i></p>
<p align="left"><i>
<input type="reset" name="Reset" value="Clear">
<input type="submit" name="Submit" value=" Submit ">
<input name="type" type="submit" value="Delete">
</i></p>
</blockquote>
</form>
Here is the print_r($_POST) stuff
Array
(
[id] =>
[title] => Example title
[date] => 2002-04-22
[file] => Advance
[content] => Testing content
[Submit] => Submit
)
The file should have been "Advanced Flooring race.JPG"
Posted: Sun Oct 26, 2003 7:23 pm
by volka
echo("<option value=" . $images_row['file'] . ">" . $images_row['file'] . "</option>");
the property is
not quoted. I do not refer to php's point of view but to the client's.
Th client receives something like
Code: Select all
<option value=the value of images_rowїfile]>the value of images_rowїfile]</option>
.
If what you want to send as the option's value is identical to what is displayed, there's no need for an value-property at all.
Anyway, try
Code: Select all
while($images_row=mysql_fetch_array($images_result))
{
echo '<option value="',$images_row['file'], '">', $images_row['file'], '</option>';
}
Doh!
Posted: Sun Oct 26, 2003 7:30 pm
by cookie_monster
Something so simple.
Thanks for finding the problem volka, sometimes a fresh pair of eyes does the trick.
Is there a PHP scripting program out there that would have picked that up like edit plus?
Joe
Double Doh
Posted: Sun Oct 26, 2003 7:33 pm
by cookie_monster
Don't you hate it when you just over look such a simple problem like that expecting yourself not be that careless.
Posted: Sun Oct 26, 2003 7:42 pm
by volka
yeah, I really do

Those are usually the only code fragments with lots of comments by me...you see them and you know I had trouble finding an error :]