Jump to content

Update Query


Go to solution Solved by Barand,

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

  • Solution

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

 

 

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

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.