Printing some results on screen when submit is selected

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

You Can Get The Org_id With This SQL Command

Code: Select all

select `org_id` from `table_name` where `person_id` = '$person_id' && `orgname` = '$orgname' && `web_url` = '$web_url' && `notes` = '$notes'
if And Only If
atleast one Of The person_id, orgname, web_url, notes is/are Unique Fields
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

My table is simple:

org_name varchar (100), web_url varchar (200), notes varchar (300),person_id int(11), org_id int(11) auto_increment

Are you saying replace:

Code: Select all

$sql = "INSERT INTO organisations (org_id,person_id, orgname, web_url, notes ) VALUES ('$org_id','$person_id','$orgname','$web_url', '$notes')";
With

Code: Select all

SELECT `org_id` FROM `table_name` WHERE `person_id` = '$person_id' && `orgname` = '$orgname' && `web_url` = '$web_url' && `notes` = '$notes'
That doesnt make sense my one is an insert statement your one is a select statement?

Please explain?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

He's saying after the insert select the last inserted record. But if the field you want to fetch from the last insert is an autoincrement field then mysql_insert_id() will have already grabbed it.
Post Reply