check

Thread Solved

Join Date: Dec 2007
Posts: 52
Reputation: kishou is an unknown quantity at this point 
Solved Threads: 1
kishou kishou is offline Offline
Junior Poster in Training

check

 
0
  #1
Dec 17th, 2007
how do i check if a value is in my table?
like this:
INSERT INTO table_name (column1, column2,...)
VALUES (value1, value2,....)
and check if those values are in the table.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 7
Reputation: MickRip is an unknown quantity at this point 
Solved Threads: 3
MickRip's Avatar
MickRip MickRip is offline Offline
Newbie Poster

Re: check

 
0
  #2
Dec 18th, 2007
You need to do a select query..

select * from table_name where column1="value1" and column2="value2" ...

The answers to these sort of questions are in php/mysql tutorials all over the internet.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 197
Reputation: vssp has a little shameless behaviour in the past 
Solved Threads: 5
vssp vssp is offline Offline
Junior Poster

Re: check

 
0
  #3
Dec 18th, 2007
select * from table_name


this lis all the values in table .

g0 to w3schools.com this is very usefull site for bignner
Thanks
VSSP
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 52
Reputation: kishou is an unknown quantity at this point 
Solved Threads: 1
kishou kishou is offline Offline
Junior Poster in Training

Re: check

 
0
  #4
Dec 18th, 2007
Originally Posted by MickRip View Post
You need to do a select query..

select * from table_name where column1="value1" and column2="value2" ...

The answers to these sort of questions are in php/mysql tutorials all over the internet.
thanks but what im trying to do is like if the thing someone put in a form is already in the Table.
so what would it be like?
i was thinking it would be like this
elseif VALUES ('$_POST[Username]'==$_POST[Username])? this is just a guess.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 52
Reputation: kishou is an unknown quantity at this point 
Solved Threads: 1
kishou kishou is offline Offline
Junior Poster in Training

Re: check

 
0
  #5
Dec 18th, 2007
Originally Posted by vssp View Post
select * from table_name


this lis all the values in table .

g0 to w3schools.com this is very usefull site for bignner
yea already went there but thanks! if select *from Users then wat?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 197
Reputation: vssp has a little shameless behaviour in the past 
Solved Threads: 5
vssp vssp is offline Offline
Junior Poster

Re: check

 
1
  #6
Dec 18th, 2007
use this command

$res=mysql_query("select * from table name where value1= $_post['value1']");

if (mysql_num_rows($res)>0)

{
$ans="value already exist";

}
else
{
$ans="....insert command...";
}
Thanks
VSSP
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 52
Reputation: kishou is an unknown quantity at this point 
Solved Threads: 1
kishou kishou is offline Offline
Junior Poster in Training

Re: check

 
0
  #7
Dec 18th, 2007
Originally Posted by vssp View Post
use this command

$res=mysql_query("select * from table name where value1= $_post['value1']");

if (mysql_num_rows($res)>0)

{
$ans="value already exist";

}
else
{
$ans="....insert command...";
}
thanks dude! So then it would look like this?
  1. $res=mysql_query("SELECT * FROM registered_members=$_POST['Username']");
  2. if (mysql_num_rows($res)>0)
  3. {
  4. echo "Username is already taken!";
  5. }
  6. else
  7. {
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 197
Reputation: vssp has a little shameless behaviour in the past 
Solved Threads: 5
vssp vssp is offline Offline
Junior Poster

Re: check

 
0
  #8
Dec 18th, 2007
yes this is the correct syntax
Thanks
VSSP
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 52
Reputation: kishou is an unknown quantity at this point 
Solved Threads: 1
kishou kishou is offline Offline
Junior Poster in Training

Re: check

 
0
  #9
Dec 18th, 2007
ok then i get this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,761
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: check

 
0
  #10
Dec 19th, 2007
Originally Posted by kishou View Post
thanks dude! So then it would look like this?
  1. $res=mysql_query("SELECT * FROM registered_members=$_POST['Username']");
  2. if (mysql_num_rows($res)>0)
  3. {
  4. echo "Username is already taken!";
  5. }
  6. else
  7. {
ok then i get this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource.
Thats because, you have your query wrong. Its missing a where clause.
$res=mysql_query("SELECT * FROM registered_members where username=$_POST['Username']");
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 1801 | Replies: 17
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC