PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Oct 22, 2020 4:12 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Fri Nov 21, 2014 8:57 am 
Offline
Forum Commoner

Joined: Tue Nov 18, 2014 10:14 am
Posts: 25
hi,
I want to insert records to table .Before that need to check whether any records exists with the given id.

I am in a confusion on where to exactly write the code for this.

I have php page called sample.php, one another php page to write all db related functions and lastly one more php page for dbconnecton
1)sample.php
2)query.php.
3)dbconnect.php.

How to write code for the existing record in table and after that insertion .
How to write code correctly....


Top
 Profile  
 
PostPosted: Fri Nov 21, 2014 9:40 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada
Do a SELECT COUNT(*) against the ID in question. If the result is 1, you're dealing with an update. If it's 0, you're dealing with an insert. If it's 2, well, that's probably bad.

_________________


Top
 Profile  
 
PostPosted: Fri Nov 21, 2014 10:14 am 
Offline
Forum Commoner

Joined: Tue Nov 18, 2014 10:14 am
Posts: 25
Yes...I know the code for checking duplicate entries...Can i write queries for both checking existing code and inserting code within one fution?

Also I wanted to insert multiple records...Means an array of records .I need to check for already existing record and after all insertion or cheching I want to display one message to user that which records already exists....is it possible?


Top
 Profile  
 
PostPosted: Fri Nov 21, 2014 10:58 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada

_________________


Top
 Profile  
 
PostPosted: Sun Nov 23, 2014 2:25 pm 
Offline
Forum Commoner

Joined: Tue Nov 18, 2014 10:14 am
Posts: 25
O.k thank you.its working


Top
 Profile  
 
PostPosted: Thu Nov 27, 2014 10:20 am 
Offline
Forum Newbie

Joined: Thu Nov 27, 2014 10:03 am
Posts: 2
Refer
INSERT INTO TABLE (VALUES) WHERE ID NOT IN (SELECT ID FROM TABLE)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group