sql - Pass value from one PHP file to another -
i'm trying pass value input box on 1 php page (itinerary.php) php page ('submit.php') can, there, saved database. can't quite figure out how across. i've tried using can see code below, using statement receive , acknowledge value same page 'submit'. guess overcomplicating it, knowledge of php still pretty limited @ stage ideas appreciated!
this extract itinerary.php file (it sits within bootstrap/html framework. note entry contains input box sequence number).
<h3><br>your itinerary</h3> <?php //display contents of itinerary if(!empty($_session['itinerary'])){ //retrieve details of each location in array database $query = "select * locations loc_id in ("; foreach ($_session['itinerary'] $loc_id=>$value) {$query.=$loc_id.',';} $query = substr($query, 0, -1).')order loc_id asc'; $result = mysqli_query($db, $query); echo'<table><tr><th colspan="5">locations in itinerary</th></tr>'; //display locations in array while ($row = mysqli_fetch_array($result, mysqli_assoc)){ $loc_id = $row['loc_id']; echo"<br><td>{$row['loc_name']}</td></tr><br> <td>{$row['loc_desc']}</td> <td><p>seq. no</p><input type=\"text\" size=\"3\" name=\"sequence\" value=????????>not sure add line retain info input</td> <td><a href=remove_loc.php?value=$loc_id>remove location</a><br></br></td> </tr><br></table>"; }//while print_r($_session); mysqli_close($db); }//if else {echo '<p><br>your itinerary empty.<br></p>';} echo '<br><p> <a href=submit.php?submit>save itinerary</a> <a href=clear_itin.php?clear>clear itinerary</a> <a href="user_home.php">your details</a> <a href="logout.php">logout</a> </p>'; ?>
and trying receive , use in sql command add database. (again, within bootstrap framework)you can ignore first sql insert statement passing other info in anyway..
<div class="row"> <div class="col-md-9"> <?php if (isset($_get['sequence'])){ $sequence = $_get['sequence']; }//if if (isset($_get['submit'])){ $query = "insert itineraries (user_id, date_created) values (".$_session['user_id'].", now())"; $result = mysqli_query($db, $query); $itinerary_id = mysqli_insert_id($db); $retrieve_locs = "select * locations loc_id in ("; foreach ($_session['itinerary'] $id=>$value) {$retrieve_locs.=$id.',';} $retrieve_locs = substr($retrieve_locs, 0, -1).')order loc_id asc'; $result = mysqli_query($db, $retrieve_locs); //store items in itin_locs db while ($row = mysqli_fetch_array ($result, mysqli_assoc)){ //this command have been trying use, commented out. second 1 below works fine, obv doesn't input sequence number. //$insert_locs = "insert itin_loc (itinerary_id, loc_id, sequenceno) values ($itinerary_id, ".$row['loc_id'].", $sequence)"; $insert_locs = "insert itin_loc (itinerary_id, loc_id) values ($itinerary_id, ".$row['loc_id'].")"; $insert_result = mysqli_query($db, $insert_locs); echo mysqli_error($db); if ($insert_result === false) { die("query failed!" . mysql_error() . $insert_locs);} }//while mysqli_close($db); echo"<p>your itinerary saved!. itinerary number #".$itinerary_id."</p><br>"; $_session['itinerary']= null; echo '<p> <a href="user_home.php">your details</a> <a href="logout.php">logout</a> </p>'; }//if else {echo '<p>your itinerary empty.<br></br></p>';} ?>
use form on html page hold input fields in table. instead of anchor "a" tag use submit button submit form other page. use thing like:
Comments
Post a Comment