Goose87 Posted July 28, 2007 Share Posted July 28, 2007 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**"); ?> Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 28, 2007 Share Posted July 28, 2007 Well, you dont appear to define $row. I would suggest that is your problem. Also, for future reference, try debugging your queries when something isn't working, and don't use error suppression(@) when there is a problem. Quote Link to comment Share on other sites More sharing options...
Goose87 Posted July 28, 2007 Author Share Posted July 28, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.