Jump to content
OGBugsy

displaying mysql data to a html page after submit

Recommended Posts

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.

pic.jpg

 

Any help would be greatly appreciated. Thanks in advance.

 

OGBugsy

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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);

 

?>

Share this post


Link to post
Share on other sites

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";

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.