Jump to content

Trying to display information from form after it is submitted (confirmation page)


Go to solution Solved by FriskyDingo,

Recommended Posts

Good afternoon,

 

I was wondering if you could help me out with a few things.  I have created a registration page and it stores the information into my database.  A success page then appears with some of the details they entered as a confirmation page.  Unfortunately I cannot get the information to appear on the page.  I have included some code, any help would be greatly appreciated.

 

<?php
 
$Username = "db1234";
$Password = "fakepassword";
$Database = "db2015";
 
$con = mysql_connect("other information here", $Username, $Password);
 
if (!$con) {
die('Could not connect: ' . mysql_error());
}
 
mysql_select_db($Database, $con);
 
$sql = 'SELECT LAST(FirstName) FROM Applicants';
 
$result = mysql_query($sql);
 
$first_name = mysql_result($result,0,applicants.FirstName);
 
 
echo "Congratulations you have been successfully registered " . $first_name;
mysql_close($con);
 
 
?>

What is the LAST() keyword in the query? I've never seen that and don't see any reference for it in the MySQL manual. If you are trying to query the last record that was generated then you are doing it the wrong way. You will create a "race condition" where two users could submit at almost the same time and then when they get to the confirmation page it would pull up the information for one user for both of them.

 

Instead, on the page that you INSERT the data into the database you should capture the last insert ID and store that as a session value. Then, on this page, query the data by that ID.

Hello,

Thank you for the response. I see what you mean by a race if 10 people submit at once I am screwed. So any ideas on how to do the capture on the submit page and post it on a success page?

Thanks again for this quick response. I really appreciate it.


The word last was to capture the last entry but your race condition isn't what I want.


Another option would that as a confirmation they receive an email instead of the success page that would include the information they entered and the auto incremented id they get when entered into the database. I have code, let me know what I can send that would help.

 

Thank you for editing the post, new to the site but not online forums ... been a long day.

Edited by FriskyDingo

No matter how you are going to display the data the last sentence to pyshco's posts still stands.

 

Instead, on the page that you INSERT the data into the database you should capture the last insert ID and store that as a session value. Then, on this page, query the data by that ID.

 

You can use mysql_insert_id to get the id of record that was inserted. Then all you do is run a query to return the data that belongs to that id.

 

I would also encourage you to stop using the mysql_* functions they are deprecated (meaning no longer supported). You should update your code to either mysqli or pdo database functions

It seems to me that you are making this needlessly confusing.  Your script that handles the submission should already have the results of the INSERT query.  

 

Then, as Psycho already stated, you can simply SELECT the new user by ID and use that information to populate your response.

 

You should not be coding new code using the mysql_ functions.  Use either mysqli or PDO/MySQL.  I prefer PDO as it's easier to use in my experience, but either one will do.

 

This page should help you understand what you need to do after your INSERT.  http://php.net/manual/en/pdo.lastinsertid.php

Wow! I don't know who to respond to first.  

 

I realize the code is old, I am going to start updated it in a couple of weeks but I need to get this working in 4 days.  After reading all the responses here is where I am.

 

 

Here is where I have the INSERT INTO command.  How do I take that information and display it on the success page.  Here is that submit code.  Not being lazy, I am so new to this that I have realized that this page needs to be completely redone. 

 

 
mysql_select_db($Database, $con);
 
$sql = 'INSERT INTO applicants (FirstName, SecondName,DOB, SEmail) ';
$sql .= "VALUES ('$FirstName', '$SecondName','$DOB', '$SEmail')";
 
mysql_query($sql, $con);
mysql_close($con);
 
header('Location: success.php') ;
}
}
?>
 
I appreciate the links to the php sites, I see I have a lot to read and practice before I redo this code.  Thanks again for all your help so far.
  • Solution

Thank you all I got it to work.  Took a little longer than I thought but your advice certainly pointed me in the right direction.  I have a year to redo this code after this week and look forward to the challenge.  Had some more issues with older commands and realize that if I am going to help out and I have a lot of freedom I should get it working for now and then update it during the 11 months it isn't used.  Thanks again.  Great site, great community.  Hopefully over time and experience I can help someone else out down the line.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.