Posting dropdown value to database

Hello.

First of all, i want to apologize for my question, since the code im about to post is way outdated.

I am hosting this script on a server which is running a very old version of php.

The website is used by me and 2 other friends, and we are the only ones able to connect to it, due to .htaccess only showing the page to recognized ip adresses… So there is no need to protect against sql injection or anything.

Now that thats out of the way, here is the problem i am facing:

i have a php script, which is showing a dropdown menu, with values gathered from a mysql table called chat_clothes.

I then have a submit button, that is supposed to post whatever you have chosen in the dropdown menu, to another table called chat_brugere

But when i click the submit button, it posts “Resource id #7”, instead of the selected value.

Here is my code:

<?php
@session_start();
header('Content-Type: text/html; charset=ISO-8859-1');
include('includes/config.php');
?>
		<link rel="stylesheet" type="text/css" href="css/chat.css" />
<div id="sidebar_header">Garderobe</div>
<div id="sidebar_content">
	<p style="display: inline;">Skid i havet.</p><br /><br />
	<select name="sko">
<?php

	if(isset($_SESSION['logget_ind']) && $_SESSION['logget_ind'] == true) {
		$getSko = mysql_query("SELECT `navn` FROM `chat_clothes` WHERE `ejer` = '".$_SESSION['brugernavn']."' AND `type` = 'sko'");

		
		while ($showSko = mysql_fetch_array($getSko)) {
			echo '<option id="sko" name="sko" style="width: 300px;">'.$showSko['navn'].'</option><br />'
			;
			}
	}
?>

</div>

			</select>
<?php
	if (isset($_POST['sko'])) {
		

						mysql_query("UPDATE chat_brugere SET shoes='".$getSko."' WHERE id='".$_SESSION['id']."'");

						echo 'sko er opdateret!';
				} else {
					echo '';
				}
			
			echo '
			<form action="nygad.php" method="POST">

				<div>
					<table>
					
						<tr>
							<td><center><input type="submit" name="sko" value="Opdater!" /></center></td>
						</tr>
					</table>
				</div>
			</form>
			';
		?>

Which version of PHP? Also, MySQL is not used and has not been used for years. At some point you should upgrade to MySQLi or even better PDO. Now, with that said…

You show a form. In that form is a table. In that table is an input for “sko”. That is it! Nothing else!
Therefore, you will never see anything else posted to the PHP code script. Your drop-down code is BEFORE the form exists. You should move your < form action=“nygad.php” method=“POST” > code up further before you create the other inputs. Remember, a “DROP-DOWN” or “SELECT” is an input area of a form. If you do not place it inside the form, the values will never be posted.

Hope this helps!

Sponsor our Newsletter | Privacy Policy | Terms of Service