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
Share on other sites

After a lot of fiddling and a lot of frustration i sorted out the problem. 

I did echo's to check the variables and i had one of them off, which was throwing the whole script off on a crazy error message frenzy :)

Thanks for advice anyway :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.