note 93745 added to function.mysql-insert-id

From: Date: Fri, 25 Sep 2009 13:16:51 +0000
Subject: note 93745 added to function.mysql-insert-id
Groups: php.notes 
Request: Send a blank email to php-notes+get-161047@lists.php.net to get a copy of this message
I thought this would be relevant to all the people using mysqli and looking for the ID after INSERT command : <?php function insert_join($catid, $disc_id) { // insert a new item into the database $conn = db_connect(); // insert new item $demande = "insert into categories_disc values ('', '".$catid."', '".$disc_id."')"; $resultat = $conn->query($demande); if (!$resultat) { return false; } else { return $conn->insert_id; // function will now return the ID instead of true. } } ?> Then, on the other side, let us call this function as follows : <?php $cat_id = insert_join($catid, $disc_id); if($cat_id !== false) { echo "<p>Category stuff was added to the database as follows : <br>"; echo "<hr>ID de la category : ".$cat_id."</p><hr>"; } ?> ---- Server IP: 89.31.146.176 Probable Submitter: 89.225.211.211 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-insert-id.php Edit -- https://master.php.net/note/edit/93745 Del: integrated -- https://master.php.net/note/delete/93745/integrated Del: useless -- https://master.php.net/note/delete/93745/useless Del: bad code -- https://master.php.net/note/delete/93745/bad+code Del: spam -- https://master.php.net/note/delete/93745/spam Del: non-english -- https://master.php.net/note/delete/93745/non-english Del: in docs -- https://master.php.net/note/delete/93745/in+docs Del: other reasons-- https://master.php.net/note/delete/93745 Reject -- https://master.php.net/note/reject/93745 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161047) next »