Jump to content

How do i check if a value is already in a mysql table ?


jd2007

Recommended Posts

This is good for login scripts too

<?php
$q = "select `id` from table where Username = '$username'";
$result = mysql_query($q) or die(mysql_error());
$rCount = mysql_num_rows($result);
if($rCount >0){
//There is an entry for it
}
else{
//There is not an entry for it
?>

<?php

$q = "select `id` from table where Username = '$username'";

$result = mysql_query($q) or die(mysql_error());

$rCount = mysql_num_rows($result);

if($rCount >0){

//There is an entry for it

}

else{

//There is not an entry for it

}

?>

 

This is one idea.The another idea also works:

 

if($result)

{

//for presence of data

}

else

{

//for absence of data

}

Archived

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

×
×
  • Create New...

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.