Jump to content

Update Query


Icewolf

Recommended Posts

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>';
		}
		
	}
}
Link to comment
https://forums.phpfreaks.com/topic/282854-update-query/
Share on other sites

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']
Link to comment
https://forums.phpfreaks.com/topic/282854-update-query/#findComment-1453371
Share on other sites

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>';
	}
Link to comment
https://forums.phpfreaks.com/topic/282854-update-query/#findComment-1453495
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/282854-update-query/#findComment-1453556
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.