OGBugsy Posted April 29, 2015 Share Posted April 29, 2015 Hi all, I have a form that submits data to a mysql db. It's working fine. What I am trying to do is output an html page (or possibly 2) that is propagated with the data that I just sent to the db. example: when I submit a new workorder, a page comes up with all the data i just submitted. so that can be printed as a "customer copy". and in a perfect world, another page comes up that is a material order form. That can be faxed to my vendor to order the materials for that job. Not looking to auto print or fax anything. I am just having trouble getting the data into my html page. Here is what I have, but sadly is not working. <?php $link = mysqli_connect("xxxx", "xxxx", "xxxx", "xxxx"); $sql = "SELECT customer FROM jobs WHERE id=6487"; echo $sql; mysqli_close($link); ?> I would like to use the data from the last id submitted and have tried several things like: WHERE id=mysqli::$insert_id and WHERE id=$insert_id with no luck. Here is a pic of the html form and the output i'm getting. Any help would be greatly appreciated. Thanks in advance. OGBugsy Quote Link to comment Share on other sites More sharing options...
Barand Posted April 29, 2015 Share Posted April 29, 2015 The last insert id is only available for the current connection. You need to get it and store it ($_SESSION) as soon as possible after the insert. When the script ends the connection closes automatically Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted April 29, 2015 Share Posted April 29, 2015 something worth considering may be, rather than going and getting the exact same info back out the database that you just put in there, check the query status of the insert and then recycle your current data in the event of a success. Quote Link to comment Share on other sites More sharing options...
Torrie Posted April 30, 2015 Share Posted April 30, 2015 You've got the first part correct. The next part should be the result. Here's your code, with the missing stuff put into it: <?php $link = mysqli_connect("xxxx", "xxxx", "xxxx", "xxxx"); $sql = "SELECT customer FROM jobs WHERE id=6487"; #the missing stuff: $result = $mysqli->query($sql) or die(); if($result->num_rows > 0) { while($row = $result->fetch_assoc()) { echo stripslashes($row['customer']); } } mysqli_close($link); ?> Quote Link to comment Share on other sites More sharing options...
gizmola Posted April 30, 2015 Share Posted April 30, 2015 Seems like we're missing the obvious answer -- pass a url parameter. if (isset($_GET['job'])) { $jobId = (int)$_GET['job']; } else { $jobId = 0; } $sql = "SELECT customer FROM jobs WHERE id=$jobId"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.