Sending a string with spaces from a from options value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cookie_monster
Forum Newbie
Posts: 5
Joined: Sat Apr 12, 2003 8:41 am
Location: Australia

Sending a string with spaces from a from options value

Post 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.
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post 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.
Last edited by scorphus on Sun Oct 26, 2003 6:53 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
cookie_monster
Forum Newbie
Posts: 5
Joined: Sat Apr 12, 2003 8:41 am
Location: Australia

Still does it

Post 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&#1111;'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&#1111;'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&#1111;'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&#1111;'image1']; ?></option>
				<?php
					$images_result=mysql_query("SELECT file, title FROM tbl_images");
					while($images_row=mysql_fetch_array($images_result))	
					&#123;  
    				  echo("<option value="  . $images_row&#1111;'file'] . ">" . $images_row&#1111;'file'] . "</option>");
					&#125;
				?>
              </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&#1111;'content']; ?></textarea>
              </i></p>
            <p align="left"><i> 
              <input type="reset" name="Reset" value="Clear">
              &nbsp;&nbsp;&nbsp;&nbsp; 
              <input type="submit" name="Submit" value="              Submit                ">
              &nbsp;&nbsp;&nbsp;&nbsp; 
              <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"
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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

&lt;option value=the value of images_row&#1111;file]&gt;the value of images_row&#1111;file]&lt;/option&gt;
.
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>';
}
User avatar
cookie_monster
Forum Newbie
Posts: 5
Joined: Sat Apr 12, 2003 8:41 am
Location: Australia

Doh!

Post 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
User avatar
cookie_monster
Forum Newbie
Posts: 5
Joined: Sat Apr 12, 2003 8:41 am
Location: Australia

Double Doh

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 :]
Post Reply