Jump to content

Archived

This topic is now archived and is closed to further replies.

alarik149

changing database field

Recommended Posts

:) 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..

Share this post


Link to post
Share on other sites

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 [color=orange]=[/color] [color=red]'inactive'[/color] [color=green]WHERE[/color] username [color=orange]=[/color] [color=red]'abc123'[/color];
[!--sql2--][/div][!--sql3--]
hope this helps

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[!--quoteo(post=352542:date=Mar 7 2006, 10:47 AM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 7 2006, 10:47 AM) [snapback]352542[/snapback][/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:'
[code]
<?php
// make your database connection here
$sql = "UPDATE register SET status = 'inactive' WHERE username = 'a'";
mysql_query($sql) or die(mysql_error());
?>
[/code]

Share this post


Link to post
Share on other sites
<?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.

Share this post


Link to post
Share on other sites
[!--quoteo(post=352551:date=Mar 7 2006, 11:29 AM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 7 2006, 11:29 AM) [snapback]352551[/snapback][/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:
[code]
$db = mysql_connect('host', 'championships', 'passwd');
mysql_select_db('championships', $db);
mysql_query("UPDATE register SET status = 'inactive' WHERE username = 'a'");
[/code]

you must call mysql_query() to query your database.

Share this post


Link to post
Share on other sites
[!--quoteo(post=352542:date=Mar 7 2006, 10:47 AM:name=ADRlAN)--][div class=\'quotetop\']QUOTE(ADRlAN @ Mar 7 2006, 10:47 AM) [snapback]352542[/snapback][/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!

Share this post


Link to post
Share on other sites

×

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.