Jump to content


Photo

changing database field


  • Please log in to reply
6 replies to this topic

#1 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 07 March 2006 - 03:27 PM

:) hi again guys.
I`m stuck again in something.I have a database named championships which contains 2 fields.1 is 'username' and second is 'status'.primary key is 'username' field.
I connect to the database with no problems,and now,the question is :
How do I search into the database for a specific entry into the 'username' field and after I find the entry how do I change the 'status' entry for the same row from its current content to a new content.I hope I was clear enough.
Thanks for your time..
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 07 March 2006 - 03:39 PM


really, if you're simply updating the status on one user, you can do it all with one UPDATE statement. for instance, if you have a username called "abc123", and you want to change his status to "inactive", you'd simply have to run the following SQL query:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']UPDATE[/span] tableName SET status = 'inactive' WHERE username = 'abc123';
[!--sql2--][/div][!--sql3--]
hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 07 March 2006 - 03:47 PM

i know that statement,but I don`t know how to write it exacly.
here is what i wrote:
UPDATE register SET status = 'inactive' WHERE username = 'a';
register is the tablename from database championships and inactive is the new value of the field 'status' of the username 'a';
what is wrong?:( i need it exacly
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 07 March 2006 - 04:24 PM

[!--quoteo(post=352542:date=Mar 7 2006, 10:47 AM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 7 2006, 10:47 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
i know that statement,but I don`t know how to write it exacly.
here is what i wrote:
UPDATE register SET status = 'inactive' WHERE username = 'a';
register is the tablename from database championships and inactive is the new value of the field 'status' of the username 'a';
what is wrong?:( i need it exacly
[/quote]

that is exactly how you would write it. you need to check on a few things, though... to match, your username MUST be only a lowercase 'a'. it will run an EXACT match when you use the '=' operator. have you made your database connection and all already? make sure you have an active DB connection open before you run your query, too. also, for one more piece of trouble shooting, you can run a mysql_error() to see what the issue is:'
<?php
// make your database connection here
$sql = "UPDATE register SET status = 'inactive' WHERE username = 'a'";
mysql_query($sql) or die(mysql_error());
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 alarik149

alarik149
  • Members
  • PipPipPip
  • Advanced Member
  • 60 posts

Posted 07 March 2006 - 04:29 PM

<?php

$db = mysql_connect('host', 'championships', 'passwd');
mysql_select_db('championships', $db);
UPDATE register SET status = 'inactive' WHERE username = 'a';

?>
that is the exact script.
the database connection is good because I connected before,it`s the same connection type i used to add information in the database.
Tired of math homework ? Just visit http://www.solvemymath.com for a free online math solver and calculator.
Videochat bucuresti studio -> http://www.GirlAddicts.com
About the adult video chat business -> www.girlplan.com

#6 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 07 March 2006 - 04:51 PM

[!--quoteo(post=352551:date=Mar 7 2006, 11:29 AM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 7 2006, 11:29 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<?php

$db = mysql_connect('host', 'championships', 'passwd');
mysql_select_db('championships', $db);
UPDATE register SET status = 'inactive' WHERE username = 'a';

?>
that is the exact script.
the database connection is good because I connected before,it`s the same connection type i used to add information in the database.
[/quote]

therein lies your problem. you're not actually querying the database, you're simply typing your query right into your php code. did you read my post above thoroughly? i showed you how to run the query in it. try this instead of what you have, though:
$db = mysql_connect('host', 'championships', 'passwd');
mysql_select_db('championships', $db);
mysql_query("UPDATE register SET status = 'inactive' WHERE username = 'a'");

you must call mysql_query() to query your database.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#7 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 07 March 2006 - 06:02 PM

[!--quoteo(post=352542:date=Mar 7 2006, 10:47 AM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 7 2006, 10:47 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
what is wrong?:( i need it exacly
[/quote]

also, when possible, try to experiment and learn some things by trial and error. if you insist on someone writing your code for you, you won't retain as much ;-).

good luck!
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users