justlukeyou Posted March 6, 2011 Share Posted March 6, 2011 I have a form which people can submit information to and then creates a unique ID number. I then echo the form results onto another page. I also want to use the unique id within a link however it echos every id in the database and not just the unique id of the newly submitted form. For example, on 100th submit: For Submit: hello my name is Tom. Echo: $comment hello my name is Tom. $id 1009998979695949392919089................. Can anyone advise how I can get it so echo just the id number which refers to this submission. IE "hello my name is Tom" Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 6, 2011 Share Posted March 6, 2011 You'd need to make some sort of change somewhere in your code. Possibly on line 54. Quote Link to comment Share on other sites More sharing options...
justlukeyou Posted March 6, 2011 Author Share Posted March 6, 2011 Hi, This is the code. // Get values from form $category = $_POST['category']; $question=$_POST['question']; $notes=$_POST['notes']; // Insert data into mysql $sql="INSERT INTO $tbl_name(category, question, notes)VALUES('$category', '$question', '$notes')"; $result=mysql_query($sql); // if successfully insert data into database, displays message "Successful". if($result){ echo "<a href= 'http://www.domain.com/test/index.php'>$question</a></br> $notes</br> $category"; } else { echo "Apologies, there appears to be a problem. Your questions was not been submitted."; } ini_set('display_errors', 1); error_reporting(-1); { $query = "SELECT * FROM home"; } $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; echo "<a href= 'http://www.domain.com.php?question='>$id</a>"; } // close connection mysql_close(); Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted March 6, 2011 Share Posted March 6, 2011 Attaboy. This should be pretty easy, assuming your primary key is an auto_increment field. Just two changes to make. After the INSERT query, add $id = mysql_insert_id(); Get rid of the SELECT query entirely. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 6, 2011 Share Posted March 6, 2011 You can get anythink you want, as it all in a database. I looked at your code and was baffled at all the insucure programming. maybe your self tualt, but you need a good tutoral,sorry but none off the var are protected for fake inserts from ppl. look at this. select what_ever from what_ever where id="what_ever" that easy. 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.