php - lastInsertId get from different function -



php - lastInsertId get from different function -

i have form, wich sends info database (when filled in)

form function:

function train_add() { $sql = "insert train_information " . "(train_id, image, train_name, tare_weight, number_of_bogies, number_of_axles, wheel_diameter_min, wheel_diameter_max)" . "values (train_id, :image, :train_name, :tare_weight, :number_of_bogies, :number_of_axles, :wheel_diameter_min, :wheel_diameter_max) "; $sth = $this->pdo->prepare($sql); $sth->bindparam(':image', $_post['image'], pdo::param_str); $sth->bindparam(':train_name', $_post['train_name'], pdo::param_str); $sth->bindparam(':tare_weight', $_post['tare_weight'], pdo::param_str); $sth->bindparam(':number_of_bogies', $_post['number_of_bogies'], pdo::param_str); $sth->bindparam(':number_of_axles', $_post['number_of_axles'], pdo::param_str); $sth->bindparam(':wheel_diameter_min', $_post['wheel_diameter_min'], pdo::param_str); $sth->bindparam(':wheel_diameter_max', $_post['wheel_diameter_max'], pdo::param_str); $sth->execute(); homecoming $this->pdo->lastinsertid('train_id'); }

right. when form filled in, send database (works).

the user redirected in 10 seconds (did myself see if errors come up).

<?php //train info send database, , selects id of added train// $add_train = $database->train_add(); ?> <meta http-equiv="refresh" content="10;url=http://localhost:8080/show_axle_table.php?train_id="<?php ['$id'] ?> >

show_axle_table.php:

<?php $show_axle = $database->axles(); ?> <div id="train_select_table"> <table> <tr> <th>train id</th> <th>number of bogies</th> <th>number of axles</th> </tr> <div id="looprow"> <?php foreach($show_axle $res){ //loop trough results, generate tablerow every time ?> <tr> <?php echo "<td>" . $res['train_id'] . "</td>"; echo "<td>" . $res['number_of_bogies'] . "</td>"; echo "<td>" . $res['number_of_axles'] . "</td>"; ?> </tr> <?php } ?> </div> </table> </div>

and function:

function axles(){ $id2 = $this->train_add($id); $sql = "select * train_information train_id = '$id2'"; $sth = $this->pdo->prepare($sql); $sth->bindparam(":id2", $_get["train_id"], pdo::param_str); $sth->execute(); homecoming $sth->fetchall(); }

now table shows me id of train. adds 1 else empty. example: user fills in form. sends database (train_add) gets , id of 1 , done.

then page redirects show_axle_table.php. function should lastly inserted id. shows me id of 2.

also want id shown in top of page like:

show_axle_table.php?train_id="<?php ['$id'] ?>

but right shows nothing. (train_id=)

update this:

<?php //train info send database, , selects id of added train// if (!(isset($_get['train_id]) && $_get['train_id'])) { $add_train = $database->train_add(); } ?> <meta http-equiv="refresh" content="10;url=http://localhost:8080/show_axle_table.php?train_id="<?php echo $add_train; ?> > <?php $show_axle = $database->axles($_get['train_id']); ?> <div id="train_select_table"> <table> <tr> <th>train id</th> <th>number of bogies</th> <th>number of axles</th> </tr> <div id="looprow"> <?php foreach($show_axle $res){ //loop trough results, generate tablerow every time ?> <tr> <?php echo "<td>" . $res['train_id'] . "</td>"; echo "<td>" . $res['number_of_bogies'] . "</td>"; echo "<td>" . $res['number_of_axles'] . "</td>"; ?> </tr> <?php } ?> </div> </table> </div>

and function as

function axles($id){ $sql = "select * train_information train_id = '$id'"; $sth = $this->pdo->prepare($sql); $sth->bindparam(":id2", $_get["train_id"], pdo::param_str); $sth->execute(); homecoming $sth->fetchall(); }

php oop pdo mysqli phpmyadmin

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -