Jump to content

Linking $id To Form Submit


justlukeyou

Recommended Posts

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"

Link to comment
https://forums.phpfreaks.com/topic/229813-linking-id-to-form-submit/
Share on other sites

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();

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.

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.

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.