Jump to content

Help...!!! Data loss after spce, Simple problem


t4tipu

Recommended Posts

Save the code below in "test.php" and execute... When i select the third option i-e "This is the sentence", only "This" is posted and the data after this is not echoed/posted... Please help...

 

<?php
if("$_POST[submit]"=="Update")
{
$hello=$_POST['list'];
echo "You selected : ".$hello;
}
?>


<form action="test.php" method="POST">

<select name="list">
<option value="">Select1</option>
<option value="Select2">Select2</option>
<?php
$var="This is the sentence";
echo "<option value=".$var.">".$var."</option>";
?>
</select>

<input class="button" type='submit' name="submit" value="Update">
</form>

I posted the solution. the contents of the value attribute need to be within quotes.

 

Theres a few other issues with the code though (I didn't notice earlier). Here, is what it ought look like:

 

<?php

if (isset($_POST['submit']))
{
  $hello=$_POST['list'];
  echo "You selected : ".$hello;
}
?>

<form action="test.php" method="POST">
<select name="list">
  <option value="">Select1</option>
  <option value="Select2">Select2</option>
<?php
  $var="This is the sentence";
  echo "  <option value='$var'>$var</option>";
?>
</select>
<input class="button" type='submit' name="submit" value="Update">
</form>

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.