Icewolf Posted October 10, 2013 Share Posted October 10, 2013 Hi I am having a little problem trying to figure out how to create two text boxes on this form so the user can add values to the max points or points earned. Then I would like once the update happens that it shows the new values from the database. The update query is based on the Member and Category. I was thinking about adding two text boxes in the form where the dropdown is but I am not sure how I would reference those boxes in my update query. <?php //create_cat.php include 'connect.php'; include 'header.php'; include 'timeout.php'; echo '<h2>Review Member Rewards</h2>'; if($_SESSION['signed_in'] == false | $_SESSION['user_level'] != 1 ) { //the user is not an admin echo 'Sorry, you do not have sufficient rights to access this page.'; } else { $sql = "Select user_name from users"; $result = mysql_query($sql); if(!$result) { //the query failed, uh-oh :-( echo 'Error while selecting from database. Please try again later.'; } else { $dropdown = "<select name='mem'>"; while($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n<option value='{$row['user_name']}'>{$row['user_name']}</option>"; } $dropdown .= "\r\n</select>"; echo ' <form action="" method="post">' . $dropdown . ' <textpoint name="max_point_cont"></textpoint><br /><br /> <textpoint name="points_earn_cont"></textpoint><br /><br /> <input type="submit" value="Get Results"> </form>'; } // only qeury the rewards table when the form above has been submitted if(isset($_POST['mem'])) { $post_sql = "select member, cat_name, point_earn, max_point from rewards where member = '" . mysql_real_escape_string($_POST['mem']) . "'"; $result_post = mysql_query($post_sql); if(!$result_post) { //the query failed, uh-oh :-( echo 'Error while selecting rewards from database. Please try again later.'; } else { echo '<table border="1"> <tr> <th>Member</th> <th>Category</th> <th>Points Earned</th> <th>Max Points</th> </tr>'; while($row = mysql_fetch_assoc($result_post)) { echo '<tr>'; echo '<td>' . $row['member'] . '</td>'; echo '<td>' . $row['cat_name'] . '</td>'; echo '<td>'. $row['point_earn']. '</td>'; echo '<td>' . $row['max_point']. '</td>'; echo '</tr>'; } echo '</table>'; } } } Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted October 10, 2013 Solution Share Posted October 10, 2013 Replace <textpoint name="max_point_cont"></textpoint><br /><br /> <textpoint name="points_earn_cont"></textpoint><br /><br />with <input type="text" name="max_point_cont" value="" /> <input type="text" name="points_earn_cont" value="" /> The values will be in $_POST['max_point_cont'] and $_POST['points_earn_cont'] Quote Link to comment Share on other sites More sharing options...
Icewolf Posted October 11, 2013 Author Share Posted October 11, 2013 Thanks for the help with the text boxes however I need to use to drop downs to do the update query. I can only get one to work. I am sure that it is wrong I am just taking a guess how it should be. { $dropdown = "<select name='mem'>"; $catdropdown = "<select name='catdp'>"; while($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n<option value='{$row['user_name']}'>{$row['user_name']}</option>"; $catdropdown .="\r\n<option value = '{$row['cat_name']} '>{$row['cat_name']}</option>"; } $dropdown .= "\r\n</select>"; $catdropdown .="\r\n</select>"; echo ' <form action="" method="post">' . $dropdown.' '. $catdropdown. ' <input type="text" name="max_point_cont" value="" /> <input type="text" name="points_earn_cont" value="" /> <input type="submit" value="Get Results"> </form>'; } Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 11, 2013 Share Posted October 11, 2013 (edited) I can only get one to work. What do you mean by that? Can only get one drop down menu to display? The code that generates the dropdown menus looks ok. How are you getting the user_name and the cat_name fields from the database? Edited October 11, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Icewolf Posted October 11, 2013 Author Share Posted October 11, 2013 The code in my first question has the select query. Yes only one has data. The dropdown is there just nothing in it. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 11, 2013 Share Posted October 11, 2013 This query you're referring to? $sql = "Select user_name from users"; $result = mysql_query($sql); If its then you're not selecting the cat_name from the database, you're only getting the user_name from the users table. Therefore the second drop down will be empty, In what table is the field the cat_name from? Quote Link to comment Share on other sites More sharing options...
Icewolf Posted October 14, 2013 Author Share Posted October 14, 2013 Sorry I am sorry I forgot I changed the sql statement. Here is the new code. $sql = "select member, cat_name from rewards, users where member = user_name"; 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.