Sending data to mySQL using drop down menu

Hi,

I need to be able to select a certain user from a drop down menu and then send some data for that user for example choose a user from a menu and fill out a comment box then send it back to the database so that user can see the comment after they log in.

I have the code already to show the users emails in my php drop down menu

[php]

<?php $sql = "SELECT * FROM users WHERE staff_mem = '".$_SESSION['email']."'"; $result = mysql_query($sql); echo "<select name = 'name'"; while($row = mysql_fetch_array($result)){ echo "" . $row['email'] . ""; } echo ""; ?>

[/php]

I’m guessing that the selected email will need to be assigned to a variable then the comment sent to that variable.

Could anyone lend some advice please?

thanks in advance.

usually you would set the value to the id of the user, so something like this

[php] echo “<select name = ‘to’”;

 while($row = mysql_fetch_array($result)){
    echo "<option value='" . $row['id'] . "'>" . $row['firstname'] . " " . $row['lastname'] . "</option>";
 }
   echo "</select>";[php]

Then submit the form to some file where you get the comment and the “to id”

[php]if (isset($_POST[‘to’]) && isset($_POST[‘comment’]) {
$db->query(‘INSERT INTO comments SET to = ?, text = ?’);
$db->setParams… etc
}
[/php]

Cheers I’ll run that through now.

I get the comment from a comment box in html and it needs to be sent to the selected email from the dropdown menu.

Thanks.

I’m getting this error

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\view_registered_students.php on line 65

it’s line 3:

while($row = mysql_fetch_array($result)){

Can you tell me why this isn’t working?

[php]

			<?php
				 $sql = "SELECT * FROM users WHERE user_type = 3";
				 $result = mysql_query($sql);
				 echo "<select name = 'to'";
               
			   while($row = mysql_fetch_array($result)){
					echo "<option value='" . $row['user_ID'] . "'>" . $row['email'] . "</option>";
			   }
					echo "</select>";
						
				if (isset($_POST['to']) && isset($_POST['comment'])) {
					$db = "INSERT INTO users SET project_results = '".$_POST['grade']."' WHERE email = '".$_POST['to']."'";
				
				}
			?>

[/php]

What I need to do is select a student from a drop down menu and send their grade for an exam to the database. I can’t seem to get this to work. Their identified by their email.

It’s being sent through html

[php]

Grade:
			<tr>
				<td colspan="2"><input type="submit" name="submit" value="send" /></td>
			</tr>	

			</td>

[/php]

Thanks in advance.

Sponsor our Newsletter | Privacy Policy | Terms of Service