Jump to content

[SOLVED] getting data from drop down menus


Goose87

Recommended Posts

I have a drop down menu and I'm trying to find out which option they have pressed.  I need to use the $_POST method to do this. 

Below is what i've written so far, but it's showing every time the messages:

 

"You don't have enough points"    AND  "you gained blah blah exp"

 

I've blocked out some of the stuff that calls up files and stuff, just for security reasons :) hope you can help me!

 

<?php 

require("**header**");
$username=$_SESSION['username'];
$user_id=$_SESSION['user_id'];
require("**connect file**");

if(isset($_POST['submit'])){
if (empty($_POST['amount'])) {  
	$a = FALSE;
	echo '<p>You did not select an amount!</p>';
} else {
	$a = ($_POST['amount']);
}

if(empty($_POST['menu'])) {
	$t = FALSE;
	echo '<p>You did not select a type type!</p>';
} else {
	$t = ($_POST['menu']);
}


if ($a && $t) { // Everything is ok.

$result=@mysql_query("SELECT points, '$t' from users WHERE user_id='$user_id'");

if ($a > $row[0]) {
	echo '<p>You do not have that many points</p>';
} else {

$training_amount = $a;
$exp=$row[1];
}

$rand1=rand(1,3);
if($rand1==1){
	$exp_gained = ($a*65);
	$exp_for_user = $exp_gained/100;
	$new_exp = $exp + $exp_gained;
	echo "<p>Your learning was average, you earnt $exp_for_user exp!</p>";
	$resultx=@mysql_query("UPDATE users set('$t') values ('$new_exp');");
} elseif($rand1==2){
	$exp_gained = ($a*70);
	$exp_for_user = $exp_gained/100;
	$new_exp = $exp + $exp_gained;
	echo "<p>Your learning was good, you earnt $exp_for_user exp!</p>";
	$resultx=@mysql_query("UPDATE users set('$t') values ('$new_exp');");
} else {($rand1==3);
	$exp_gained = ($a*80);
	$exp_for_user = $exp_gained/100;
	$new_exp = $exp + $exp_gained;
	echo "<p>Your learning was superb!!  You earnt $exp_for_user exp!</p>";
	$resultx=@mysql_query("UPDATE users set('$t') values ('$new_exp');");
}
}
}
?>

<div align="center">
<form method="post" action="dtraining.php">
<input type="text" name="amount" size="5" maxlength="5" />
<select name="menu"><option value="NULL">Select:</option>
<option value="Option1">Option1</option>
<option value="Option2">Option2</option>
<option value="Optioon3">Option3</option>
<option value="Option4">Option4</option>
<input type="submit" name="submit" value="Train" /></div>

<?php 
require("**footer**");
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/62202-solved-getting-data-from-drop-down-menus/
Share on other sites

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.