Jump to content

How to transfer form data into php?


beginann

Recommended Posts

I am looking for a way to transfer form data into php variables. I can not figure out how to transfer select values. Can anyone help?

This is my formcode:

<form method="post" action="namn.php">
<select name="select" size="1" class="text_11" onChange="MM_jumpMenu('parent',this,0)">
  <option value="Välj namn" selected="selected">Välj namn</option>
  <option value="namn.php">Alverdal Nedin Liselotte</option>
  <option value="namn.php">Andersson Annica</option>
  <option value="namn.php">Andersson Inga-Lill</option>
  <option value="namn.php">Bendelin Kerstin</option>
  <option value="namn.php">Boulogner Kerstin</option>
</select>
</form>  

 

This is my php-code:

<?php

$namn=$_POST["namn"];

//Söker alla  
    	$query = "SELECT namn, verksamhet FROM verksamhet WHERE namn LIKE '%namn%'";
	$result = mysql_query($query);
		if(!$result){
	   	echo "<div class=tabell1><table><tr><td>Frågan är fel ställd. MySQL rapporterar: " . mysql_error() ."</td></tr>";
		echo "</table></div>";
		}
		else if ($result && mysql_num_rows($result) > 0)
		{
			echo "<div class=tabell1><table>
			<tr><td> </td></tr>;
			<tr><td> </td></tr>;
			<tr><td> </td></tr>;
			<tr><td><h5>Namn        </h5></td>;				
			<td><h5>    Verksamhet</h5></td></tr>";
			while(false !== ($line = mysql_fetch_assoc($result)))
			{
			echo "<tr><td>" . $line["namn"] ."</td>
			<td>    " . $line["verksamhet"] ."</td></tr>";
			}
			echo "</table></div>";
		}

	// Stänger anslutningen till vår databas
        	mysql_close($connection);

?>

 

Many thanks for some help!!

A-B

Link to comment
https://forums.phpfreaks.com/topic/47142-how-to-transfer-form-data-into-php/
Share on other sites

You have all your values set the same

 

Should be like:

<form action='doc.php' method ='post'>
<select name="type" id="type">
<option value='0' selected>Select One</option>
<option value='Comic Book'>Comic Book</option>
<option value='Trade'>Trade</option>
</select>
</form>

Chnage:

$namn=$_POST["namn"];

 

to

 

$namn=$_POST["select"];

-select is name of your combobox/select.


 

You should change name of your select tag (for example:

<select name="lst_books" size="1" class="text_11" onChange="MM_jumpMenu('parent',this,0)">)

and your first php line would be like this:

$namn=$_POST["lst_books"];

 

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.