conditional execution of Sql query thru PHP

Reply

Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

conditional execution of Sql query thru PHP

 
0
  #1
Apr 22nd, 2009
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...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
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: conditional execution of Sql query thru PHP

 
0
  #2
Apr 22nd, 2009
  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.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 46
Reputation: akshit is an unknown quantity at this point 
Solved Threads: 0
akshit akshit is offline Offline
Light Poster

Re: conditional execution of Sql query thru PHP

 
0
  #3
Apr 22nd, 2009
hey thx.... i'll try the code, and get bak 2 u!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the MySQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC