954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

check

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.

kishou
Junior Poster in Training
52 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

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.

MickRip
Newbie Poster
7 posts since Dec 2007
Reputation Points: 10
Solved Threads: 3
 

select * from table_name


this lis all the values in table .

g0 to w3schools.com this is very usefull site for bignner

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 

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.

kishou
Junior Poster in Training
52 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

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?

kishou
Junior Poster in Training
52 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

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...";
}

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 

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?

$res=mysql_query("SELECT * FROM registered_members=$_POST['Username']");
if (mysql_num_rows($res)>0)
{
echo "Username is already taken!";
}
else
{
kishou
Junior Poster in Training
52 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

yes this is the correct syntax

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 

ok then i get this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource.

kishou
Junior Poster in Training
52 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

thanks dude! So then it would look like this?

$res=mysql_query("SELECT * FROM registered_members=$_POST['Username']");
if (mysql_num_rows($res)>0)
{
echo "Username is already taken!";
}
else
{

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']");

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 
Thats because, you have your query wrong. Its missing a where clause. $res=mysql_query("SELECT * FROM registered_members where username=$_POST['Username']");


Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource. still same error

kishou
Junior Poster in Training
52 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

Can you show us your script ?

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

still same err.

kishou
Junior Poster in Training
52 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 
yea dont copy it though. please.

Dude! I can write my own script.. :D Anyway, here is the error.. $res=mysql_query("SELECT * FROM mailing_list where Email=$_POST[email]");

This should have been $res=mysql_query("SELECT * FROM mailing_list where Email='".$_POST[email]."'");

You should put your variable name in single quote if its a string.

Cheers,
Nav

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

Dude! I can write my own script.. :D Anyway, here is the error.. $res=mysql_query("SELECT * FROM mailing_list where Email=$_POST[email]");

This should have been $res=mysql_query("SELECT * FROM mailing_list where Email='".$_POST[email]."'");

You should put your variable name in single quote if its a string.

Cheers, Nav


still same error. :( and for copying i mean everyone in general not just you. and yea i know you can make a script just like that.

kishou
Junior Poster in Training
52 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

Ok. I see the error. Its your select_db string. mysql_select_db("kishou_website", $connect);/ Its after your query. Put it above the query. :) This should fix it.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 
Ok. I see the error. Its your select_db string. mysql_select_db("kishou_website", $connect);/ Its after your query. Put it above the query. :) This should fix it.


dude thanks soo much! im a really big noob as you can see! you're like my savior! :D thanks!

kishou
Junior Poster in Training
52 posts since Dec 2007
Reputation Points: 10
Solved Threads: 1
 

:) you are welcome!

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You