drop down table data not going into table

using data from DB for form to re-update

Page 1 of 1

11 Replies - 1056 Views - Last Post: 18 January 2010 - 03:47 PM Rate Topic: -----

#1 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

drop down table data not going into table

Posted 14 January 2010 - 01:07 PM

Hey all, my problem is when i go to update the data any data that i send over which is from a drop down box (form), it for some reason does not update it. However if i update data that is inputted it updates fine.

I've checked to see if the data is actually sent to the next page also and that it does so I'm usure why it does not work. I've checked to make sure all the rows are the same but still can't find anything

first page:
<select name="rankname">
		 
		 <?
		 $rankq = 'SELECT * FROM rank ORDER BY rankid ASC';
		 $rankquery = mysql_query($rankq);
		 while($rows = mysql_fetch_array($rankquery)){
			 
			 $rankid = $rows['rankid'];
			 $rankchoice = $rows['rank'];
			 
				echo'<option value='.$rankchoice.'>'.$rankchoice.'</option>';
				}?>
				</select>	



second page:

require ("connection.php");
require ("session.php");


$updaterank = 'UPDATE user set rank = '.$_POST['rankname'].' WHERE userid = '.$_SESSION['userid'].'';
$rankres = mysql_query($updaterank);



Database look:

rank varchar(20) latin1_general_ci No

This post has been edited by Decypher: 14 January 2010 - 06:00 PM


Is This A Good Question/Topic? 0
  • +

Replies To: drop down table data not going into table

#2 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: drop down table data not going into table

Posted 14 January 2010 - 01:31 PM

View PostDecypher, on 14 Jan, 2010 - 12:07 PM, said:

Hey all, my problem is when i go to update the data any data that i send over which is from a drop down box (form), it for some reason does not update it. However if i update data that is inputted it updates fine.

I've checked to see if the data is actually sent to the next page also and that it does so I'm usure why it does not work. I've checked to make sure all the rows are the same but still can't find anything

first page:
<select name="rank">
		 
		 <?
		 $rankq = 'SELECT * FROM rank ORDER BY rankid ASC';
		 $rankquery = mysql_query($rankq);
		 while($rows = mysql_fetch_array($rankquery)){
			 
			 $rankid = $rows['rankid'];
			 $rankchoice = $rows['rank'];
			 
				echo'<option value='.$rankchoice.'>'.$rankchoice.'</option>';
				}?>
				</select>	



second page:
$rank = $_POST['rank'];

echo $rank;

$updaterank = 'UPDATE user set rank = '.$rank.' WHERE userid = '.$_SESSION['userid'].'';
$rankres = mysql_query($updaterank);




i take it your staring the session on top of both pages ?

There is no connect be for the mysql



mysql_connect("localhost", "username", "pass") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());



This post has been edited by nick1200: 14 January 2010 - 01:33 PM

Was This Post Helpful? 0
  • +
  • -

#3 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: drop down table data not going into table

Posted 14 January 2010 - 01:59 PM

there is a session and a connection as like i've said if the data is inputted it will update, it's only if the data comes from a drop down box like above
Was This Post Helpful? 0
  • +
  • -

#4 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: drop down table data not going into table

Posted 14 January 2010 - 06:02 PM

ok added the structure of the database too incase that will help but I'm still confused on why it won't update the data either though the data is being sent across to the next page...

I guess I'm right in sayin it has something to do with the update statement?

But if that is the case why does the same statement work for other pieces of data?
Was This Post Helpful? 0
  • +
  • -

#5 thinspirit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 12-January 10

Re: drop down table data not going into table

Posted 14 January 2010 - 11:34 PM

Try adding this to your update query and see what it says:

$rankres = mysql_query($updaterank) or die(mysql_error());



If it presents an error, it should help to lead you to a solution.
Was This Post Helpful? 0
  • +
  • -

#6 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: drop down table data not going into table

Posted 15 January 2010 - 07:59 AM

yeah it comes up with that error

so i take it it's something wrong with the previous line?
Was This Post Helpful? 0
  • +
  • -

#7 thinspirit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 12-January 10

Re: drop down table data not going into table

Posted 15 January 2010 - 11:16 AM

what does the error say?
Was This Post Helpful? 0
  • +
  • -

#8 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: drop down table data not going into table

Posted 16 January 2010 - 08:34 AM

Unknown column 'Hitman' in 'field list'

that's the error I gain but shouldn't the data be inputted for that column and not the column name changed?

'UPDATE user set rank = '.$_POST['rankname'].' WHERE userid = '.$_SESSION['userid'].'';



which is what i don't get...user is the table, rank is the field that is being changed and rankname(Hitman) is the variable that is ment to change it :S

This post has been edited by Decypher: 16 January 2010 - 08:48 AM

Was This Post Helpful? 0
  • +
  • -

#9 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: drop down table data not going into table

Posted 18 January 2010 - 11:05 AM

any ideas?
Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: drop down table data not going into table

Posted 18 January 2010 - 11:37 AM

How about enclosing the rank in quotes within the update? If it's a string column, you need to do that.
Was This Post Helpful? 1
  • +
  • -

#11 xerxes333  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 504
  • Joined: 05-July 07

Re: drop down table data not going into table

Posted 18 January 2010 - 11:44 AM

Have you tried (as JOAT suggested)
$updaterank = "UPDATE user set rank = '".$_POST['rankname']."' WHERE userid = '".$_SESSION['userid']."'";

Was This Post Helpful? 1
  • +
  • -

#12 Decypher  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 400
  • Joined: 28-June 08

Re: drop down table data not going into table

Posted 18 January 2010 - 03:47 PM

yeah that works :)

Thanks alot jack and xerxes.

Just a quick question...How come for input boxes you can get away with singular quotations but when I've used select boxes it won't work?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1