PHP - Update record - list/menu issues

  • argrafic
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Dec 14, 2007
  • Posts: 53
  • Status: Offline

Post May 6th, 2008, 9:12 am

Hello all.

I have the insert form that has 3 list/menus.

When I want to update a record I gather all the information and show it with a form.

My problem is with the values the list/menus have, because so far they appear with the default value which if the user doesn't see might overwrite withouth their knowledge the wrong value.

How can I get the list/menu to match the value saved in the database?

Thanks!
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 6th, 2008, 9:12 am

  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7134
  • Loc: Ozzuland
  • Status: Offline

Post May 6th, 2008, 4:08 pm

You would need some SQL to do that. Here is a very small example of such thing.
PHP Code: [ Download ] [ Select ]
<?php
$value = "1";
 
$host = "localhost";
$user = "user";
$pass = "myPass";
$dbname = "dbname";
 
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
 
$sql = "SELECT fieldName FROM table";
$process = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($process);
$value2 = $row['fieldName'];
mysql_close();
if($value == $value2) {
 echo "The values matched.<br />\n";
} else {
 echo "The values didn't match.<br />\n";
}
?>
  1. <?php
  2. $value = "1";
  3.  
  4. $host = "localhost";
  5. $user = "user";
  6. $pass = "myPass";
  7. $dbname = "dbname";
  8.  
  9. mysql_connect($host,$user,$pass) or die(mysql_error());
  10. mysql_select_db($dbname) or die(mysql_error());
  11.  
  12. $sql = "SELECT fieldName FROM table";
  13. $process = mysql_query($sql) or die(mysql_error());
  14. $row = mysql_fetch_assoc($process);
  15. $value2 = $row['fieldName'];
  16. mysql_close();
  17. if($value == $value2) {
  18.  echo "The values matched.<br />\n";
  19. } else {
  20.  echo "The values didn't match.<br />\n";
  21. }
  22. ?>
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.
  • argrafic
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Dec 14, 2007
  • Posts: 53
  • Status: Offline

Post May 7th, 2008, 11:39 am

thanks, so i suppose it's a match for each of the dropdowns i have?
  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7134
  • Loc: Ozzuland
  • Status: Offline

Post May 7th, 2008, 1:32 pm

Yeah I guess... I suppose you know how to take it from here... correct?
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.
  • argrafic
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Dec 14, 2007
  • Posts: 53
  • Status: Offline

Post May 8th, 2008, 8:08 am

yeah, i have an idea, i'll try it and tell you how it went. thanks!!
  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7134
  • Loc: Ozzuland
  • Status: Offline

Post May 8th, 2008, 8:49 am

Alright. Good :D
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.
  • argrafic
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Dec 14, 2007
  • Posts: 53
  • Status: Offline

Post May 9th, 2008, 11:35 am

it worked!!! thanks Bogey, you've been a lot of help lately!!! God bless!!!!
  • Bogey
  • Disturbed
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 7134
  • Loc: Ozzuland
  • Status: Offline

Post May 9th, 2008, 2:13 pm

argrafic wrote:
it worked!!! thanks Bogey, you've been a lot of help lately!!! God bless!!!!

Thanks :) Glad it worked
Learn PHP | I got 10 PHP tutorials! Check them out!
Dreamtale - Farewell
Just a note... I've giving up on web development and that stuff... Just lost all interest in it.

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: planetsap and 338 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.