943,725 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 710
  • MySQL RSS
Apr 22nd, 2009
0

conditional execution of Sql query thru PHP

Expand Post »
Hi.

I am working on a php-mysql project.

My table contains a field called "ID", which i have declared as teh PRIMARY key.

but what i want is, that when the user tries ot insert record B into the table, an [B]ERROR message[/B] should be displayed, showing that a record already exists with primary key =100....

I tried doing this as follows:

if('$id' in (mysql_query("Select ID from client") ))
{
echo "ERROR!";
}

else
{
run the query...
}


someone please help...
thx...
Reputation Points: 10
Solved Threads: 0
Light Poster
akshit is offline Offline
46 posts
since Jun 2008
Apr 22nd, 2009
0

Re: conditional execution of Sql query thru PHP

php Syntax (Toggle Plain Text)
  1. $query = "select * from table where id = 100";
  2. $result = mysql_query($query);
  3. if(mysql_num_rows($result) > 0 ) {
  4. // record already exists
  5. } else {
  6. // record doesn't exist, so insert..
  7. }
Use [code] tags to wrap your code next time.
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Apr 22nd, 2009
0

Re: conditional execution of Sql query thru PHP

hey thx.... i'll try the code, and get bak 2 u!!
Reputation Points: 10
Solved Threads: 0
Light Poster
akshit is offline Offline
46 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: problem with project in mysql
Next Thread in MySQL Forum Timeline: incremental backup





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC